@@ -222,6 +222,85 @@ describe('E2EIHandler', () => {
222
222
return enrollPromise ;
223
223
} ) ;
224
224
225
+ it ( 'shows the error modal without the snooze option after enrollment failed and the client is fresh' , async ( ) => {
226
+ jest . spyOn ( coreMock . service ! . e2eIdentity ! , 'isFreshMLSSelfClient' ) . mockResolvedValue ( true ) ;
227
+ jest . spyOn ( coreMock . service ! . e2eIdentity ! , 'isEnrollmentInProgress' ) . mockResolvedValue ( true ) ;
228
+ jest . spyOn ( coreMock , 'enrollE2EI' ) . mockRejectedValue ( new Error ( 'OIDC Error' ) ) ;
229
+
230
+ const handler = E2EIHandler . getInstance ( ) ;
231
+
232
+ // mock window search params (code, session_state, state)
233
+ const searchParams = new URLSearchParams ( ) ;
234
+ searchParams . append ( 'code' , 'CODE' ) ;
235
+ searchParams . append ( 'session_state' , 'SESSION_STATE' ) ;
236
+ searchParams . append ( 'state' , 'STATE' ) ;
237
+
238
+ Object . defineProperty ( window , 'location' , {
239
+ value : {
240
+ search : searchParams . toString ( ) ,
241
+ } ,
242
+ writable : true ,
243
+ } ) ;
244
+
245
+ const enrollPromise = handler . initialize ( params ) ;
246
+
247
+ await waitFor ( ( ) => {
248
+ expect ( modalMock ) . toHaveBeenCalledWith (
249
+ PrimaryModalType . ACKNOWLEDGE ,
250
+ expect . objectContaining ( { text : expect . objectContaining ( { title : 'acme.error.headline' } ) } ) ,
251
+ ) ;
252
+ expect ( modalMock ) . not . toHaveBeenCalledWith (
253
+ PrimaryModalType . CONFIRM ,
254
+ expect . objectContaining ( { secondaryAction : expect . objectContaining ( { text : 'acme.error.button.secondary' } ) } ) ,
255
+ ) ;
256
+ } ) ;
257
+
258
+ jest . spyOn ( handler , 'enroll' ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
259
+
260
+ modalMock . mock . lastCall ?. [ 1 ] . primaryAction ?. action ?.( ) ;
261
+
262
+ return enrollPromise ;
263
+ } ) ;
264
+
265
+ it ( 'shows the error modal with the snooze option after enrollment failed and the client is an e2ei client already' , async ( ) => {
266
+ jest . spyOn ( coreMock . service ! . e2eIdentity ! , 'isFreshMLSSelfClient' ) . mockResolvedValue ( false ) ;
267
+ jest . spyOn ( coreMock . service ! . e2eIdentity ! , 'isEnrollmentInProgress' ) . mockResolvedValue ( true ) ;
268
+ jest . spyOn ( coreMock , 'enrollE2EI' ) . mockRejectedValue ( new Error ( 'OIDC Error' ) ) ;
269
+
270
+ const handler = E2EIHandler . getInstance ( ) ;
271
+
272
+ // mock window search params (code, session_state, state)
273
+ const searchParams = new URLSearchParams ( ) ;
274
+ searchParams . append ( 'code' , 'CODE' ) ;
275
+ searchParams . append ( 'session_state' , 'SESSION_STATE' ) ;
276
+ searchParams . append ( 'state' , 'STATE' ) ;
277
+
278
+ Object . defineProperty ( window , 'location' , {
279
+ value : {
280
+ search : searchParams . toString ( ) ,
281
+ } ,
282
+ writable : true ,
283
+ } ) ;
284
+
285
+ const enrollPromise = handler . initialize ( params ) ;
286
+
287
+ await waitFor ( ( ) => {
288
+ expect ( modalMock ) . toHaveBeenCalledWith (
289
+ PrimaryModalType . CONFIRM ,
290
+ expect . objectContaining ( {
291
+ text : expect . objectContaining ( { title : 'acme.error.headline' } ) ,
292
+ secondaryAction : expect . objectContaining ( { text : 'acme.error.button.secondary' } ) ,
293
+ } ) ,
294
+ ) ;
295
+ } ) ;
296
+
297
+ jest . spyOn ( handler , 'enroll' ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
298
+
299
+ modalMock . mock . lastCall ?. [ 1 ] . primaryAction ?. action ?.( ) ;
300
+
301
+ return enrollPromise ;
302
+ } ) ;
303
+
225
304
it ( 'registers a renew timer when device is enrolled' , async ( ) => {
226
305
const conversationState = container . resolve ( ConversationState ) ;
227
306
jest . spyOn ( conversationState , 'getSelfMLSConversation' ) . mockReturnValue ( new Conversation ( ) as any ) ;
0 commit comments