test: comprehensive Journey test suite — 89.5% new code coverage

Server (172 tests):
- journeyService unit tests (87 tests): CRUD, access control, sync, photos, contributors
- journeyShareService unit tests (20 tests): share links, token validation, public access
- journey integration tests (45 tests): all API routes, auth, permissions, edge cases
- Test helpers: journey factories, RESET_TABLES updated

Client (340+ tests):
- journeyStore tests (15 tests): all store actions and state management
- JourneyPage tests (20 tests): frontpage, create flow, suggestions, navigation
- JourneyDetailPage tests (94 tests): all sub-components, entry editor, settings,
  share links, contributors, gallery, map, trip linking
- JourneyPublicPage tests (18 tests): public view, tabs, restricted access
- JourneyBookPDF tests (6 tests): PDF generation
- BottomNav tests (9 tests): profile sheet, navigation
- PhotoLightbox tests (8 tests): keyboard nav, counter
- JourneyMap tests (12 tests): markers, polylines, zoom
- Component tests: moodConfig, stripMarkdown, MarkdownToolbar, JournalBody, MobileTopHeader
- DashboardPage tests (32 tests): spotlight card, quick actions, widget settings

SonarQube: exclude unused MemoriesPanel from coverage (dead code, moved to Journey)
This commit is contained in:
Maurice
2026-04-12 01:19:53 +02:00
parent 2d9f545c57
commit de157cb87b
21 changed files with 8943 additions and 16 deletions
+90
View File
@@ -638,3 +638,93 @@ export function createTag(
const result = db.prepare('INSERT INTO tags (user_id, name, color) VALUES (?, ?, ?)').run(userId, name, color);
return db.prepare('SELECT * FROM tags WHERE id = ?').get(result.lastInsertRowid) as { id: number; user_id: number; name: string; color: string };
}
// ---------------------------------------------------------------------------
// Journeys
// ---------------------------------------------------------------------------
let _journeySeq = 0;
export interface TestJourney {
id: number;
user_id: number;
title: string;
subtitle: string | null;
status: string;
cover_image: string | null;
created_at: number;
updated_at: number;
}
export function createJourney(
db: Database.Database,
userId: number,
overrides: Partial<{ title: string; subtitle: string; status: string }> = {}
): TestJourney {
_journeySeq++;
const title = overrides.title ?? `Test Journey ${_journeySeq}`;
const now = Date.now();
const result = db.prepare(
'INSERT INTO journeys (user_id, title, subtitle, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)'
).run(userId, title, overrides.subtitle ?? null, overrides.status ?? 'active', now, now);
const journeyId = result.lastInsertRowid as number;
// Auto-add owner as contributor
db.prepare(
"INSERT INTO journey_contributors (journey_id, user_id, role, added_at) VALUES (?, ?, 'owner', ?)"
).run(journeyId, userId, now);
return db.prepare('SELECT * FROM journeys WHERE id = ?').get(journeyId) as TestJourney;
}
export interface TestJourneyEntry {
id: number;
journey_id: number;
author_id: number;
type: string;
entry_date: string;
title: string | null;
story: string | null;
}
export function createJourneyEntry(
db: Database.Database,
journeyId: number,
authorId: number,
overrides: Partial<{ type: string; entry_date: string; title: string; story: string; location_name: string; mood: string; weather: string }> = {}
): TestJourneyEntry {
const now = Date.now();
const result = db.prepare(`
INSERT INTO journey_entries (journey_id, author_id, type, entry_date, title, story, location_name, mood, weather, visibility, sort_order, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 'private', 0, ?, ?)
`).run(
journeyId, authorId,
overrides.type ?? 'entry',
overrides.entry_date ?? '2026-01-15',
overrides.title ?? null,
overrides.story ?? null,
overrides.location_name ?? null,
overrides.mood ?? null,
overrides.weather ?? null,
now, now
);
return db.prepare('SELECT * FROM journey_entries WHERE id = ?').get(result.lastInsertRowid) as TestJourneyEntry;
}
export function addJourneyContributor(
db: Database.Database,
journeyId: number,
userId: number,
role: 'editor' | 'viewer' = 'editor'
): void {
db.prepare(
'INSERT OR IGNORE INTO journey_contributors (journey_id, user_id, role, added_at) VALUES (?, ?, ?, ?)'
).run(journeyId, userId, role, Date.now());
}
export function linkTripToJourney(db: Database.Database, journeyId: number, tripId: number): void {
db.prepare(
'INSERT OR IGNORE INTO journey_trips (journey_id, trip_id, linked_at) VALUES (?, ?, ?)'
).run(journeyId, tripId, Date.now());
}