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.
63 lines
2.5 KiB
TypeScript
63 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 { VacayUserSettings } from '../../../../src/db/entities/VacayUserSettings.entity';
|
|
import type { VacayUserSettingsRepository } from '../../../../src/db/repositories/VacayUserSettings.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: 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();
|
|
});
|
|
});
|