chore: apply prettier on the entire project

This commit is contained in:
jubnl
2026-05-25 21:59:42 +02:00
parent c130ed41be
commit 6bcdfbc34b
488 changed files with 82986 additions and 45830 deletions
+90 -125
View File
@@ -2,9 +2,25 @@
* Journey API integration tests.
* Covers JOURNEY-INT-001 through JOURNEY-INT-020.
*/
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
import request from 'supertest';
import { createApp } from '../../src/app';
import { runMigrations } from '../../src/db/migrations';
import { createTables } from '../../src/db/schema';
import { loginAttempts, mfaAttempts } from '../../src/routes/auth';
import { invalidatePermissionsCache } from '../../src/services/permissions';
import { authCookie } from '../helpers/auth';
import {
createUser,
createAdmin,
createTrip,
createJourney,
createJourneyEntry,
addJourneyContributor,
} from '../helpers/factories';
import { resetTestDb } from '../helpers/test-db';
import type { Application } from 'express';
import request from 'supertest';
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
// ─────────────────────────────────────────────────────────────────────────────
// Step 1: Bare in-memory DB — schema applied in beforeAll after mocks register
@@ -21,16 +37,32 @@ const { testDb, dbMock } = vi.hoisted(() => {
closeDb: () => {},
reinitialize: () => {},
getPlaceWithTags: (placeId: number) => {
const place: any = db.prepare(`
const place: any = db
.prepare(
`
SELECT p.*, c.name as category_name, c.color as category_color, c.icon as category_icon
FROM places p LEFT JOIN categories c ON p.category_id = c.id WHERE p.id = ?
`).get(placeId);
`,
)
.get(placeId);
if (!place) return null;
const tags = db.prepare(`SELECT t.* FROM tags t JOIN place_tags pt ON t.id = pt.tag_id WHERE pt.place_id = ?`).all(placeId);
return { ...place, category: place.category_id ? { id: place.category_id, name: place.category_name, color: place.category_color, icon: place.category_icon } : null, tags };
const tags = db
.prepare(`SELECT t.* FROM tags t JOIN place_tags pt ON t.id = pt.tag_id WHERE pt.place_id = ?`)
.all(placeId);
return {
...place,
category: place.category_id
? { id: place.category_id, name: place.category_name, color: place.category_color, icon: place.category_icon }
: null,
tags,
};
},
canAccessTrip: (tripId: any, userId: number) =>
db.prepare(`SELECT t.id, t.user_id FROM trips t LEFT JOIN trip_members m ON m.trip_id = t.id AND m.user_id = ? WHERE t.id = ? AND (t.user_id = ? OR m.user_id IS NOT NULL)`).get(userId, tripId, userId),
db
.prepare(
`SELECT t.id, t.user_id FROM trips t LEFT JOIN trip_members m ON m.trip_id = t.id AND m.user_id = ? WHERE t.id = ? AND (t.user_id = ? OR m.user_id IS NOT NULL)`,
)
.get(userId, tripId, userId),
isOwner: (tripId: any, userId: number) =>
!!db.prepare('SELECT id FROM trips WHERE id = ? AND user_id = ?').get(tripId, userId),
};
@@ -55,36 +87,27 @@ vi.mock('../../src/services/memories/immichService', () => ({
getImmichCredentials: vi.fn(() => null),
}));
import { createApp } from '../../src/app';
import { createTables } from '../../src/db/schema';
import { runMigrations } from '../../src/db/migrations';
import { resetTestDb } from '../helpers/test-db';
import {
createUser,
createAdmin,
createTrip,
createJourney,
createJourneyEntry,
addJourneyContributor,
} from '../helpers/factories';
import { authCookie } from '../helpers/auth';
import { loginAttempts, mfaAttempts } from '../../src/routes/auth';
import { invalidatePermissionsCache } from '../../src/services/permissions';
const app: Application = createApp();
beforeAll(() => { createTables(testDb); runMigrations(testDb); });
beforeAll(() => {
createTables(testDb);
runMigrations(testDb);
});
beforeEach(() => {
resetTestDb(testDb);
loginAttempts.clear();
mfaAttempts.clear();
invalidatePermissionsCache();
// Enable the journey addon
testDb.prepare(
"INSERT OR REPLACE INTO addons (id, name, description, type, icon, enabled, sort_order) VALUES ('journey', 'Journey', 'Travel journal', 'global', 'Compass', 1, 35)"
).run();
testDb
.prepare(
"INSERT OR REPLACE INTO addons (id, name, description, type, icon, enabled, sort_order) VALUES ('journey', 'Journey', 'Travel journal', 'global', 'Compass', 1, 35)",
)
.run();
});
afterAll(() => {
testDb.close();
});
afterAll(() => { testDb.close(); });
// ─────────────────────────────────────────────────────────────────────────────
// List journeys (JOURNEY-INT-001, 002)
@@ -94,9 +117,7 @@ describe('List journeys', () => {
it('JOURNEY-INT-001 — GET /api/journeys returns 200 with empty list initially', async () => {
const { user } = createUser(testDb);
const res = await request(app)
.get('/api/journeys')
.set('Cookie', authCookie(user.id));
const res = await request(app).get('/api/journeys').set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.journeys).toEqual([]);
@@ -127,9 +148,7 @@ describe('Create journey', () => {
expect(res.body.id).toBeDefined();
// Should appear in listing now
const list = await request(app)
.get('/api/journeys')
.set('Cookie', authCookie(user.id));
const list = await request(app).get('/api/journeys').set('Cookie', authCookie(user.id));
expect(list.body.journeys).toHaveLength(1);
expect(list.body.journeys[0].title).toBe('Japan 2026');
});
@@ -144,9 +163,7 @@ describe('Get journey detail', () => {
const { user } = createUser(testDb);
const journey = createJourney(testDb, user.id, { title: 'Iceland' });
const res = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(user.id));
const res = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.title).toBe('Iceland');
@@ -158,9 +175,7 @@ describe('Get journey detail', () => {
it('JOURNEY-INT-005 — GET /api/journeys/:id returns 404 for non-existent', async () => {
const { user } = createUser(testDb);
const res = await request(app)
.get('/api/journeys/99999')
.set('Cookie', authCookie(user.id));
const res = await request(app).get('/api/journeys/99999').set('Cookie', authCookie(user.id));
expect(res.status).toBe(404);
});
@@ -195,17 +210,13 @@ describe('Delete journey', () => {
const { user } = createUser(testDb);
const journey = createJourney(testDb, user.id);
const res = await request(app)
.delete(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(user.id));
const res = await request(app).delete(`/api/journeys/${journey.id}`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.success).toBe(true);
// Verify it's gone
const get = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(user.id));
const get = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(user.id));
expect(get.status).toBe(404);
});
});
@@ -229,9 +240,7 @@ describe('Journey trips', () => {
expect(res.body.success).toBe(true);
// Verify trip appears in journey detail
const detail = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(user.id));
const detail = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(user.id));
expect(detail.body.trips).toHaveLength(1);
expect(detail.body.trips[0].trip_id).toBe(trip.id);
});
@@ -265,16 +274,13 @@ describe('Journey entries', () => {
const { user } = createUser(testDb);
const journey = createJourney(testDb, user.id);
const res = await request(app)
.post(`/api/journeys/${journey.id}/entries`)
.set('Cookie', authCookie(user.id))
.send({
title: 'First day in Tokyo',
story: 'Arrived at Narita airport.',
entry_date: '2026-04-01',
entry_time: '14:00',
location_name: 'Narita Airport',
});
const res = await request(app).post(`/api/journeys/${journey.id}/entries`).set('Cookie', authCookie(user.id)).send({
title: 'First day in Tokyo',
story: 'Arrived at Narita airport.',
entry_date: '2026-04-01',
entry_time: '14:00',
location_name: 'Narita Airport',
});
expect(res.status).toBe(201);
expect(res.body.title).toBe('First day in Tokyo');
@@ -308,9 +314,7 @@ describe('Journey entries', () => {
entry_date: '2026-04-02',
});
const res = await request(app)
.delete(`/api/journeys/entries/${entry.id}`)
.set('Cookie', authCookie(user.id));
const res = await request(app).delete(`/api/journeys/entries/${entry.id}`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.success).toBe(true);
@@ -336,9 +340,7 @@ describe('Journey contributors', () => {
expect(res.body.success).toBe(true);
// Contributor should now be able to access the journey
const detail = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(contributor.id));
const detail = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(contributor.id));
expect(detail.status).toBe(200);
expect(detail.body.title).toBeDefined();
});
@@ -357,9 +359,7 @@ describe('Journey contributors', () => {
expect(res.body.success).toBe(true);
// Contributor should no longer access the journey
const detail = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(contributor.id));
const detail = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(contributor.id));
expect(detail.status).toBe(404);
});
});
@@ -373,9 +373,7 @@ describe('Journey share link', () => {
const { user } = createUser(testDb);
const journey = createJourney(testDb, user.id);
const res = await request(app)
.get(`/api/journeys/${journey.id}/share-link`)
.set('Cookie', authCookie(user.id));
const res = await request(app).get(`/api/journeys/${journey.id}/share-link`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.link).toBeNull();
@@ -396,9 +394,7 @@ describe('Journey share link', () => {
expect(res.body.created).toBe(true);
// GET should now return the link
const get = await request(app)
.get(`/api/journeys/${journey.id}/share-link`)
.set('Cookie', authCookie(user.id));
const get = await request(app).get(`/api/journeys/${journey.id}/share-link`).set('Cookie', authCookie(user.id));
expect(get.body.link).not.toBeNull();
expect(get.body.link.token).toBe(res.body.token);
expect(get.body.link.share_timeline).toBe(true);
@@ -417,17 +413,13 @@ describe('Journey share link', () => {
.send({ share_timeline: true, share_gallery: true, share_map: true });
// Delete
const res = await request(app)
.delete(`/api/journeys/${journey.id}/share-link`)
.set('Cookie', authCookie(user.id));
const res = await request(app).delete(`/api/journeys/${journey.id}/share-link`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.success).toBe(true);
// Verify it's gone
const get = await request(app)
.get(`/api/journeys/${journey.id}/share-link`)
.set('Cookie', authCookie(user.id));
const get = await request(app).get(`/api/journeys/${journey.id}/share-link`).set('Cookie', authCookie(user.id));
expect(get.body.link).toBeNull();
});
});
@@ -445,16 +437,12 @@ describe('Journey permissions', () => {
addJourneyContributor(testDb, journey.id, viewer.id, 'viewer');
// Viewer can read
const viewerRes = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(viewer.id));
const viewerRes = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(viewer.id));
expect(viewerRes.status).toBe(200);
expect(viewerRes.body.title).toBe('Private Journey');
// Outsider cannot
const outsiderRes = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(outsider.id));
const outsiderRes = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(outsider.id));
expect(outsiderRes.status).toBe(404);
});
@@ -465,21 +453,15 @@ describe('Journey permissions', () => {
addJourneyContributor(testDb, journey.id, editor.id, 'editor');
// Editor can read
const readRes = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(editor.id));
const readRes = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(editor.id));
expect(readRes.status).toBe(200);
// Editor cannot delete — only owner can
const delRes = await request(app)
.delete(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(editor.id));
const delRes = await request(app).delete(`/api/journeys/${journey.id}`).set('Cookie', authCookie(editor.id));
expect(delRes.status).toBe(404);
// Journey still exists
const verify = await request(app)
.get(`/api/journeys/${journey.id}`)
.set('Cookie', authCookie(owner.id));
const verify = await request(app).get(`/api/journeys/${journey.id}`).set('Cookie', authCookie(owner.id));
expect(verify.status).toBe(200);
});
});
@@ -499,9 +481,7 @@ describe('Journey suggestions', () => {
end_date: '2026-03-05',
});
const res = await request(app)
.get('/api/journeys/suggestions')
.set('Cookie', authCookie(user.id));
const res = await request(app).get('/api/journeys/suggestions').set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.trips).toBeDefined();
@@ -518,9 +498,7 @@ describe('Available trips', () => {
const { user } = createUser(testDb);
createTrip(testDb, user.id, { title: 'My Trip', start_date: '2026-05-01', end_date: '2026-05-03' });
const res = await request(app)
.get('/api/journeys/available-trips')
.set('Cookie', authCookie(user.id));
const res = await request(app).get('/api/journeys/available-trips').set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.trips).toBeDefined();
@@ -550,10 +528,7 @@ describe('Create journey validation', () => {
it('JOURNEY-INT-023 — POST /api/journeys returns 400 for blank title', async () => {
const { user } = createUser(testDb);
const res = await request(app)
.post('/api/journeys')
.set('Cookie', authCookie(user.id))
.send({ title: ' ' });
const res = await request(app).post('/api/journeys').set('Cookie', authCookie(user.id)).send({ title: ' ' });
expect(res.status).toBe(400);
expect(res.body.error).toBe('Title is required');
@@ -717,9 +692,7 @@ describe('Delete photo (route)', () => {
it('JOURNEY-INT-032 — DELETE /api/journeys/photos/:id returns 404 for non-existent', async () => {
const { user } = createUser(testDb);
const res = await request(app)
.delete('/api/journeys/photos/99999')
.set('Cookie', authCookie(user.id));
const res = await request(app).delete('/api/journeys/photos/99999').set('Cookie', authCookie(user.id));
expect(res.status).toBe(404);
});
@@ -736,9 +709,7 @@ describe('Journey entries sub-routes', () => {
createJourneyEntry(testDb, journey.id, user.id, { title: 'Day 1', entry_date: '2026-04-01' });
createJourneyEntry(testDb, journey.id, user.id, { title: 'Day 2', entry_date: '2026-04-02' });
const res = await request(app)
.get(`/api/journeys/${journey.id}/entries`)
.set('Cookie', authCookie(user.id));
const res = await request(app).get(`/api/journeys/${journey.id}/entries`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(200);
expect(res.body.entries).toHaveLength(2);
@@ -749,9 +720,7 @@ describe('Journey entries sub-routes', () => {
const { user: outsider } = createUser(testDb);
const journey = createJourney(testDb, owner.id);
const res = await request(app)
.get(`/api/journeys/${journey.id}/entries`)
.set('Cookie', authCookie(outsider.id));
const res = await request(app).get(`/api/journeys/${journey.id}/entries`).set('Cookie', authCookie(outsider.id));
expect(res.status).toBe(404);
});
@@ -789,9 +758,7 @@ describe('Update entry edge cases', () => {
it('JOURNEY-INT-037 — DELETE /api/journeys/entries/:id returns 404 for non-existent entry', async () => {
const { user } = createUser(testDb);
const res = await request(app)
.delete('/api/journeys/entries/99999')
.set('Cookie', authCookie(user.id));
const res = await request(app).delete('/api/journeys/entries/99999').set('Cookie', authCookie(user.id));
expect(res.status).toBe(404);
});
@@ -913,9 +880,7 @@ describe('Share link update', () => {
expect(update.body.created).toBe(false);
// Verify updated permissions
const get = await request(app)
.get(`/api/journeys/${journey.id}/share-link`)
.set('Cookie', authCookie(user.id));
const get = await request(app).get(`/api/journeys/${journey.id}/share-link`).set('Cookie', authCookie(user.id));
expect(get.body.link.share_timeline).toBe(true);
expect(get.body.link.share_gallery).toBe(false);
expect(get.body.link.share_map).toBe(false);
@@ -953,7 +918,8 @@ describe('Provider photos — passphrase persistence', () => {
expect(res.status).toBe(201);
const row = testDb.prepare('SELECT passphrase FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?')
const row = testDb
.prepare('SELECT passphrase FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?')
.get('synologyphotos', 'shared-asset-1', user.id) as { passphrase: string | null } | undefined;
expect(row?.passphrase).not.toBeNull();
expect(typeof row?.passphrase).toBe('string');
@@ -973,7 +939,8 @@ describe('Provider photos — passphrase persistence', () => {
expect(res.body.added).toBe(2);
for (const assetId of ['batch-asset-1', 'batch-asset-2']) {
const row = testDb.prepare('SELECT passphrase FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?')
const row = testDb
.prepare('SELECT passphrase FROM trek_photos WHERE provider = ? AND asset_id = ? AND owner_id = ?')
.get('synologyphotos', assetId, user.id) as { passphrase: string | null } | undefined;
expect(row?.passphrase).not.toBeNull();
}
@@ -989,9 +956,7 @@ describe('Photo upload validation', () => {
const journey = createJourney(testDb, user.id);
const entry = createJourneyEntry(testDb, journey.id, user.id, { entry_date: '2026-04-01' });
const res = await request(app)
.post(`/api/journeys/entries/${entry.id}/photos`)
.set('Cookie', authCookie(user.id));
const res = await request(app).post(`/api/journeys/entries/${entry.id}/photos`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(400);
expect(res.body.error).toBe('No files uploaded');