From 9c6a905788e0280dc103e072fffb74ad4ff253e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 9 Apr 2026 18:06:02 +0800 Subject: [PATCH] fix: improve test coverage accuracy and fix session timestamp bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Exclude seed files from coverage (not business logic) - Fix Date.now() double call bug in createSession functions - Coverage improved: 53.13% → 54.18% - All 122 test suites passing --- jest.config.js | 1 + src/lib/auth/session.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/jest.config.js b/jest.config.js index 409d9f0..2b26a20 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,6 +8,7 @@ module.exports = { '!src/**/*.d.ts', '!src/**/*.stories.{ts,tsx}', '!src/**/__tests__/**', + '!src/db/seed*.ts', ], coverageThreshold: { global: { diff --git a/src/lib/auth/session.ts b/src/lib/auth/session.ts index 18f2e1f..51a8401 100644 --- a/src/lib/auth/session.ts +++ b/src/lib/auth/session.ts @@ -9,10 +9,11 @@ export interface Session extends SessionData { } export function createSession(userData: SessionData): Session { + const now = Date.now(); return { ...userData, - createdAt: Date.now(), - expiresAt: Date.now() + (24 * 60 * 60 * 1000), + createdAt: now, + expiresAt: now + (24 * 60 * 60 * 1000), }; } @@ -33,9 +34,10 @@ export function isSessionExpired(session: Session): boolean { } export function createSessionWithCustomExpiration(userData: SessionData, expiresInMs: number): Session { + const now = Date.now(); return { ...userData, - createdAt: Date.now(), - expiresAt: Date.now() + expiresInMs, + createdAt: now, + expiresAt: now + expiresInMs, }; }