@@ -11,6 +11,8 @@ import {
11
11
import { AmplifyOutputs } from '@aws-amplify/core/internals/utils' ;
12
12
13
13
import {
14
+ CognitoAWSCredentialsAndIdentityIdProvider ,
15
+ DefaultIdentityIdStore ,
14
16
cognitoCredentialsProvider ,
15
17
cognitoUserPoolsTokenProvider ,
16
18
} from '../src/auth/cognito' ;
@@ -23,6 +25,8 @@ jest.mock('../src/auth/cognito', () => ({
23
25
setKeyValueStorage : jest . fn ( ) ,
24
26
} ,
25
27
cognitoCredentialsProvider : jest . fn ( ) ,
28
+ DefaultIdentityIdStore : jest . fn ( ) ,
29
+ CognitoAWSCredentialsAndIdentityIdProvider : jest . fn ( ) ,
26
30
} ) ) ;
27
31
28
32
const mockCognitoUserPoolsTokenProviderSetAuthConfig =
@@ -32,6 +36,10 @@ const mockCognitoUserPoolsTokenProviderSetKeyValueStorage =
32
36
const mockAmplifySingletonConfigure = AmplifySingleton . configure as jest . Mock ;
33
37
const mockAmplifySingletonGetConfig = AmplifySingleton . getConfig as jest . Mock ;
34
38
const MockCookieStorage = CookieStorage as jest . Mock ;
39
+ const MockDefaultIdentityIdStore = jest . mocked ( DefaultIdentityIdStore ) ;
40
+ const MockCognitoAWSCredentialsAndIdentityIdProvider = jest . mocked (
41
+ CognitoAWSCredentialsAndIdentityIdProvider ,
42
+ ) ;
35
43
36
44
const mockResourceConfig : ResourcesConfig = {
37
45
Auth : {
@@ -50,8 +58,16 @@ const mockResourceConfig: ResourcesConfig = {
50
58
51
59
describe ( 'initSingleton (DefaultAmplify)' , ( ) => {
52
60
const mockCookieStorageInstance = { } ;
61
+ const mockCognitoAWSCredentialsAndIdentityIdProviderInstance = { } as any ;
62
+ const mockDefaultIdentityIdStoreInstance = { } as any ;
53
63
beforeAll ( ( ) => {
54
64
MockCookieStorage . mockImplementation ( ( ) => mockCookieStorageInstance ) ;
65
+ MockDefaultIdentityIdStore . mockImplementation (
66
+ ( ) => mockDefaultIdentityIdStoreInstance ,
67
+ ) ;
68
+ MockCognitoAWSCredentialsAndIdentityIdProvider . mockImplementation (
69
+ ( ) => mockCognitoAWSCredentialsAndIdentityIdProviderInstance ,
70
+ ) ;
55
71
} ) ;
56
72
beforeEach ( ( ) => {
57
73
mockAmplifySingletonConfigure . mockImplementation ( ( _ , libraryOptions ) => {
@@ -64,6 +80,8 @@ describe('initSingleton (DefaultAmplify)', () => {
64
80
65
81
afterEach ( ( ) => {
66
82
MockCookieStorage . mockClear ( ) ;
83
+ MockCognitoAWSCredentialsAndIdentityIdProvider . mockClear ( ) ;
84
+ MockDefaultIdentityIdStore . mockClear ( ) ;
67
85
mockCognitoUserPoolsTokenProviderSetAuthConfig . mockReset ( ) ;
68
86
mockCognitoUserPoolsTokenProviderSetKeyValueStorage . mockReset ( ) ;
69
87
mockAmplifySingletonConfigure . mockReset ( ) ;
@@ -252,13 +270,20 @@ describe('initSingleton (DefaultAmplify)', () => {
252
270
expect (
253
271
mockCognitoUserPoolsTokenProviderSetKeyValueStorage ,
254
272
) . toHaveBeenCalledWith ( mockCookieStorageInstance ) ;
273
+ expect ( MockDefaultIdentityIdStore ) . toHaveBeenCalledWith (
274
+ mockCookieStorageInstance ,
275
+ ) ;
276
+ expect (
277
+ MockCognitoAWSCredentialsAndIdentityIdProvider ,
278
+ ) . toHaveBeenCalledWith ( mockDefaultIdentityIdStoreInstance ) ;
255
279
expect ( mockAmplifySingletonConfigure ) . toHaveBeenCalledWith (
256
280
mockResourceConfig ,
257
281
{
258
282
...libraryOptions ,
259
283
Auth : {
260
284
tokenProvider : cognitoUserPoolsTokenProvider ,
261
- credentialsProvider : cognitoCredentialsProvider ,
285
+ credentialsProvider :
286
+ mockCognitoAWSCredentialsAndIdentityIdProviderInstance ,
262
287
} ,
263
288
} ,
264
289
) ;
@@ -345,7 +370,6 @@ describe('initSingleton (DefaultAmplify)', () => {
345
370
expect (
346
371
mockCognitoUserPoolsTokenProviderSetAuthConfig ,
347
372
) . not . toHaveBeenCalled ( ) ;
348
- expect ( MockCookieStorage ) . not . toHaveBeenCalled ( ) ;
349
373
expect (
350
374
mockCognitoUserPoolsTokenProviderSetKeyValueStorage ,
351
375
) . not . toHaveBeenCalled ( ) ;
0 commit comments