1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import "reflect-metadata";
|
24 | import PopUpLoginHandler from "../../../src/login/popUp/PopUpLoginHandler";
|
25 | import { SessionInfoManagerMock } from "../../../src/sessionInfo/__mocks__/SessionInfoManager";
|
26 | import { LoginHandlerMock } from "../../../src/login/__mocks__/LoginHandler";
|
27 |
|
28 | describe("PopUpLoginHandler", () => {
|
29 | const defaultMocks = {
|
30 | loginHandler: LoginHandlerMock,
|
31 | sessionCreator: SessionInfoManagerMock,
|
32 | };
|
33 | function getInitialisedHandler(
|
34 | mocks: Partial<typeof defaultMocks> = defaultMocks
|
35 | ): PopUpLoginHandler {
|
36 | return new PopUpLoginHandler(
|
37 | mocks.loginHandler ?? defaultMocks.loginHandler,
|
38 | mocks.sessionCreator ?? defaultMocks.sessionCreator
|
39 | );
|
40 | }
|
41 |
|
42 | describe("canHandle", () => {
|
43 | it("Accepts a configuration for popup", async () => {
|
44 | const handler = getInitialisedHandler();
|
45 | expect(
|
46 | await handler.canHandle({
|
47 | sessionId: "mySession",
|
48 | popUp: true,
|
49 | redirectUrl: "/redirect",
|
50 | tokenType: "DPoP",
|
51 | })
|
52 | ).toBe(true);
|
53 | });
|
54 | it("Rejects a configuration not for popup", async () => {
|
55 | const handler = getInitialisedHandler();
|
56 | expect(
|
57 | await handler.canHandle({
|
58 | sessionId: "mySession",
|
59 | popUp: false,
|
60 | redirectUrl: "https://coolsite.com/redirect",
|
61 | tokenType: "DPoP",
|
62 | })
|
63 | ).toBe(false);
|
64 | });
|
65 | });
|
66 |
|
67 | describe("handle", () => {
|
68 | it("is unimplemented", async () => {
|
69 | const handler = getInitialisedHandler();
|
70 | await expect(
|
71 | handler.handle({
|
72 | sessionId: "mySession",
|
73 | popUp: true,
|
74 | tokenType: "DPoP",
|
75 | })
|
76 | ).rejects.toThrow("Popup login is not implemented yet");
|
77 | });
|
78 | });
|
79 | });
|