mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
514d5159ce
The repository suites for assignments, notifications, document sync, tags, photo metadata, vacay, day notes, notice dismissals, idempotency keys, settings, travellers, invites, providers, hidden regions, road trip tracks and the collection role check seeded their fixtures and read back what a write left behind with raw statements. Fixtures now go through the ORM factories and insertRow/updateRows, and the state reads through findRow/findRows/countRows. What stays raw is raw on purpose and carries a test-sql-allow marker: the legacy statements every parity case compares a repository against, the full raw rows used as such an oracle, PRAGMA reads, typeof() and date() storage checks, and the out-of-band writes the identity map freshness cases are about, which have to bypass every EntityManager.
47 lines
2.2 KiB
TypeScript
47 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 { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
|
import { resetTestDb } from '../../../helpers/test-db';
|
|
import { createTestOrm, type TestOrm } from '../../../helpers/test-orm';
|
|
import { createUser } from '../../../helpers/factories';
|
|
import { HiddenRegions } from '../../../../src/db/entities/HiddenRegions.entity';
|
|
import type { HiddenRegionsRepository } from '../../../../src/db/repositories/HiddenRegions.repository';
|
|
import { insertRow } from '../../../helpers/factories/rows';
|
|
|
|
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([]);
|
|
});
|
|
});
|