@@ -35,7 +35,7 @@ import { AuthEventManager } from '../auth/auth_event_manager';
35
35
import { AUTH_ERROR_FACTORY , AuthErrorCode } from '../errors' ;
36
36
import { UserCredentialImpl } from '../user/user_credential_impl' ;
37
37
import { _getInstance } from '../util/instantiator' ;
38
- import { AbstractPopupRedirectAction } from './abstract_popup_redirect_action ' ;
38
+ import { AbstractPopupRedirectOperation } from './abstract_popup_redirect_operation ' ;
39
39
import * as idp from './idp' ;
40
40
41
41
use ( sinonChai ) ;
@@ -48,13 +48,13 @@ const ERROR = AUTH_ERROR_FACTORY.create(AuthErrorCode.INTERNAL_ERROR, {
48
48
/**
49
49
* A real class is needed to instantiate the action
50
50
*/
51
- class WrapperAction extends AbstractPopupRedirectAction {
51
+ class WrapperOperation extends AbstractPopupRedirectOperation {
52
52
eventId = '100' ;
53
53
onExecution = sinon . stub ( ) . returns ( Promise . resolve ( ) ) ;
54
54
cleanUp = sinon . stub ( ) ;
55
55
}
56
56
57
- describe ( 'src/core/strategies/abstract_popup_redirect_action ' , ( ) => {
57
+ describe ( 'src/core/strategies/abstract_popup_redirect_operation ' , ( ) => {
58
58
let auth : Auth ;
59
59
let resolver : PopupRedirectResolver ;
60
60
let eventManager : EventManager ;
@@ -72,92 +72,147 @@ describe('src/core/strategies/abstract_popup_redirect_action', () => {
72
72
} ) ;
73
73
74
74
context ( '#execute' , ( ) => {
75
- let action : WrapperAction ;
75
+ let operation : WrapperOperation ;
76
76
77
77
beforeEach ( ( ) => {
78
- action = new WrapperAction ( auth , AuthEventType . LINK_VIA_POPUP , resolver ) ;
78
+ operation = new WrapperOperation ( auth , AuthEventType . LINK_VIA_POPUP , resolver ) ;
79
79
idpStubs . _signIn . returns ( Promise . resolve ( new UserCredentialImpl ( testUser ( auth , 'uid' ) , null , OperationType . SIGN_IN ) ) ) ;
80
80
} ) ;
81
81
82
82
/** Finishes out the promise */
83
83
function finishPromise ( outcome : AuthEvent | FirebaseError ) : void {
84
84
delay ( ( ) : void => {
85
85
if ( outcome instanceof FirebaseError ) {
86
- action . onError ( outcome ) ;
86
+ operation . onError ( outcome ) ;
87
87
} else {
88
88
// eslint-disable-next-line @typescript-eslint/no-floating-promises
89
- action . onAuthEvent ( outcome ) ;
89
+ operation . onAuthEvent ( outcome ) ;
90
90
}
91
91
} ) ;
92
92
}
93
93
94
94
it ( 'initializes the resolver' , async ( ) => {
95
95
sinon . spy ( resolver , '_initialize' ) ;
96
- const promise = action . execute ( ) ;
96
+ const promise = operation . execute ( ) ;
97
97
finishPromise ( authEvent ( ) ) ;
98
98
await promise ;
99
99
expect ( resolver . _initialize ) . to . have . been . calledWith ( auth ) ;
100
100
} ) ;
101
101
102
102
it ( 'calls subclass onExecution' , async ( ) => {
103
103
finishPromise ( authEvent ( ) ) ;
104
- await action . execute ( ) ;
105
- expect ( action . onExecution ) . to . have . been . called ;
104
+ await operation . execute ( ) ;
105
+ expect ( operation . onExecution ) . to . have . been . called ;
106
106
} ) ;
107
107
108
108
it ( 'registers and unregisters itself with the event manager' , async ( ) => {
109
109
sinon . spy ( eventManager , 'registerConsumer' ) ;
110
110
sinon . spy ( eventManager , 'unregisterConsumer' ) ;
111
111
finishPromise ( authEvent ( ) ) ;
112
- await action . execute ( ) ;
113
- expect ( eventManager . registerConsumer ) . to . have . been . calledWith ( action ) ;
114
- expect ( eventManager . unregisterConsumer ) . to . have . been . calledWith ( action ) ;
112
+ await operation . execute ( ) ;
113
+ expect ( eventManager . registerConsumer ) . to . have . been . calledWith ( operation ) ;
114
+ expect ( eventManager . unregisterConsumer ) . to . have . been . calledWith ( operation ) ;
115
115
} ) ;
116
116
117
117
it ( 'unregisters itself in case of error' , async ( ) => {
118
118
sinon . spy ( eventManager , 'unregisterConsumer' ) ;
119
119
finishPromise ( ERROR ) ;
120
- try { await action . execute ( ) ; } catch { }
121
- expect ( eventManager . unregisterConsumer ) . to . have . been . calledWith ( action ) ;
120
+ try { await operation . execute ( ) ; } catch { }
121
+ expect ( eventManager . unregisterConsumer ) . to . have . been . calledWith ( operation ) ;
122
122
} ) ;
123
123
124
124
it ( 'emits the user credential returned from idp task' , async ( ) => {
125
125
finishPromise ( authEvent ( ) ) ;
126
- const cred = await action . execute ( ) ;
126
+ const cred = await operation . execute ( ) ;
127
127
expect ( cred . user . uid ) . to . eq ( 'uid' ) ;
128
128
expect ( cred . credential ) . to . be . null ;
129
129
expect ( cred . operationType ) . to . eq ( OperationType . SIGN_IN ) ;
130
130
} ) ;
131
131
132
- it ( 'bubbles up any error' , async ( done ) => {
132
+ it ( 'bubbles up any error' , done => {
133
133
finishPromise ( ERROR ) ;
134
- try {
135
- await action . execute ( ) ;
136
- } catch ( e ) {
134
+ operation . execute ( ) . catch ( e => {
137
135
expect ( e ) . to . eq ( ERROR ) ;
138
136
done ( ) ;
139
- }
137
+ } ) ;
138
+ } ) ;
139
+
140
+ it ( 'calls cleanUp on error' , async ( ) => {
141
+ finishPromise ( ERROR ) ;
142
+ try {
143
+ await operation . execute ( ) ;
144
+ } catch { }
145
+ expect ( operation . cleanUp ) . to . have . been . called ;
146
+ } ) ;
147
+
148
+ it ( 'calls cleanUp on success' , async ( ) => {
149
+ finishPromise ( authEvent ( ) ) ;
150
+ await operation . execute ( ) ;
151
+ expect ( operation . cleanUp ) . to . have . been . called ;
140
152
} ) ;
141
153
142
154
context ( 'idp tasks' , ( ) => {
143
- function updateFilter ( type : AuthEventType ) {
144
- ( action as unknown as Record < string , unknown > ) . filter = type ;
155
+ function updateFilter ( type : AuthEventType ) : void {
156
+ ( operation as unknown as Record < string , unknown > ) . filter = type ;
145
157
}
146
158
147
- const expectedIdpTaskParams : idp . IdpTaskParams = {
148
- auth,
149
- requestUri : BASE_AUTH_EVENT . urlResponse ! ,
150
- sessionId : BASE_AUTH_EVENT . sessionId ! ,
151
- tenantId : BASE_AUTH_EVENT . tenantId || undefined ,
152
- postBody : BASE_AUTH_EVENT . postBody || undefined ,
153
- } ;
159
+ function expectedIdpTaskParams ( ) : idp . IdpTaskParams {
160
+ return {
161
+ auth,
162
+ requestUri : BASE_AUTH_EVENT . urlResponse ! ,
163
+ sessionId : BASE_AUTH_EVENT . sessionId ! ,
164
+ tenantId : BASE_AUTH_EVENT . tenantId || undefined ,
165
+ postBody : BASE_AUTH_EVENT . postBody || undefined ,
166
+ user : undefined ,
167
+ } ;
168
+ }
154
169
155
- it ( 'routes signInWithPopup ' , async ( ) => {
170
+ it ( 'routes SIGN_IN_VIA_POPUP ' , async ( ) => {
156
171
const type = AuthEventType . SIGN_IN_VIA_POPUP ;
157
172
updateFilter ( type ) ;
158
173
finishPromise ( authEvent ( { type} ) ) ;
159
- await action . execute ( ) ;
160
- expect ( idp . _signIn ) . to . have . been . calledWith ( expectedIdpTaskParams ) ;
174
+ await operation . execute ( ) ;
175
+ expect ( idp . _signIn ) . to . have . been . calledWith ( expectedIdpTaskParams ( ) ) ;
176
+ } ) ;
177
+
178
+ it ( 'routes SIGN_IN_VIA_REDIRECT' , async ( ) => {
179
+ const type = AuthEventType . SIGN_IN_VIA_REDIRECT ;
180
+ updateFilter ( type ) ;
181
+ finishPromise ( authEvent ( { type} ) ) ;
182
+ await operation . execute ( ) ;
183
+ expect ( idp . _signIn ) . to . have . been . calledWith ( expectedIdpTaskParams ( ) ) ;
184
+ } ) ;
185
+
186
+ it ( 'routes LINK_VIA_POPUP' , async ( ) => {
187
+ const type = AuthEventType . LINK_VIA_POPUP ;
188
+ updateFilter ( type ) ;
189
+ finishPromise ( authEvent ( { type} ) ) ;
190
+ await operation . execute ( ) ;
191
+ expect ( idp . _link ) . to . have . been . calledWith ( expectedIdpTaskParams ( ) ) ;
192
+ } ) ;
193
+
194
+ it ( 'routes LINK_VIA_REDIRECT' , async ( ) => {
195
+ const type = AuthEventType . LINK_VIA_REDIRECT ;
196
+ updateFilter ( type ) ;
197
+ finishPromise ( authEvent ( { type} ) ) ;
198
+ await operation . execute ( ) ;
199
+ expect ( idp . _link ) . to . have . been . calledWith ( expectedIdpTaskParams ( ) ) ;
200
+ } ) ;
201
+
202
+ it ( 'routes REAUTH_VIA_POPUP' , async ( ) => {
203
+ const type = AuthEventType . REAUTH_VIA_POPUP ;
204
+ updateFilter ( type ) ;
205
+ finishPromise ( authEvent ( { type} ) ) ;
206
+ await operation . execute ( ) ;
207
+ expect ( idp . _reauth ) . to . have . been . calledWith ( expectedIdpTaskParams ( ) ) ;
208
+ } ) ;
209
+
210
+ it ( 'routes REAUTH_VIA_REDIRECT' , async ( ) => {
211
+ const type = AuthEventType . REAUTH_VIA_REDIRECT ;
212
+ updateFilter ( type ) ;
213
+ finishPromise ( authEvent ( { type} ) ) ;
214
+ await operation . execute ( ) ;
215
+ expect ( idp . _reauth ) . to . have . been . calledWith ( expectedIdpTaskParams ( ) ) ;
161
216
} ) ;
162
217
} ) ;
163
218
} ) ;
0 commit comments