Files
familysync/apps/api/tests/helpers/db.ts
Lucas Berger 982438dc10 style(13-03): apply Prettier formatting across repo
Mechanical reformat — no logic changes. 398 files changed, 19125
insertions(+), 16457 deletions(-). Prettier 3.8.4 with .prettierrc
(singleQuote:true, semi:true, tabWidth:2, trailingComma:all,
printWidth:100). Isolated per D-13-08 for reviewability.
2026-06-11 20:35:18 -04:00

91 lines
2.6 KiB
TypeScript

/**
* Test DB fixture helpers.
*
* For unit tests (Tasks 1-2 scope): provides mock/stub helpers so tests can run
* without a real MariaDB connection. Plan 02/03 will fill in integration-style
* fixtures that hit the Docker MariaDB (DB_HOST=127.0.0.1 from the dev compose override).
*/
// Re-export vi for convenience in test files
export { vi } from 'vitest';
/**
* Creates a minimal mock for the Drizzle `db` singleton.
* Replace individual methods per test as needed.
*
* Plan 02 (auth) will extend this with a real test-schema fixture.
* Plan 03 (broker) will extend with event-fixture helpers.
*/
export function createMockDb() {
return {
select: vi.fn().mockReturnThis(),
from: vi.fn().mockReturnThis(),
where: vi.fn().mockReturnThis(),
limit: vi.fn().mockResolvedValue([]),
insert: vi.fn().mockReturnThis(),
values: vi.fn().mockReturnThis(),
onDuplicateKeyUpdate: vi.fn().mockResolvedValue([{ id: 1 }]),
$returningId: vi.fn().mockResolvedValue([{ id: 1 }]),
execute: vi.fn().mockResolvedValue([]),
};
}
/**
* Sample VEVENT string for broker tests — a timed event (Plan 03).
*/
export const SAMPLE_VEVENT_TIMED = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//FamilySync//Test//EN
BEGIN:VEVENT
UID:test-timed-event-001@familysync
DTSTART:20260615T100000Z
DTEND:20260615T110000Z
SUMMARY:Test Timed Event
END:VEVENT
END:VCALENDAR`;
/**
* Sample VEVENT string for broker tests — an all-day event (Plan 03).
*/
export const SAMPLE_VEVENT_ALLDAY = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//FamilySync//Test//EN
BEGIN:VEVENT
UID:test-allday-event-001@familysync
DTSTART;VALUE=DATE:20260615
DTEND;VALUE=DATE:20260616
SUMMARY:Test All-Day Event
END:VEVENT
END:VCALENDAR`;
/**
* Sample VEVENT string — a timed recurring event (RRULE:FREQ=WEEKLY).
* Used to test that sync sets hasRrule=true for recurring events.
*/
export const SAMPLE_VEVENT_RECURRING_TIMED = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//FamilySync//Test//EN
BEGIN:VEVENT
UID:test-recurring-timed-001@familysync
DTSTART:20240101T100000Z
RRULE:FREQ=WEEKLY;BYDAY=MO
SUMMARY:Weekly Monday Meeting
END:VEVENT
END:VCALENDAR`;
/**
* Sample VEVENT string — an all-day recurring event (RRULE:FREQ=YEARLY).
* Used to test that sync sets hasRrule=true for all-day recurring events,
* and that the events route returns occurrences even when dtstartUtc is NULL.
*/
export const SAMPLE_VEVENT_RECURRING_ALLDAY = `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//FamilySync//Test//EN
BEGIN:VEVENT
UID:test-recurring-allday-001@familysync
DTSTART;VALUE=DATE:20240615
RRULE:FREQ=YEARLY
SUMMARY:Annual Birthday
END:VEVENT
END:VCALENDAR`;