mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 11:36:05 +00:00
724c88c201
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.
78 lines
3.0 KiB
TypeScript
78 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 { VacayUserYears } from '../../../../src/db/entities/VacayUserYears.entity';
|
|
import type { VacayUserYearsRepository } from '../../../../src/db/repositories/VacayUserYears.repository';
|
|
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
|
import { createUser } from '../../../helpers/factories';
|
|
import { insertRow } from '../../../helpers/factories/rows';
|
|
import { makeVacayPlan } from '../../../helpers/factories/vacay';
|
|
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: 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();
|
|
});
|
|
});
|