@@ -21,6 +21,7 @@ import * as _ from 'lodash';
2121import * as chai from 'chai' ;
2222import * as sinon from 'sinon' ;
2323import { HttpClient } from '../../../src/utils/api-request' ;
24+ import * as sinonChai from 'sinon-chai' ;
2425import * as utils from '../utils' ;
2526import * as mocks from '../../resources/mocks' ;
2627import { getMetricsHeader , getSdkVersion } from '../../../src/utils' ;
@@ -31,6 +32,7 @@ import { FirebaseAppError } from '../../../src/utils/error';
3132import { deepCopy } from '../../../src/utils/deep-copy' ;
3233
3334const expect = chai . expect ;
35+ chai . use ( sinonChai ) ;
3436
3537describe ( 'AppCheckApiClient' , ( ) => {
3638
@@ -210,7 +212,31 @@ describe('AppCheckApiClient', () => {
210212 method : 'POST' ,
211213 url : `https://firebaseappcheck.googleapis.com/v1/projects/test-project/apps/${ APP_ID } :exchangeCustomToken` ,
212214 headers : EXPECTED_HEADERS ,
213- data : { customToken : TEST_TOKEN_TO_EXCHANGE }
215+ data : {
216+ customToken : TEST_TOKEN_TO_EXCHANGE ,
217+ limitedUse : undefined ,
218+ }
219+ } ) ;
220+ } ) ;
221+ } ) ;
222+
223+ it ( 'should resolve with the App Check token on success with limitedUse' , ( ) => {
224+ const stub = sinon
225+ . stub ( HttpClient . prototype , 'send' )
226+ . resolves ( utils . responseFrom ( TEST_RESPONSE , 200 ) ) ;
227+ stubs . push ( stub ) ;
228+ return apiClient . exchangeToken ( TEST_TOKEN_TO_EXCHANGE , APP_ID , true )
229+ . then ( ( resp ) => {
230+ expect ( resp . token ) . to . deep . equal ( TEST_RESPONSE . token ) ;
231+ expect ( resp . ttlMillis ) . to . deep . equal ( 3000 ) ;
232+ expect ( stub ) . to . have . been . calledOnce . and . calledWith ( {
233+ method : 'POST' ,
234+ url : `https://firebaseappcheck.googleapis.com/v1/projects/test-project/apps/${ APP_ID } :exchangeCustomToken` ,
235+ headers : EXPECTED_HEADERS ,
236+ data : {
237+ customToken : TEST_TOKEN_TO_EXCHANGE ,
238+ limitedUse : true ,
239+ }
214240 } ) ;
215241 } ) ;
216242 } ) ;
0 commit comments