@@ -246,29 +246,40 @@ describe('initSingleton (DefaultAmplify)', () => {
246246 } ) ;
247247
248248 describe ( 'when ResourcesConfig.Auth is defined' , ( ) => {
249- it ( 'should merge with existing libraryOptions when libraryOptions.Auth is defined' , ( ) => {
250- const customTokenProvider = { getTokens : jest . fn ( ) } ;
251- const storageLibraryOptions = {
252- S3 : { defaultAccessLevel : 'private' as const } ,
253- } ;
254- AmplifySingleton . libraryOptions = {
255- Storage : storageLibraryOptions ,
256- } ;
249+ it ( 'should sync default Cognito auth config when libraryOptions.Auth uses default provider' , ( ) => {
257250 const libraryOptions = {
258- Auth : { tokenProvider : customTokenProvider } ,
251+ Auth : {
252+ tokenProvider : cognitoUserPoolsTokenProvider ,
253+ credentialsProvider : cognitoCredentialsProvider ,
254+ } ,
259255 } ;
256+
260257 Amplify . configure ( mockResourceConfig , libraryOptions ) ;
261258
259+ expect (
260+ mockCognitoUserPoolsTokenProviderSetAuthConfig ,
261+ ) . toHaveBeenCalledWith ( mockResourceConfig . Auth ) ;
262262 expect ( mockAmplifySingletonConfigure ) . toHaveBeenCalledWith (
263263 mockResourceConfig ,
264- {
265- Storage : storageLibraryOptions ,
266- Auth : libraryOptions . Auth ,
267- } ,
264+ libraryOptions ,
268265 ) ;
266+ } ) ;
267+
268+ it ( 'should not sync Cognito auth config when libraryOptions.Auth uses a custom token provider' , ( ) => {
269+ const customTokenProvider = { getTokens : jest . fn ( ) } ;
270+ const libraryOptions = {
271+ Auth : { tokenProvider : customTokenProvider } ,
272+ } ;
273+
274+ Amplify . configure ( mockResourceConfig , libraryOptions ) ;
275+
269276 expect (
270277 mockCognitoUserPoolsTokenProviderSetAuthConfig ,
271278 ) . not . toHaveBeenCalled ( ) ;
279+ expect ( mockAmplifySingletonConfigure ) . toHaveBeenCalledWith (
280+ mockResourceConfig ,
281+ libraryOptions ,
282+ ) ;
272283 } ) ;
273284
274285 describe ( 'when the singleton libraryOptions have not yet been configured with Auth' , ( ) => {
@@ -398,34 +409,6 @@ describe('initSingleton (DefaultAmplify)', () => {
398409 ) ;
399410 } ) ;
400411
401- it ( 'should preserve non-Auth library options when reconfiguring with partial libraryOptions' , ( ) => {
402- const storageLibraryOptions = {
403- S3 : { defaultAccessLevel : 'private' as const } ,
404- } ;
405- AmplifySingleton . libraryOptions = {
406- Auth : {
407- tokenProvider : cognitoUserPoolsTokenProvider ,
408- credentialsProvider : cognitoCredentialsProvider ,
409- } ,
410- Storage : storageLibraryOptions ,
411- } ;
412- const authLibraryOptions = AmplifySingleton . libraryOptions . Auth ;
413-
414- Amplify . configure ( mockResourceConfig , { ssr : true } ) ;
415-
416- expect (
417- mockCognitoUserPoolsTokenProviderSetAuthConfig ,
418- ) . toHaveBeenCalledWith ( mockResourceConfig . Auth ) ;
419- expect ( mockAmplifySingletonConfigure ) . toHaveBeenCalledWith (
420- mockResourceConfig ,
421- {
422- Auth : authLibraryOptions ,
423- Storage : storageLibraryOptions ,
424- ssr : true ,
425- } ,
426- ) ;
427- } ) ;
428-
429412 it ( 'should sync default Cognito auth config when reconfiguring with resource config only' , ( ) => {
430413 Amplify . configure ( mockResourceConfig ) ;
431414
@@ -437,33 +420,6 @@ describe('initSingleton (DefaultAmplify)', () => {
437420 ) ;
438421 } ) ;
439422
440- it ( 'should sync default Cognito auth config when libraryOptions.Auth overrides with default provider' , ( ) => {
441- const updatedResourceConfig : ResourcesConfig = {
442- Auth : {
443- Cognito : {
444- userPoolClientId : 'newClientId' ,
445- userPoolId : 'newPoolId' ,
446- } ,
447- } ,
448- } ;
449- AmplifySingleton . libraryOptions = {
450- Auth : {
451- tokenProvider : cognitoUserPoolsTokenProvider ,
452- credentialsProvider : cognitoCredentialsProvider ,
453- } ,
454- } ;
455-
456- Amplify . configure ( updatedResourceConfig , {
457- Auth : {
458- tokenProvider : cognitoUserPoolsTokenProvider ,
459- credentialsProvider : cognitoCredentialsProvider ,
460- } ,
461- } ) ;
462-
463- expect (
464- mockCognitoUserPoolsTokenProviderSetAuthConfig ,
465- ) . toHaveBeenCalledWith ( updatedResourceConfig . Auth ) ;
466- } ) ;
467423 } ) ;
468424
469425 it ( 'should invoke AmplifySingleton.configure with other provided library options' , ( ) => {
0 commit comments