oauthCachedSessionRestore.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { describe, expect, it, vi } from "vitest";
  2. import { applyCachedOAuthSessionRestoreResult } from "@/root/oauthCachedSessionRestore.js";
  3. describe("applyCachedOAuthSessionRestoreResult", () => {
  4. it("clears the displayed user, shows one expiry alert, then opens reauthentication", async () => {
  5. const setUser = vi.fn();
  6. const requestAlert = vi.fn(async () => undefined);
  7. const onReauthenticationRequired = vi.fn();
  8. await applyCachedOAuthSessionRestoreResult({
  9. result: {
  10. status: "reauthentication-required",
  11. reason: "jwt-expired",
  12. },
  13. setUser,
  14. requestAlert,
  15. onReauthenticationRequired,
  16. copy: {
  17. title: "登录已过期",
  18. description: "为了保障账号安全,请重新登录。",
  19. actionLabel: "重新登录",
  20. },
  21. });
  22. expect(setUser).toHaveBeenCalledWith(null);
  23. expect(requestAlert).toHaveBeenCalledTimes(1);
  24. expect(requestAlert).toHaveBeenCalledWith({
  25. title: "登录已过期",
  26. description: "为了保障账号安全,请重新登录。",
  27. actionLabel: "重新登录",
  28. });
  29. expect(onReauthenticationRequired).toHaveBeenCalledTimes(1);
  30. expect(requestAlert.mock.invocationCallOrder[0]).toBeLessThan(
  31. onReauthenticationRequired.mock.invocationCallOrder[0],
  32. );
  33. });
  34. });