@@ -2,12 +2,14 @@ import { TestBed } from "@angular/core/testing";
2
2
import {
3
3
AuthenticationResult ,
4
4
AuthError ,
5
+ InteractionStatus ,
5
6
InteractionType ,
6
7
Logger ,
7
8
PublicClientApplication ,
8
9
SilentRequest ,
9
10
} from "@azure/msal-browser" ;
10
11
import { MsalModule , MsalBroadcastService , MsalService } from "./public-api" ;
12
+ import { takeLast } from "rxjs/operators" ;
11
13
12
14
let authService : MsalService ;
13
15
let broadcastService : MsalBroadcastService ;
@@ -30,6 +32,7 @@ function initializeMsal() {
30
32
} ) ,
31
33
] ,
32
34
providers : [ MsalService , MsalBroadcastService ] ,
35
+ teardown : { destroyAfterEach : false } ,
33
36
} ) ;
34
37
35
38
authService = TestBed . inject ( MsalService ) ;
@@ -198,7 +201,7 @@ describe("MsalService", () => {
198
201
199
202
authService . ssoSilent ( request ) . subscribe ( {
200
203
error : ( error : AuthError ) => {
201
- expect ( error . message ) . toBe ( sampleError . message ) ;
204
+ expect ( error . errorMessage ) . toBe ( sampleError . errorMessage ) ;
202
205
expect (
203
206
PublicClientApplication . prototype . ssoSilent
204
207
) . toHaveBeenCalledWith ( request ) ;
@@ -259,7 +262,7 @@ describe("MsalService", () => {
259
262
260
263
authService . acquireTokenSilent ( request ) . subscribe ( {
261
264
error : ( error : AuthError ) => {
262
- expect ( error . message ) . toBe ( sampleError . message ) ;
265
+ expect ( error . errorMessage ) . toBe ( sampleError . errorMessage ) ;
263
266
expect (
264
267
PublicClientApplication . prototype . acquireTokenSilent
265
268
) . toHaveBeenCalledWith ( request ) ;
@@ -339,7 +342,7 @@ describe("MsalService", () => {
339
342
340
343
authService . acquireTokenPopup ( request ) . subscribe ( {
341
344
error : ( error : AuthError ) => {
342
- expect ( error . message ) . toBe ( sampleError . message ) ;
345
+ expect ( error . errorMessage ) . toBe ( sampleError . errorMessage ) ;
343
346
expect (
344
347
PublicClientApplication . prototype . acquireTokenPopup
345
348
) . toHaveBeenCalledWith ( request ) ;
@@ -350,11 +353,14 @@ describe("MsalService", () => {
350
353
} ) ;
351
354
352
355
describe ( "handleRedirectObservable" , ( ) => {
353
- it ( "success" , ( done ) => {
356
+ it ( "success and resets inProgress event to none " , ( done ) => {
354
357
const sampleAccessToken = {
355
358
accessToken : "123abc" ,
356
359
} ;
357
360
361
+ //@ts -ignore
362
+ broadcastService . _inProgress . next ( InteractionStatus . Startup ) ;
363
+
358
364
spyOn ( PublicClientApplication . prototype , "initialize" ) . and . returnValue (
359
365
Promise . resolve ( )
360
366
) ;
@@ -379,13 +385,19 @@ describe("MsalService", () => {
379
385
expect (
380
386
PublicClientApplication . prototype . handleRedirectPromise
381
387
) . toHaveBeenCalled ( ) ;
388
+ broadcastService . inProgress$ . subscribe ( ( result ) => {
389
+ expect ( result ) . toBe ( InteractionStatus . None ) ;
390
+ } ) ;
382
391
done ( ) ;
383
392
} ) ;
384
393
} ) ;
385
394
386
- it ( "failure" , ( done ) => {
395
+ it ( "failure and also resets inProgress event to none " , ( done ) => {
387
396
const sampleError = new AuthError ( "123" , "message" ) ;
388
397
398
+ //@ts -ignore
399
+ broadcastService . _inProgress . next ( InteractionStatus . Startup ) ;
400
+
389
401
spyOn ( PublicClientApplication . prototype , "initialize" ) . and . returnValue (
390
402
Promise . resolve ( )
391
403
) ;
@@ -408,6 +420,10 @@ describe("MsalService", () => {
408
420
expect (
409
421
PublicClientApplication . prototype . handleRedirectPromise
410
422
) . toHaveBeenCalled ( ) ;
423
+ broadcastService . inProgress$ . pipe ( takeLast ( 1 ) ) . subscribe ( ( result ) => {
424
+ console . log ( "failure result" , result ) ;
425
+ expect ( result ) . toBe ( InteractionStatus . None ) ;
426
+ } ) ;
411
427
done ( ) ;
412
428
} ,
413
429
} ) ;
0 commit comments