11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- import { configure } from '../src/configure' ;
54import { createConfigurationBuilder } from '@aws-amplify/core' ;
5+
6+ import { configure } from '../src/configure' ;
7+
68import { amplifyOutputsFixture } from './fixtures/amplifyOutputs' ;
79
810describe ( 'configure()' , ( ) => {
@@ -45,6 +47,7 @@ describe('configure()', () => {
4547 ...amplifyOutputsFixture ,
4648 auth : {
4749 ...amplifyOutputsFixture . auth ,
50+ // eslint-disable-next-line camelcase
4851 user_pool_id : 'eu-north-1_NewPoolId' ,
4952 } ,
5053 } ) ;
@@ -58,6 +61,60 @@ describe('configure()', () => {
5861 } ) ;
5962} ) ;
6063
64+ describe ( 'configure() — resolveLocalLibraryOptions branches' , ( ) => {
65+ it ( 'returns empty options when no Auth config' , ( ) => {
66+ const ctx = configure ( {
67+ version : '1.4' ,
68+ storage : amplifyOutputsFixture . storage ,
69+ } ) ;
70+ expect ( ctx . resourcesConfig . Auth ) . toBeUndefined ( ) ;
71+ expect ( ctx . resourcesConfig . Storage ?. S3 ?. bucket ) . toBe (
72+ 'my-test-app-storage-bucket-abcdef123456' ,
73+ ) ;
74+ } ) ;
75+
76+ it ( 'passes through custom Auth libraryOptions' , ( ) => {
77+ const mockTokenProvider = {
78+ getTokens : jest . fn ( ) . mockResolvedValue ( undefined ) ,
79+ } ;
80+ const mockCredentialsProvider = {
81+ getCredentialsAndIdentityId : jest . fn ( ) . mockResolvedValue ( undefined ) ,
82+ clearCredentialsAndIdentityId : jest . fn ( ) ,
83+ } ;
84+ const ctx = configure ( amplifyOutputsFixture , {
85+ Auth : {
86+ tokenProvider : mockTokenProvider as any ,
87+ credentialsProvider : mockCredentialsProvider as any ,
88+ } ,
89+ } ) ;
90+ expect ( ctx . resourcesConfig . Auth ?. Cognito . userPoolId ) . toBe (
91+ 'eu-north-1_Ab12CdEfG' ,
92+ ) ;
93+ } ) ;
94+
95+ it ( 'uses cookie storage when ssr is true' , ( ) => {
96+ const ctx = configure ( amplifyOutputsFixture , { ssr : true } ) ;
97+ expect ( ctx . resourcesConfig . Auth ?. Cognito . userPoolId ) . toBe (
98+ 'eu-north-1_Ab12CdEfG' ,
99+ ) ;
100+ } ) ;
101+
102+ it ( 'delegates fetchAuthSession to AuthClass' , ( ) => {
103+ const ctx = configure ( amplifyOutputsFixture ) ;
104+ expect ( typeof ctx . fetchAuthSession ) . toBe ( 'function' ) ;
105+ } ) ;
106+
107+ it ( 'delegates clearCredentials to AuthClass' , ( ) => {
108+ const ctx = configure ( amplifyOutputsFixture ) ;
109+ expect ( typeof ctx . clearCredentials ) . toBe ( 'function' ) ;
110+ } ) ;
111+
112+ it ( 'delegates getTokens to AuthClass' , ( ) => {
113+ const ctx = configure ( amplifyOutputsFixture ) ;
114+ expect ( typeof ctx . getTokens ) . toBe ( 'function' ) ;
115+ } ) ;
116+ } ) ;
117+
61118describe ( 'createConfigurationBuilder()' , ( ) => {
62119 it ( 'round-trips through configure()' , ( ) => {
63120 const config = createConfigurationBuilder ( )
@@ -87,6 +144,7 @@ describe('createConfigurationBuilder()', () => {
87144 . auth ( amplifyOutputsFixture . auth )
88145 . auth ( {
89146 ...amplifyOutputsFixture . auth ,
147+ // eslint-disable-next-line camelcase
90148 user_pool_id : 'eu-north-1_Replaced' ,
91149 } )
92150 . build ( ) ;
0 commit comments