mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +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.
50 lines
2.5 KiB
TypeScript
50 lines
2.5 KiB
TypeScript
/**
|
|
* VacayUserSettingsRepository.findForUser — Plan 4 Task 8b-2 item 3 (3f L6
|
|
* carry): "user year settings and settings" (VC3, `getUserYearSettings`)
|
|
* 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 { VacayUserSettings } from '../../../../src/db/entities/VacayUserSettings.entity';
|
|
import type { VacayUserSettingsRepository } from '../../../../src/db/repositories/VacayUserSettings.repository';
|
|
import { insertRow } from '../../../helpers/factories/rows';
|
|
|
|
const testDb = createSnapshotTestDb();
|
|
let t: TestOrm;
|
|
let repo: VacayUserSettingsRepository;
|
|
|
|
beforeAll(async () => {
|
|
t = await createTestOrm(testDb);
|
|
repo = t.repo(VacayUserSettings);
|
|
});
|
|
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
|
afterAll(async () => { await t.close(); testDb.close(); });
|
|
|
|
describe('VacayUserSettingsRepository.findForUser (VC3, getUserYearSettings)', () => {
|
|
it('VACAYUSETREPO-001: matches SELECT * FROM vacay_user_settings WHERE user_id = ? run raw, hire_date both NULL and SET', async () => {
|
|
const { user } = createUser(testDb);
|
|
await insertRow(t, VacayUserSettings, { user: user.id, year_type: 'fiscal', year_start_month: 4, year_start_day: 1, hire_date: '2020-06-15' });
|
|
|
|
// 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_settings WHERE user_id = ?').get(user.id);
|
|
expect(await repo.findForUser(user.id)).toEqual(legacy);
|
|
});
|
|
|
|
it('VACAYUSETREPO-002: hire_date NULL matches the legacy row too', async () => {
|
|
const { user } = createUser(testDb);
|
|
await insertRow(t, VacayUserSettings, { user: user.id });
|
|
|
|
// 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_settings WHERE user_id = ?').get(user.id);
|
|
expect(await repo.findForUser(user.id)).toEqual(legacy);
|
|
});
|
|
|
|
it('VACAYUSETREPO-003: null when the user has no settings row (schema defaults apply at the service layer)', async () => {
|
|
const { user } = createUser(testDb);
|
|
expect(await repo.findForUser(user.id)).toBeNull();
|
|
});
|
|
});
|