Skip to content

Commit a6f98be

Browse files
committed
added and updated unit test for bug fix
1 parent 1276e2f commit a6f98be

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

lib/msal-angular/src/msal.broadcast.service.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,32 @@ describe("MsalBroadcastService", () => {
443443
InteractionType.Redirect
444444
);
445445
});
446+
447+
it("automatically sets inProgress to None when handleRedirectPromise returns without emitting HANDLE_REDIRECT_END", (done) => {
448+
const expectedInProgress = [
449+
InteractionStatus.Startup,
450+
InteractionStatus.HandleRedirect,
451+
InteractionStatus.None,
452+
];
453+
let index = 0;
454+
455+
subscription = broadcastService.inProgress$.subscribe((result) => {
456+
expect(result).toEqual(expectedInProgress[index]);
457+
if (index === expectedInProgress.length - 1) {
458+
done();
459+
} else if (
460+
expectedInProgress[index] === InteractionStatus.HandleRedirect
461+
) {
462+
index++;
463+
broadcastService.resetInProgressEvent();
464+
} else {
465+
index++;
466+
}
467+
});
468+
469+
eventHandler.emitEvent(
470+
EventType.HANDLE_REDIRECT_START,
471+
InteractionType.Redirect
472+
);
473+
});
446474
});

lib/msal-angular/src/msal.service.spec.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { TestBed } from "@angular/core/testing";
22
import {
33
AuthenticationResult,
44
AuthError,
5+
InteractionStatus,
56
InteractionType,
67
Logger,
78
PublicClientApplication,
89
SilentRequest,
910
} from "@azure/msal-browser";
1011
import { MsalModule, MsalBroadcastService, MsalService } from "./public-api";
12+
import { takeLast } from "rxjs/operators";
1113

1214
let authService: MsalService;
1315
let broadcastService: MsalBroadcastService;
@@ -351,11 +353,14 @@ describe("MsalService", () => {
351353
});
352354

353355
describe("handleRedirectObservable", () => {
354-
it("success", (done) => {
356+
it("success and resets inProgress event to none", (done) => {
355357
const sampleAccessToken = {
356358
accessToken: "123abc",
357359
};
358360

361+
//@ts-ignore
362+
broadcastService._inProgress.next(InteractionStatus.Startup);
363+
359364
spyOn(PublicClientApplication.prototype, "initialize").and.returnValue(
360365
Promise.resolve()
361366
);
@@ -380,13 +385,19 @@ describe("MsalService", () => {
380385
expect(
381386
PublicClientApplication.prototype.handleRedirectPromise
382387
).toHaveBeenCalled();
388+
broadcastService.inProgress$.subscribe((result) => {
389+
expect(result).toBe(InteractionStatus.None);
390+
});
383391
done();
384392
});
385393
});
386394

387-
it("failure", (done) => {
395+
it("failure and also resets inProgress event to none", (done) => {
388396
const sampleError = new AuthError("123", "message");
389397

398+
//@ts-ignore
399+
broadcastService._inProgress.next(InteractionStatus.Startup);
400+
390401
spyOn(PublicClientApplication.prototype, "initialize").and.returnValue(
391402
Promise.resolve()
392403
);
@@ -409,6 +420,10 @@ describe("MsalService", () => {
409420
expect(
410421
PublicClientApplication.prototype.handleRedirectPromise
411422
).toHaveBeenCalled();
423+
broadcastService.inProgress$.pipe(takeLast(1)).subscribe((result) => {
424+
console.log("failure result", result);
425+
expect(result).toBe(InteractionStatus.None);
426+
});
412427
done();
413428
},
414429
});

0 commit comments

Comments
 (0)