|
1 |
| -import { describe, expect, it, beforeEach } from "vitest"; |
| 1 | +import { describe, expect, it, beforeEach, vi } from "vitest"; |
2 | 2 | import { MemoryStorage, StorageKeys } from "../../sessionManager";
|
3 | 3 | import { getUserProfile, setActiveStorage } from ".";
|
4 | 4 | import { createMockAccessToken } from "./testUtils";
|
@@ -53,4 +53,32 @@ describe("getUserProfile", () => {
|
53 | 53 | picture: "https://kinde.com/",
|
54 | 54 | });
|
55 | 55 | });
|
| 56 | + |
| 57 | + it("when no sub, return null", async () => { |
| 58 | + await storage.setSessionItem( |
| 59 | + StorageKeys.idToken, |
| 60 | + createMockAccessToken({ |
| 61 | + sub: null, |
| 62 | + }), |
| 63 | + ); |
| 64 | + const idToken = await getUserProfile(); |
| 65 | + |
| 66 | + expect(idToken).toStrictEqual(null); |
| 67 | + }); |
| 68 | + |
| 69 | + it("when no sub, return null", async () => { |
| 70 | + const consoleMock = vi |
| 71 | + .spyOn(console, "error") |
| 72 | + .mockImplementation(() => undefined); |
| 73 | + |
| 74 | + await storage.setSessionItem( |
| 75 | + StorageKeys.idToken, |
| 76 | + createMockAccessToken({ |
| 77 | + sub: null, |
| 78 | + }), |
| 79 | + ); |
| 80 | + await getUserProfile(); |
| 81 | + |
| 82 | + expect(consoleMock).toHaveBeenCalledWith("No sub in idToken"); |
| 83 | + }); |
56 | 84 | });
|
0 commit comments