This commit is contained in:
Nabil Ahmed 2026-10-04 10:36:43 +09:00 • committed by GitHub
commit 96dc59d294
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View file

@ -118,6 +118,40 @@ describe("loginCall - storeLoginToken integration", () => {
});
});
describe("exchangeLoginCode - storeLoginToken integration", () => {
const originalFetch = global.fetch;
beforeEach(() => {
vi.clearAllMocks();
});
afterEach(() => {
global.fetch = originalFetch;
});
it("calls storeLoginToken when exchange response includes token", async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ token: "sso-jwt" }),
}) as unknown as typeof global.fetch;
const { storeLoginToken } = await import("@/utils/cookieUtils");
const token = await Networking.exchangeLoginCode("some-login-code");
expect(token).toBe("sso-jwt");
expect(storeLoginToken).toHaveBeenCalledWith("sso-jwt");
});
it("does not call storeLoginToken when exchange response has no token", async () => {
global.fetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({}),
}) as unknown as typeof global.fetch;
const { storeLoginToken } = await import("@/utils/cookieUtils");
const token = await Networking.exchangeLoginCode("some-login-code");
expect(token).toBeUndefined();
expect(storeLoginToken).not.toHaveBeenCalled();
});
});
describe("modelInfoCall", () => {
let currentFetch: typeof global.fetch;

View file

@ -7000,7 +7000,7 @@ export const exchangeLoginCode = async (code: string, workerBaseUrl?: string | n
const data = await response.json();
if (data.token) {
document.cookie = `token=${data.token}; path=/; SameSite=Lax`;
storeLoginToken(data.token);
}
return data.token;
};