mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
test(server): snapshot harness keeps the legacy id semantics
This commit is contained in:
@@ -46,6 +46,16 @@ export function createSnapshotTestDb(): Database.Database {
|
||||
db.exec('PRAGMA journal_mode = WAL');
|
||||
db.exec('PRAGMA busy_timeout = 5000');
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
// The snapshot carries the first-run seeded `admin` row (id 1); the legacy
|
||||
// createTestDb() started with no users at all, so the first user a test
|
||||
// created was always id 1. Normalise ONCE, here, rather than resetting the
|
||||
// sequence on every resetTestDb() call: ids then keep growing across tests
|
||||
// within a file exactly as they did under the legacy helper, which several
|
||||
// suites (oauth.test.ts's per-user client cap, mcp.test.ts's in-memory
|
||||
// session registry, memories-synology.test.ts's insert-once fixtures) rely
|
||||
// on to stay disjoint from one test to the next.
|
||||
db.exec('DELETE FROM users');
|
||||
db.exec("DELETE FROM sqlite_sequence WHERE name = 'users'");
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
@@ -248,14 +248,13 @@ export function resetTestDb(db: Database.Database): void {
|
||||
db.exec(`DELETE FROM "${table}"`);
|
||||
}
|
||||
}
|
||||
// Restart ids at 1, exactly as a fresh legacy database did — the snapshot's
|
||||
// seeded `admin` user (id 1) was just deleted above, and the factories assume
|
||||
// a clean autoincrement sequence.
|
||||
const seqTable = existingTables.has('sqlite_sequence');
|
||||
if (seqTable) {
|
||||
const clear = db.prepare('DELETE FROM sqlite_sequence WHERE name = ?');
|
||||
for (const table of RESET_TABLES) if (existingTables.has(table)) clear.run(table);
|
||||
}
|
||||
// No sqlite_sequence reset here, on purpose: the legacy helper never reset
|
||||
// sequences either, so ids keep growing across tests within a file. Several
|
||||
// suites (oauth.test.ts's per-user client cap, mcp.test.ts's in-memory
|
||||
// session registry keyed by user id, memories-synology.test.ts's
|
||||
// insert-once fixtures) rely on that to stay disjoint from one test to the
|
||||
// next. The snapshot's one seeded row (the first-run `admin` user) is
|
||||
// normalised away once, in createSnapshotTestDb() (db-mock.ts), not here.
|
||||
db.exec('PRAGMA foreign_keys = ON');
|
||||
seedDefaults(db);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,11 @@ beforeEach(() => {
|
||||
resetRateLimits(nestApp);
|
||||
// Providers only count as enabled under an enabled journey addon (migration 84 seeds it off).
|
||||
setAddonEnabled(testDb, 'journey', true);
|
||||
// The migrated snapshot seeds photo_providers.immich.enabled = 0 (an admin must
|
||||
// configure it before it's usable in production); the legacy test helper always
|
||||
// seeded it enabled, which is what these tests assume. Same convention
|
||||
// memories-synology.test.ts already uses for its own provider.
|
||||
testDb.prepare("UPDATE photo_providers SET enabled = 1 WHERE id = 'immich'").run();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
||||
@@ -219,6 +219,11 @@ beforeEach(() => {
|
||||
resetRateLimits(nestApp);
|
||||
// Providers only count as enabled under an enabled journey addon (migration 84 seeds it off).
|
||||
setAddonEnabled(testDb, 'journey', true);
|
||||
// The migrated snapshot seeds photo_providers.immich.enabled = 0 (an admin must
|
||||
// configure it before it's usable in production); the legacy test helper always
|
||||
// seeded it enabled, which is what these tests assume. Same convention
|
||||
// memories-synology.test.ts already uses for its own provider.
|
||||
testDb.prepare("UPDATE photo_providers SET enabled = 1 WHERE id = 'immich'").run();
|
||||
immichState.albumAssets = DEFAULT_ALBUM_ASSETS.map((a) => ({ ...a }));
|
||||
immichState.albumAssetPages = null;
|
||||
immichState.searchCalls = [];
|
||||
|
||||
@@ -57,6 +57,11 @@ beforeEach(() => {
|
||||
resetRateLimits(nestApp);
|
||||
// Providers only count as enabled under an enabled journey addon (migration 84 seeds it off).
|
||||
setAddonEnabled(testDb, 'journey', true);
|
||||
// The migrated snapshot seeds photo_providers.immich.enabled = 0 (an admin must
|
||||
// configure it before it's usable in production); the legacy test helper always
|
||||
// seeded it enabled, which is what these tests assume. Same convention
|
||||
// memories-synology.test.ts already uses for its own provider.
|
||||
testDb.prepare("UPDATE photo_providers SET enabled = 1 WHERE id = 'immich'").run();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
||||
Reference in New Issue
Block a user