mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
test(server): plan 4 — vacay read-model parity remainder (3f L6 carry)
Task 8b-2 item 3 (vacay half): full-key toEqual(<legacy raw>) coverage for the vacay read models the 3f Task 7 review's L6 finding listed as missing (minus VC81/82, already landed) — VacayPlans.findByOwner/findById (the getPlanData/getStats composite's own plan read), VacayYears.listForPlan (listYears), VacayCompanyHolidays.listForPlan (the company-holidays list), VacayHolidayCalendars.listForPlan/findById (holiday-calendar reads), VacayUserSettings.findForUser (user year settings), VacayUserYears. findForYear (getStats rows, including the NULL vacation_days case the review named explicitly), and VacayPlanMembers.listAvailableForFusion/ listPendingForPlan/listPendingForUser (the fusion and share pickers). Seven new standalone files — only VacayShares had a repository-level test before this. getSharedCalendars itself is a service-level composite over these same reads plus VacayCompanyHolidays.listDatesForRange (already exercised elsewhere); its own dedicated test is NOT added here.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* VacayCompanyHolidaysRepository.listForPlan — Plan 4 Task 8b-2 item 3 (3f
|
||||
* L6 carry): "the company-holidays list" (VC29/VC67) 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 { VacayCompanyHolidays } from '../../../../src/db/entities/VacayCompanyHolidays.entity';
|
||||
import type { VacayCompanyHolidaysRepository } from '../../../../src/db/repositories/VacayCompanyHolidays.repository';
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
let t: TestOrm;
|
||||
let repo: VacayCompanyHolidaysRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
repo = t.repo(VacayCompanyHolidays);
|
||||
});
|
||||
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
||||
afterAll(async () => { await t.close(); testDb.close(); });
|
||||
|
||||
function insertPlan(ownerId: number): number {
|
||||
return Number(testDb.prepare('INSERT INTO vacay_plans (owner_id) VALUES (?)').run(ownerId).lastInsertRowid);
|
||||
}
|
||||
|
||||
describe('VacayCompanyHolidaysRepository.listForPlan (VC29/67)', () => {
|
||||
it('VACAYCOHOLREPO-001: matches SELECT date, note FROM vacay_company_holidays WHERE plan_id = ? run raw, note both NULL and SET', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const planId = insertPlan(user.id);
|
||||
const other = insertPlan(createUser(testDb).user.id);
|
||||
testDb.prepare('INSERT INTO vacay_company_holidays (plan_id, date, note) VALUES (?, ?, ?)').run(planId, '2026-12-25', 'Christmas');
|
||||
testDb.prepare('INSERT INTO vacay_company_holidays (plan_id, date, note) VALUES (?, ?, ?)').run(planId, '2026-01-01', null);
|
||||
testDb.prepare('INSERT INTO vacay_company_holidays (plan_id, date, note) VALUES (?, ?, ?)').run(other, '2026-07-04', 'Not mine');
|
||||
|
||||
const legacy = testDb.prepare('SELECT date, note FROM vacay_company_holidays WHERE plan_id = ?').all(planId);
|
||||
const rows = await repo.listForPlan(planId);
|
||||
|
||||
expect(rows).toEqual(legacy);
|
||||
expect(rows.map((r) => r.date).sort()).toEqual(['2026-01-01', '2026-12-25']);
|
||||
});
|
||||
|
||||
it('VACAYCOHOLREPO-002: empty array for a plan with none', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const planId = insertPlan(user.id);
|
||||
expect(await repo.listForPlan(planId)).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* VacayHolidayCalendarsRepository — Plan 4 Task 8b-2 item 3 (3f L6 carry):
|
||||
* "holiday-calendar listForPlan / findById" (VC37/131, VC39/42) had no
|
||||
* repository-level `toEqual(<legacy raw>)` parity test. Appends after the
|
||||
* pre-existing `existsForSchoolRegion` per this file's own ownership rule
|
||||
* (SH14, untouched).
|
||||
*/
|
||||
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 { VacayHolidayCalendars } from '../../../../src/db/entities/VacayHolidayCalendars.entity';
|
||||
import type { VacayHolidayCalendarsRepository } from '../../../../src/db/repositories/VacayHolidayCalendars.repository';
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
let t: TestOrm;
|
||||
let repo: VacayHolidayCalendarsRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
repo = t.repo(VacayHolidayCalendars);
|
||||
});
|
||||
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
||||
afterAll(async () => { await t.close(); testDb.close(); });
|
||||
|
||||
function insertPlan(ownerId: number): number {
|
||||
return Number(testDb.prepare('INSERT INTO vacay_plans (owner_id) VALUES (?)').run(ownerId).lastInsertRowid);
|
||||
}
|
||||
|
||||
function insertCalendar(planId: number, overrides: Partial<{ type: string; region: string; label: string | null; color: string; sort_order: number }> = {}): number {
|
||||
const result = testDb.prepare(
|
||||
'INSERT INTO vacay_holiday_calendars (plan_id, type, region, label, color, sort_order) VALUES (?, ?, ?, ?, ?, ?)',
|
||||
).run(
|
||||
planId,
|
||||
overrides.type ?? 'public_holiday',
|
||||
overrides.region ?? 'DE',
|
||||
overrides.label === undefined ? null : overrides.label,
|
||||
overrides.color ?? '#fecaca',
|
||||
overrides.sort_order ?? 0,
|
||||
);
|
||||
return Number(result.lastInsertRowid);
|
||||
}
|
||||
|
||||
describe('VacayHolidayCalendarsRepository.listForPlan (VC37/131, getPlanData)', () => {
|
||||
it('VACAYHOLCALREPO-001: matches SELECT * FROM vacay_holiday_calendars WHERE plan_id = ? ORDER BY sort_order, id run raw, label both NULL and SET', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const planId = insertPlan(user.id);
|
||||
const other = insertPlan(createUser(testDb).user.id);
|
||||
const second = insertCalendar(planId, { region: 'DE', sort_order: 1, label: 'Bavaria' });
|
||||
const first = insertCalendar(planId, { region: 'FR', sort_order: 0, label: null });
|
||||
insertCalendar(other, { region: 'US' });
|
||||
|
||||
const legacy = testDb.prepare('SELECT * FROM vacay_holiday_calendars WHERE plan_id = ? ORDER BY sort_order ASC, id ASC').all(planId);
|
||||
const rows = await repo.listForPlan(planId);
|
||||
|
||||
expect(rows).toEqual(legacy);
|
||||
expect(rows.map((r) => r.id)).toEqual([first, second]);
|
||||
});
|
||||
|
||||
it('VACAYHOLCALREPO-002: empty array for a plan with none', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const planId = insertPlan(user.id);
|
||||
expect(await repo.listForPlan(planId)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('VacayHolidayCalendarsRepository.findById (VC39/42)', () => {
|
||||
it('VACAYHOLCALREPO-003: matches SELECT * FROM vacay_holiday_calendars WHERE id = ? run raw', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const planId = insertPlan(user.id);
|
||||
const id = insertCalendar(planId, { type: 'school_holiday', region: 'DE-BY', label: 'Summer' });
|
||||
|
||||
const legacy = testDb.prepare('SELECT * FROM vacay_holiday_calendars WHERE id = ?').get(id);
|
||||
expect(await repo.findById(id)).toEqual(legacy);
|
||||
});
|
||||
|
||||
it('VACAYHOLCALREPO-004: null for a missing id', async () => {
|
||||
expect(await repo.findById(999999)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* VacayPlanMembersRepository — Plan 4 Task 8b-2 item 3 (3f L6 carry): "the
|
||||
* share and fusion pickers" and the `getPlanData` pending-invite reads
|
||||
* (VC75 `getAvailableUsers`, VC129/130) 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 { VacayPlanMembers } from '../../../../src/db/entities/VacayPlanMembers.entity';
|
||||
import type { VacayPlanMembersRepository } from '../../../../src/db/repositories/VacayPlanMembers.repository';
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
let t: TestOrm;
|
||||
let repo: VacayPlanMembersRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
repo = t.repo(VacayPlanMembers);
|
||||
});
|
||||
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
||||
afterAll(async () => { await t.close(); testDb.close(); });
|
||||
|
||||
function insertPlan(ownerId: number): number {
|
||||
return Number(testDb.prepare('INSERT INTO vacay_plans (owner_id) VALUES (?)').run(ownerId).lastInsertRowid);
|
||||
}
|
||||
|
||||
function insertMember(planId: number, userId: number, status: string): number {
|
||||
return Number(testDb.prepare('INSERT INTO vacay_plan_members (plan_id, user_id, status) VALUES (?, ?, ?)').run(planId, userId, status).lastInsertRowid);
|
||||
}
|
||||
|
||||
describe('VacayPlanMembersRepository.listAvailableForFusion (VC75, getAvailableUsers — the fusion-candidate picker)', () => {
|
||||
it('VACAYMEMREPO-001: matches the legacy three-NOT-IN statement — excludes self, guests, existing plan members, any already-fused user, and the owner of an already-fused plan', async () => {
|
||||
const { user: me } = createUser(testDb);
|
||||
const planId = insertPlan(me.id);
|
||||
const { user: candidate } = createUser(testDb, { username: 'candidate' });
|
||||
const { user: existingMember } = createUser(testDb, { username: 'existingmember' });
|
||||
insertMember(planId, existingMember.id, 'pending');
|
||||
const { user: alreadyFusedElsewhere } = createUser(testDb, { username: 'fusedelsewhere' });
|
||||
const otherPlan = insertPlan(createUser(testDb, { username: 'otherowner' }).user.id);
|
||||
insertMember(otherPlan, alreadyFusedElsewhere.id, 'accepted');
|
||||
const { user: fusedPlanOwner } = createUser(testDb, { username: 'fusedplanowner' });
|
||||
const fusedPlan = insertPlan(fusedPlanOwner.id);
|
||||
const { user: theirFusedMember } = createUser(testDb, { username: 'theirfusedmember' });
|
||||
insertMember(fusedPlan, theirFusedMember.id, 'accepted');
|
||||
const { user: guest } = createUser(testDb, { username: 'guestuser' });
|
||||
testDb.prepare('UPDATE users SET is_guest = 1 WHERE id = ?').run(guest.id);
|
||||
|
||||
const legacy = testDb.prepare(`
|
||||
SELECT u.id, u.username, u.email FROM users u
|
||||
WHERE u.id != ? AND COALESCE(u.is_guest, 0) = 0
|
||||
AND u.id NOT IN (SELECT user_id FROM vacay_plan_members WHERE plan_id = ?)
|
||||
AND u.id NOT IN (SELECT user_id FROM vacay_plan_members WHERE status = 'accepted')
|
||||
AND u.id NOT IN (SELECT owner_id FROM vacay_plans WHERE id IN (SELECT plan_id FROM vacay_plan_members WHERE status = 'accepted'))
|
||||
ORDER BY u.username`).all(me.id, planId);
|
||||
|
||||
const typed = await repo.listAvailableForFusion(me.id, planId);
|
||||
expect(typed).toEqual(legacy);
|
||||
expect(typed.map((r) => r.id)).toContain(candidate.id);
|
||||
expect(typed.map((r) => r.id)).not.toContain(me.id);
|
||||
expect(typed.map((r) => r.id)).not.toContain(existingMember.id);
|
||||
expect(typed.map((r) => r.id)).not.toContain(alreadyFusedElsewhere.id);
|
||||
expect(typed.map((r) => r.id)).not.toContain(fusedPlanOwner.id);
|
||||
expect(typed.map((r) => r.id)).not.toContain(guest.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('VacayPlanMembersRepository.listPendingForPlan / listPendingForUser (VC129/130, getPlanData\'s share picker)', () => {
|
||||
it('VACAYMEMREPO-002: listPendingForPlan matches the legacy JOIN — outgoing invites the plan owner sent', async () => {
|
||||
const { user: owner } = createUser(testDb);
|
||||
const planId = insertPlan(owner.id);
|
||||
const { user: invitee } = createUser(testDb, { username: 'invitee' });
|
||||
insertMember(planId, invitee.id, 'pending');
|
||||
const { user: accepted } = createUser(testDb, { username: 'accepted' });
|
||||
insertMember(planId, accepted.id, 'accepted');
|
||||
|
||||
const legacy = testDb.prepare(`
|
||||
SELECT m.id, m.user_id, u.username, u.email, m.created_at
|
||||
FROM vacay_plan_members m JOIN users u ON m.user_id = u.id
|
||||
WHERE m.plan_id = ? AND m.status = 'pending'`).all(planId);
|
||||
|
||||
const typed = await repo.listPendingForPlan(planId);
|
||||
expect(typed).toEqual(legacy);
|
||||
expect(typed.map((r) => r.user_id)).toEqual([invitee.id]);
|
||||
});
|
||||
|
||||
it('VACAYMEMREPO-003: listPendingForUser matches the legacy JOIN — the OWNER\'s username/email, not the invited member\'s', async () => {
|
||||
const { user: owner } = createUser(testDb, { username: 'planowner' });
|
||||
const planId = insertPlan(owner.id);
|
||||
const { user: invitee } = createUser(testDb, { username: 'invitee' });
|
||||
insertMember(planId, invitee.id, 'pending');
|
||||
|
||||
const legacy = testDb.prepare(`
|
||||
SELECT m.id, m.plan_id, u.username, u.email, m.created_at
|
||||
FROM vacay_plan_members m JOIN vacay_plans p ON m.plan_id = p.id JOIN users u ON p.owner_id = u.id
|
||||
WHERE m.user_id = ? AND m.status = 'pending'`).all(invitee.id);
|
||||
|
||||
const typed = await repo.listPendingForUser(invitee.id);
|
||||
expect(typed).toEqual(legacy);
|
||||
expect(typed).toEqual([{ id: typed[0].id, plan_id: planId, username: 'planowner', email: owner.email, created_at: typed[0].created_at }]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* VacayPlansRepository — Plan 4 Task 8b-2 item 3 (3f L6 carry): the
|
||||
* `getPlanData`/`getStats` composite's own plan read (VC7/VC14, "the
|
||||
* hottest statement in this file") 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 { VacayPlans } from '../../../../src/db/entities/VacayPlans.entity';
|
||||
import type { VacayPlansRepository } from '../../../../src/db/repositories/VacayPlans.repository';
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
let t: TestOrm;
|
||||
let repo: VacayPlansRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
repo = t.repo(VacayPlans);
|
||||
});
|
||||
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
||||
afterAll(async () => { await t.close(); testDb.close(); });
|
||||
|
||||
function insertPlan(ownerId: number, overrides: Partial<{ block_weekends: number; holidays_enabled: number; holidays_region: string; school_holidays_enabled: number; company_holidays_enabled: number; carry_over_enabled: number; weekend_days: string; week_start: number }> = {}): number {
|
||||
const cols = Object.keys(overrides);
|
||||
const placeholders = cols.map(() => '?').join(', ');
|
||||
const extra = cols.length > 0 ? `, ${cols.join(', ')}` : '';
|
||||
const result = testDb.prepare(`INSERT INTO vacay_plans (owner_id${extra}) VALUES (?${cols.length > 0 ? ', ' + placeholders : ''})`)
|
||||
.run(ownerId, ...cols.map((c) => (overrides as Record<string, unknown>)[c]));
|
||||
return Number(result.lastInsertRowid);
|
||||
}
|
||||
|
||||
describe('VacayPlansRepository.findByOwner (VC7/9/78)', () => {
|
||||
it('VACAYPLANREPO-001: matches SELECT * FROM vacay_plans WHERE owner_id = ? run raw, every nullable column set', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const id = insertPlan(user.id, { holidays_region: 'DE', weekend_days: '["sat","sun"]', week_start: 1 });
|
||||
|
||||
const legacy = testDb.prepare('SELECT * FROM vacay_plans WHERE owner_id = ?').get(user.id);
|
||||
expect(await repo.findByOwner(user.id)).toEqual(legacy);
|
||||
expect((await repo.findByOwner(user.id))!.id).toBe(id);
|
||||
});
|
||||
|
||||
it('VACAYPLANREPO-002: null when the user has no plan', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
expect(await repo.findByOwner(user.id)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('VacayPlansRepository.findById (VC14, the hottest statement in this file)', () => {
|
||||
it('VACAYPLANREPO-003: matches SELECT * FROM vacay_plans WHERE id = ? run raw, defaulted columns included', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const id = insertPlan(user.id);
|
||||
|
||||
const legacy = testDb.prepare('SELECT * FROM vacay_plans WHERE id = ?').get(id);
|
||||
expect(await repo.findById(id)).toEqual(legacy);
|
||||
});
|
||||
|
||||
it('VACAYPLANREPO-004: null for a missing id', async () => {
|
||||
expect(await repo.findById(999999)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
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);
|
||||
testDb.prepare('INSERT INTO vacay_user_settings (user_id, year_type, year_start_month, year_start_day, hire_date) VALUES (?, ?, ?, ?, ?)')
|
||||
.run(user.id, 'fiscal', 4, 1, '2020-06-15');
|
||||
|
||||
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);
|
||||
testDb.prepare('INSERT INTO vacay_user_settings (user_id) VALUES (?)').run(user.id);
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
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(); });
|
||||
|
||||
function insertPlan(ownerId: number): number {
|
||||
return Number(testDb.prepare('INSERT INTO vacay_plans (owner_id) VALUES (?)').run(ownerId).lastInsertRowid);
|
||||
}
|
||||
|
||||
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 = insertPlan(user.id);
|
||||
testDb.prepare('INSERT INTO vacay_user_years (user_id, plan_id, year, vacation_days, carried_over) VALUES (?, ?, ?, ?, ?)')
|
||||
.run(user.id, planId, 2026, 25, 3);
|
||||
|
||||
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 = insertPlan(user.id);
|
||||
testDb.prepare('INSERT INTO vacay_user_years (user_id, plan_id, year, vacation_days, carried_over) VALUES (?, ?, ?, ?, ?)')
|
||||
.run(user.id, planId, 2027, null, null);
|
||||
|
||||
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 = insertPlan(user.id);
|
||||
expect(await repo.findForYear(user.id, planId, 2099)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* VacayYearsRepository.listForPlan — Plan 4 Task 8b-2 item 3 (3f L6 carry):
|
||||
* VC33/VC94 (`VacayService.listYears`) 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 { VacayYears } from '../../../../src/db/entities/VacayYears.entity';
|
||||
import type { VacayYearsRepository } from '../../../../src/db/repositories/VacayYears.repository';
|
||||
|
||||
const testDb = createSnapshotTestDb();
|
||||
let t: TestOrm;
|
||||
let repo: VacayYearsRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
t = await createTestOrm(testDb);
|
||||
repo = t.repo(VacayYears);
|
||||
});
|
||||
beforeEach(() => { resetTestDb(testDb); t.clear(); });
|
||||
afterAll(async () => { await t.close(); testDb.close(); });
|
||||
|
||||
function insertPlan(ownerId: number): number {
|
||||
return Number(testDb.prepare('INSERT INTO vacay_plans (owner_id) VALUES (?)').run(ownerId).lastInsertRowid);
|
||||
}
|
||||
|
||||
describe('VacayYearsRepository.listForPlan (VC33/94, VacayService.listYears)', () => {
|
||||
it('VACAYYEARREPO-001: matches SELECT year FROM vacay_years WHERE plan_id = ? ORDER BY year run raw, scoped to the plan', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const planId = insertPlan(user.id);
|
||||
const other = insertPlan(createUser(testDb).user.id);
|
||||
testDb.prepare('INSERT INTO vacay_years (plan_id, year) VALUES (?, ?)').run(planId, 2027);
|
||||
testDb.prepare('INSERT INTO vacay_years (plan_id, year) VALUES (?, ?)').run(planId, 2026);
|
||||
testDb.prepare('INSERT INTO vacay_years (plan_id, year) VALUES (?, ?)').run(other, 2099);
|
||||
|
||||
const legacy = testDb.prepare('SELECT year FROM vacay_years WHERE plan_id = ? ORDER BY year').all(planId);
|
||||
const years = await repo.listForPlan(planId);
|
||||
|
||||
expect(years).toEqual(legacy.map((r) => (r as { year: number }).year));
|
||||
expect(years).toEqual([2026, 2027]);
|
||||
});
|
||||
|
||||
it('VACAYYEARREPO-002: empty array for a plan with no years', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const planId = insertPlan(user.id);
|
||||
expect(await repo.listForPlan(planId)).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user