Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/nperez0111/bookhive. Track your books, share your shelves, see what others are reading bookhive.buzz
atproto bluesky books bookshelf goodreads management-system
Something went wrong. Try again.
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import { describe, it, expect, mock } from "bun:test";import { getIronSession } from "iron-session";
// Mock iron-sessionconst mockGetIronSession = mock();void mock.module("iron-session", () => ({ getIronSession: mockGetIronSession,}));
// Mock environmentvoid mock.module("../env", () => ({ env: { COOKIE_SECRET: "test-secret-key-for-testing-purposes-only", },}));
describe("Auth Session TTL Logic", () => { it("should set session TTL to 24 hours regardless of token expiration", async () => { const mockSession = { updateConfig: mock(), save: mock(), destroy: mock(), };
mockGetIronSession.mockResolvedValueOnce(mockSession);
const mockReq = {} as any; const mockRes = {} as any;
await getIronSession(mockReq, mockRes, { cookieName: "sid", password: "test-secret-key-for-testing-purposes-only", ttl: 60 * 60 * 24, });
expect(getIronSession).toHaveBeenCalledWith( mockReq, mockRes, expect.objectContaining({ cookieName: "sid", password: "test-secret-key-for-testing-purposes-only", ttl: 86400, }), ); });
it("should use fixed TTL instead of token expiration time", () => { const fixedTTL = 60 * 60 * 24; const tokenExpirationInSeconds = 30 * 60;
expect(fixedTTL).toBe(86400); expect(fixedTTL).toBeGreaterThan(tokenExpirationInSeconds); });
it("should maintain session longer than typical OAuth token lifetime", () => { const sessionTTL = 60 * 60 * 24; const typicalOAuthTokenLifetime = 30 * 60;
expect(sessionTTL).toBeGreaterThan(typicalOAuthTokenLifetime * 10); });});