Files
TREK/server/tests/unit/db/repositories/HiddenRegions.repository.test.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

54 lines
2.2 KiB
TypeScript

/**
* `HiddenRegionsRepository.listForUser` — Plan 4 Task 8b-2 item 3 (3f L6
* carry): AT22 (`getHiddenRegions`) had no repository-level
* `toEqual(<legacy raw>)` parity test.
*/
import { HiddenRegions } from '../../../../src/db/entities/HiddenRegions.entity';
import type { HiddenRegionsRepository } from '../../../../src/db/repositories/HiddenRegions.repository';
import { createSnapshotTestDb } from '../../../helpers/db-mock';
import { createUser } from '../../../helpers/factories';
import { insertRow } from '../../../helpers/factories/rows';
import { resetTestDb } from '../../../helpers/test-db';
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
const testDb = createSnapshotTestDb();
let t: TestOrm;
let repo: HiddenRegionsRepository;
beforeAll(async () => {
t = await createTestOrm(testDb);
repo = t.repo(HiddenRegions);
});
beforeEach(() => {
resetTestDb(testDb);
t.clear();
});
afterAll(async () => {
await t.close();
testDb.close();
});
describe('HiddenRegionsRepository.listForUser (AT22)', () => {
it('HIDDENREGREPO-001: matches SELECT region_code FROM hidden_regions WHERE user_id = ? run raw, scoped to the user', async () => {
const { user } = createUser(testDb);
const { user: other } = createUser(testDb, { username: 'other' });
await insertRow(t, HiddenRegions, { user: user.id, region_code: 'DE-BY', country_code: 'DE' });
await insertRow(t, HiddenRegions, { user: user.id, region_code: 'DE-BE', country_code: 'DE' });
await insertRow(t, HiddenRegions, { user: other.id, region_code: 'FR-IDF', country_code: 'FR' });
// test-sql-allow: the legacy AT22 statement is the parity oracle the repository is compared against.
const legacy = testDb.prepare('SELECT region_code FROM hidden_regions WHERE user_id = ?').all(user.id);
const codes = await repo.listForUser(user.id);
expect(codes).toEqual(legacy.map((r) => (r as { region_code: string }).region_code));
expect(codes.sort()).toEqual(['DE-BE', 'DE-BY']);
});
it('HIDDENREGREPO-002: empty array for a user with nothing hidden', async () => {
const { user } = createUser(testDb);
expect(await repo.listForUser(user.id)).toEqual([]);
});
});