mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +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.
61 lines
3.0 KiB
TypeScript
61 lines
3.0 KiB
TypeScript
/**
|
|
* VacayUserYearsRepository.findForYear — Plan 4 Task 8b-2 item 3 (3f L6
|
|
* carry): "getStats rows, including a NULL vacation_days row" (VC34/98/109/
|
|
* 123) 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 { VacayUserYears } from '../../../../src/db/entities/VacayUserYears.entity';
|
|
import type { VacayUserYearsRepository } from '../../../../src/db/repositories/VacayUserYears.repository';
|
|
import { insertRow } from '../../../helpers/factories/rows';
|
|
import { makeVacayPlan } from '../../../helpers/factories/vacay';
|
|
|
|
const testDb = createSnapshotTestDb();
|
|
let t: TestOrm;
|
|
let repo: VacayUserYearsRepository;
|
|
|
|
beforeAll(async () => {
|
|
t = await createTestOrm(testDb);
|
|
repo = t.repo(VacayUserYears);
|
|
});
|
|
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
|
afterAll(async () => { await t.close(); testDb.close(); });
|
|
|
|
async function insertPlan(ownerId: number): Promise<number> {
|
|
return (await makeVacayPlan(t, ownerId)).id;
|
|
}
|
|
|
|
describe('VacayUserYearsRepository.findForYear (VC34/98/109/123, getStats)', () => {
|
|
it('VACAYUYEARREPO-001: matches the legacy row with vacation_days SET (30)', async () => {
|
|
const { user } = createUser(testDb);
|
|
const planId = await insertPlan(user.id);
|
|
await insertRow(t, VacayUserYears, { user: user.id, plan: planId, year: 2026, vacation_days: 25, carried_over: 3 });
|
|
|
|
// test-sql-allow: the legacy full-row SELECT is the parity oracle the repository is compared against.
|
|
const legacy = testDb.prepare('SELECT * FROM vacay_user_years WHERE user_id = ? AND plan_id = ? AND year = ?').get(user.id, planId, 2026);
|
|
expect(await repo.findForYear(user.id, planId, 2026)).toEqual(legacy);
|
|
});
|
|
|
|
it('VACAYUYEARREPO-002: matches the legacy row with vacation_days explicitly NULL — the review\'s named gap', async () => {
|
|
const { user } = createUser(testDb);
|
|
const planId = await insertPlan(user.id);
|
|
await insertRow(t, VacayUserYears, { user: user.id, plan: planId, year: 2027, vacation_days: null, carried_over: null });
|
|
|
|
// test-sql-allow: the legacy full-row SELECT is the parity oracle the repository is compared against.
|
|
const legacy = testDb.prepare('SELECT * FROM vacay_user_years WHERE user_id = ? AND plan_id = ? AND year = ?').get(user.id, planId, 2027);
|
|
const row = await repo.findForYear(user.id, planId, 2027);
|
|
expect(row).toEqual(legacy);
|
|
expect(row!.vacation_days).toBeNull();
|
|
expect(row!.carried_over).toBeNull();
|
|
});
|
|
|
|
it('VACAYUYEARREPO-003: null for a year with no row', async () => {
|
|
const { user } = createUser(testDb);
|
|
const planId = await insertPlan(user.id);
|
|
expect(await repo.findForYear(user.id, planId, 2099)).toBeNull();
|
|
});
|
|
});
|