diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-08 17:06:51 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-08 17:06:51 +0200 |
| commit | bd2f982c489b15ce1165c051fdedf35af979f784 (patch) | |
| tree | 5c76d07f94b34f6b7b31be6a133793b2cdaccd79 /src/lib/server/auth.test.ts | |
| parent | 6d69c7b1e6a8051338e052cc9d1836f4f1a20f51 (diff) | |
Migrate date handling from Date to Temporal API
Routine scheduling, health series, service stamps, session expiry, and
date formatting move to native Temporal (Instant / ZonedDateTime in
UTC), with ISO strings kept at DB and chart boundaries. Ambient types
in src/temporal-ambient.d.ts cover the native runtime; no polyfill.
Observable behavior and stored formats are unchanged.
Diffstat (limited to 'src/lib/server/auth.test.ts')
| -rw-r--r-- | src/lib/server/auth.test.ts | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/lib/server/auth.test.ts b/src/lib/server/auth.test.ts index 59ddabc..d19aa03 100644 --- a/src/lib/server/auth.test.ts +++ b/src/lib/server/auth.test.ts @@ -12,7 +12,7 @@ import { const TEST_PASSWORD = vi.hoisted(() => { return 'family-password-5f2c1d7e'; }); -const NOW = 1_800_000_000_000; +const NOW = Temporal.Instant.fromEpochMilliseconds(1_800_000_000_000); vi.mock('$env/dynamic/private', () => ({ env: { AUTH_PASSWORD: TEST_PASSWORD }, @@ -27,12 +27,12 @@ describe('authentication', () => { it('accepts a signed session until its expiry', () => { const session = createSession(NOW); - expect( - isValidSession(session, NOW + SESSION_MAX_AGE_SECONDS * 1000 - 1), - ).toBe(true); - expect(isValidSession(session, NOW + SESSION_MAX_AGE_SECONDS * 1000)).toBe( - false, - ); + const almostExpired = NOW.add({ + milliseconds: SESSION_MAX_AGE_SECONDS * 1000 - 1, + }); + expect(isValidSession(session, almostExpired)).toBe(true); + const expired = NOW.add({ milliseconds: SESSION_MAX_AGE_SECONDS * 1000 }); + expect(isValidSession(session, expired)).toBe(false); expect(isValidSession(`${session}x`, NOW)).toBe(false); }); @@ -43,7 +43,9 @@ describe('authentication', () => { set: vi.fn(), } as unknown as Cookies; - expect(renewSession(cookies, true, NOW + 1_000)).toBe(true); + expect(renewSession(cookies, true, NOW.add({ milliseconds: 1_000 }))).toBe( + true, + ); expect(cookies.set).toHaveBeenCalledWith( AUTH_COOKIE_NAME, expect.any(String), |
