From 0fa47e4297db71b8075d8970db388d8b56782d61 Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 8 Oct 2026 19:18:42 +0200 Subject: [PATCH] test(demo): give the session reset spec a baseline to reset to resetDemoUser returns early when no baseline file exists and asks the port whether it can snapshot, so the spec needs both to reach the swap. --- server/tests/unit/demo/demo-reset-sessions.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/tests/unit/demo/demo-reset-sessions.test.ts b/server/tests/unit/demo/demo-reset-sessions.test.ts index ba33ffe9d..b09b8fe13 100644 --- a/server/tests/unit/demo/demo-reset-sessions.test.ts +++ b/server/tests/unit/demo/demo-reset-sessions.test.ts @@ -12,6 +12,8 @@ * The reads and writes around it run for real against the snapshot schema. */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import fs from 'node:fs'; +import path from 'node:path'; import type Database from 'better-sqlite3'; import { createSnapshotTestDb } from '../../helpers/db-mock'; import { createTestOrm, type TestOrm } from '../../helpers/test-orm'; @@ -25,6 +27,8 @@ import { verifyJwtAndLoadUser } from '../../../src/nest/auth/jwt-verify'; import { Users } from '../../../src/db/entities/Users.entity'; import { UserSessions } from '../../../src/db/entities/UserSessions.entity'; +const BASELINE = path.resolve(__dirname, '..', '..', '..', 'data', 'travel-baseline.db'); + describe('demo reset and the signed-in sessions', () => { let ormDb: Database.Database; let t: TestOrm; @@ -36,10 +40,13 @@ describe('demo reset and the signed-in sessions', () => { vi.spyOn(console, 'log').mockImplementation(() => undefined); ormDb = createSnapshotTestDb(); t = await createTestOrm(ormDb); + // After the snapshot DB is built: it locates the migrations through fs.existsSync. + vi.spyOn(fs, 'existsSync').mockImplementation(((p: fs.PathLike) => String(p) === BASELINE) as typeof fs.existsSync); swap = async () => { await deleteRows(t, UserSessions); }; database = { + canSnapshot: () => true, checkpoint: vi.fn(async () => undefined), replace: vi.fn(async () => { await swap();