1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
+ import { tokenOrchestrator } from '../../../../../src/providers/cognito/tokenProvider' ;
4
5
import { completeOAuthSignOut } from '../../../../../src/providers/cognito/utils/oauth/completeOAuthSignOut' ;
5
6
import { handleOAuthSignOut } from '../../../../../src/providers/cognito/utils/oauth/handleOAuthSignOut.native' ;
6
7
import { oAuthSignOutRedirect } from '../../../../../src/providers/cognito/utils/oauth/oAuthSignOutRedirect' ;
@@ -23,6 +24,9 @@ describe('handleOAuthSignOut (native)', () => {
23
24
// assert mocks
24
25
const mockCompleteOAuthSignOut = completeOAuthSignOut as jest . Mock ;
25
26
const mockOAuthSignOutRedirect = oAuthSignOutRedirect as jest . Mock ;
27
+ const mockTokenOrchestrator = tokenOrchestrator as jest . Mocked <
28
+ typeof tokenOrchestrator
29
+ > ;
26
30
// create mocks
27
31
const mockStore = {
28
32
loadOAuthSignIn : jest . fn ( ) ,
@@ -43,33 +47,51 @@ describe('handleOAuthSignOut (native)', () => {
43
47
} ) ;
44
48
it ( 'should complete OAuth sign out and redirect' , async ( ) => {
45
49
mockOAuthSignOutRedirect . mockResolvedValue ( { type : 'success' } ) ;
46
- await handleOAuthSignOut ( cognitoConfig , mockStore ) ;
50
+ await handleOAuthSignOut (
51
+ cognitoConfig ,
52
+ mockStore ,
53
+ mockTokenOrchestrator ,
54
+ undefined ,
55
+ ) ;
47
56
48
57
expect ( mockOAuthSignOutRedirect ) . toHaveBeenCalledWith (
49
58
cognitoConfig ,
50
59
false ,
60
+ undefined ,
51
61
) ;
52
62
expect ( mockCompleteOAuthSignOut ) . toHaveBeenCalledWith ( mockStore ) ;
53
63
} ) ;
54
64
55
65
it ( 'should not complete OAuth sign out if redirect is canceled' , async ( ) => {
56
66
mockOAuthSignOutRedirect . mockResolvedValue ( { type : 'canceled' } ) ;
57
- await handleOAuthSignOut ( cognitoConfig , mockStore ) ;
67
+ await handleOAuthSignOut (
68
+ cognitoConfig ,
69
+ mockStore ,
70
+ mockTokenOrchestrator ,
71
+ undefined ,
72
+ ) ;
58
73
59
74
expect ( mockOAuthSignOutRedirect ) . toHaveBeenCalledWith (
60
75
cognitoConfig ,
61
76
false ,
77
+ undefined ,
62
78
) ;
63
79
expect ( mockCompleteOAuthSignOut ) . not . toHaveBeenCalled ( ) ;
64
80
} ) ;
65
81
66
82
it ( 'should not complete OAuth sign out if redirect failed' , async ( ) => {
67
83
mockOAuthSignOutRedirect . mockResolvedValue ( { type : 'error' } ) ;
68
- await handleOAuthSignOut ( cognitoConfig , mockStore ) ;
84
+ await handleOAuthSignOut (
85
+ cognitoConfig ,
86
+ mockStore ,
87
+ mockTokenOrchestrator ,
88
+ undefined ,
89
+ ) ;
69
90
70
91
expect ( mockOAuthSignOutRedirect ) . toHaveBeenCalledWith (
71
92
cognitoConfig ,
72
93
false ,
94
+ undefined ,
73
95
) ;
74
96
expect ( mockCompleteOAuthSignOut ) . not . toHaveBeenCalled ( ) ;
75
97
} ) ;
@@ -81,9 +103,18 @@ describe('handleOAuthSignOut (native)', () => {
81
103
preferPrivateSession : true ,
82
104
} ) ;
83
105
mockOAuthSignOutRedirect . mockResolvedValue ( { type : 'error' } ) ;
84
- await handleOAuthSignOut ( cognitoConfig , mockStore ) ;
106
+ await handleOAuthSignOut (
107
+ cognitoConfig ,
108
+ mockStore ,
109
+ mockTokenOrchestrator ,
110
+ undefined ,
111
+ ) ;
85
112
86
- expect ( mockOAuthSignOutRedirect ) . toHaveBeenCalledWith ( cognitoConfig , true ) ;
113
+ expect ( mockOAuthSignOutRedirect ) . toHaveBeenCalledWith (
114
+ cognitoConfig ,
115
+ true ,
116
+ undefined ,
117
+ ) ;
87
118
expect ( mockCompleteOAuthSignOut ) . toHaveBeenCalledWith ( mockStore ) ;
88
119
} ) ;
89
120
@@ -92,7 +123,12 @@ describe('handleOAuthSignOut (native)', () => {
92
123
isOAuthSignIn : false ,
93
124
preferPrivateSession : false ,
94
125
} ) ;
95
- await handleOAuthSignOut ( cognitoConfig , mockStore ) ;
126
+ await handleOAuthSignOut (
127
+ cognitoConfig ,
128
+ mockStore ,
129
+ mockTokenOrchestrator ,
130
+ undefined ,
131
+ ) ;
96
132
97
133
expect ( mockOAuthSignOutRedirect ) . not . toHaveBeenCalled ( ) ;
98
134
expect ( mockCompleteOAuthSignOut ) . toHaveBeenCalledWith ( mockStore ) ;
0 commit comments