test(db): run the trips and vacay suites on the real database module

They reset through resetDatabase and seed through the ORM factories on the
booted app's ORM instead of the SQLite snapshot mock, so they run in the
Postgres lane as well.
This commit is contained in:
Maurice
2026-11-17 18:14:09 +01:00
parent 3764efde7a
commit 88c2b8b991
4 changed files with 267 additions and 285 deletions
-2
View File
@@ -60,8 +60,6 @@
"tests/integration/legacy-upgrade-v244.test.ts": 1, "tests/integration/legacy-upgrade-v244.test.ts": 1,
"tests/integration/plugins/boot-registry-order.test.ts": 1, "tests/integration/plugins/boot-registry-order.test.ts": 1,
"tests/integration/plugins/plugin-runtime.test.ts": 1, "tests/integration/plugins/plugin-runtime.test.ts": 1,
"tests/integration/trips.test.ts": 1,
"tests/integration/vacay.test.ts": 1,
"tests/setup.ts": 1, "tests/setup.ts": 1,
"tests/unit/auto-backup.test.ts": 1, "tests/unit/auto-backup.test.ts": 1,
"tests/unit/db/database-lazy-open.test.ts": 1, "tests/unit/db/database-lazy-open.test.ts": 1,
+208 -216
View File
@@ -3,7 +3,6 @@
* Covers TRIP-001 through TRIP-022. * Covers TRIP-001 through TRIP-022.
*/ */
import { buildApp } from '../../src/bootstrap'; import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { AppSettings } from '../../src/db/entities/AppSettings.entity'; import { AppSettings } from '../../src/db/entities/AppSettings.entity';
import { BudgetCategoryOrder } from '../../src/db/entities/BudgetCategoryOrder.entity'; import { BudgetCategoryOrder } from '../../src/db/entities/BudgetCategoryOrder.entity';
import { BudgetItems } from '../../src/db/entities/BudgetItems.entity'; import { BudgetItems } from '../../src/db/entities/BudgetItems.entity';
@@ -22,42 +21,36 @@ import { Trips } from '../../src/db/entities/Trips.entity';
import { Users } from '../../src/db/entities/Users.entity'; import { Users } from '../../src/db/entities/Users.entity';
import { invalidatePermissionsCache } from '../../src/nest/permissions/permissions-cache'; import { invalidatePermissionsCache } from '../../src/nest/permissions/permissions-cache';
import { authCookie } from '../helpers/auth'; import { authCookie } from '../helpers/auth';
import { import { makeBudgetItem } from '../helpers/factories/budget';
createUser,
createAdmin,
createTrip,
addTripMember,
createPlace,
createReservation,
createTag,
createDayAccommodation,
createBudgetItem,
createPackingItem,
createDayNote,
createDayAssignment,
} from '../helpers/factories';
import type { FactoryOrm } from '../helpers/factories/context'; import type { FactoryOrm } from '../helpers/factories/context';
import { makeDayAccommodation } from '../helpers/factories/itinerary';
import { makeDayAssignment } from '../helpers/factories/itinerary';
import { makeDayNote } from '../helpers/factories/itinerary';
import { makePackingItem } from '../helpers/factories/packing';
import { makePlace } from '../helpers/factories/places';
import { makeTag } from '../helpers/factories/places';
import { tagPlace } from '../helpers/factories/places'; import { tagPlace } from '../helpers/factories/places';
import { makeReservation } from '../helpers/factories/reservations';
import { countRows, findRow, findRows, insertRow, insertRows, updateRows } from '../helpers/factories/rows'; import { countRows, findRow, findRows, insertRow, insertRows, updateRows } from '../helpers/factories/rows';
import { setAppSetting } from '../helpers/factories/settings'; import { setAppSetting } from '../helpers/factories/settings';
import { addTripMember } from '../helpers/factories/trips';
import { makeTrip } from '../helpers/factories/trips';
import { readTripDays } from '../helpers/factories/trips'; import { readTripDays } from '../helpers/factories/trips';
import { makeAdmin } from '../helpers/factories/users';
import { makeUser } from '../helpers/factories/users';
import { readUser } from '../helpers/factories/users'; import { readUser } from '../helpers/factories/users';
import { resetTestDb, resetRateLimits } from '../helpers/test-db'; import { resetDatabase } from '../helpers/reset-database';
import { resetRateLimits } from '../helpers/test-db';
import { MikroORM } from '@mikro-orm/core'; import { MikroORM } from '@mikro-orm/core';
import type { INestApplication } from '@nestjs/common'; import type { INestApplication } from '@nestjs/common';
import type { Application } from 'express'; import type { Application } from 'express';
import request from 'supertest'; import request from 'supertest';
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest'; import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';
// ───────────────────────────────────────────────────────────────────────────── // ─────────────────────────────────────────────────────────────────────────────
// Step 1: Bare in-memory DB — schema applied in beforeAll after mocks register // Step 1: Bare in-memory DB — schema applied in beforeAll after mocks register
// ───────────────────────────────────────────────────────────────────────────── // ─────────────────────────────────────────────────────────────────────────────
vi.mock('../../src/db/database', async () => {
const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock');
return buildDbMock(createSnapshotTestDb());
});
let nestApp: INestApplication; let nestApp: INestApplication;
let app: Application; let app: Application;
let orm: FactoryOrm; let orm: FactoryOrm;
@@ -68,13 +61,12 @@ beforeAll(async () => {
orm = nestApp.get(MikroORM); orm = nestApp.get(MikroORM);
}); });
beforeEach(async () => { beforeEach(async () => {
resetTestDb(testDb); await resetDatabase(orm);
await resetRateLimits(nestApp); await resetRateLimits(nestApp);
await invalidatePermissionsCache(); await invalidatePermissionsCache();
}); });
afterAll(async () => { afterAll(async () => {
await nestApp.close(); await nestApp.close();
testDb.close();
}); });
// ───────────────────────────────────────────────────────────────────────────── // ─────────────────────────────────────────────────────────────────────────────
@@ -83,7 +75,7 @@ afterAll(async () => {
describe('Create trip', () => { describe('Create trip', () => {
it('TRIP-001 — POST /api/trips with start_date/end_date returns 201 and auto-generates days', async () => { it('TRIP-001 — POST /api/trips with start_date/end_date returns 201 and auto-generates days', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app) const res = await request(app)
.post('/api/trips') .post('/api/trips')
@@ -102,7 +94,7 @@ describe('Create trip', () => {
}); });
it('TRIP-002 — POST /api/trips without dates returns 201 and creates 7 dateless placeholder days', async () => { it('TRIP-002 — POST /api/trips without dates returns 201 and creates 7 dateless placeholder days', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app) const res = await request(app)
.post('/api/trips') .post('/api/trips')
@@ -121,7 +113,7 @@ describe('Create trip', () => {
}); });
it('TRIP-002b — POST /api/trips with day_count creates correct number of dateless days', async () => { it('TRIP-002b — POST /api/trips with day_count creates correct number of dateless days', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app) const res = await request(app)
.post('/api/trips') .post('/api/trips')
@@ -137,7 +129,7 @@ describe('Create trip', () => {
}); });
it('TRIP-001 — POST /api/trips requires a title, returns 400 without one', async () => { it('TRIP-001 — POST /api/trips requires a title, returns 400 without one', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app) const res = await request(app)
.post('/api/trips') .post('/api/trips')
@@ -149,7 +141,7 @@ describe('Create trip', () => {
}); });
it('TRIP-001 — POST /api/trips rejects end_date before start_date with 400', async () => { it('TRIP-001 — POST /api/trips rejects end_date before start_date with 400', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app) const res = await request(app)
.post('/api/trips') .post('/api/trips')
@@ -161,7 +153,7 @@ describe('Create trip', () => {
}); });
it('TRIP-003 — trip_create permission set to admin blocks regular user with 403', async () => { it('TRIP-003 — trip_create permission set to admin blocks regular user with 403', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
// Restrict trip creation to admins only // Restrict trip creation to admins only
await insertRow(orm, AppSettings, { key: 'perm_trip_create', value: 'admin' }); await insertRow(orm, AppSettings, { key: 'perm_trip_create', value: 'admin' });
@@ -177,7 +169,7 @@ describe('Create trip', () => {
}); });
it('TRIP-003 — trip_create permission set to admin allows admin user', async () => { it('TRIP-003 — trip_create permission set to admin allows admin user', async () => {
const { user: admin } = createAdmin(testDb); const { user: admin } = await makeAdmin(orm);
await insertRow(orm, AppSettings, { key: 'perm_trip_create', value: 'admin' }); await insertRow(orm, AppSettings, { key: 'perm_trip_create', value: 'admin' });
await invalidatePermissionsCache(); await invalidatePermissionsCache();
@@ -199,16 +191,16 @@ describe('Create trip', () => {
describe('List trips', () => { describe('List trips', () => {
it('TRIP-004 — GET /api/trips returns own trips and member trips, not other users trips', async () => { it('TRIP-004 — GET /api/trips returns own trips and member trips, not other users trips', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const { user: stranger } = createUser(testDb); const { user: stranger } = await makeUser(orm);
const ownTrip = createTrip(testDb, owner.id, { title: "Owner's Trip" }); const ownTrip = await makeTrip(orm, owner.id, { title: "Owner's Trip" });
const memberTrip = createTrip(testDb, stranger.id, { title: "Stranger's Trip (member)" }); const memberTrip = await makeTrip(orm, stranger.id, { title: "Stranger's Trip (member)" });
createTrip(testDb, stranger.id, { title: "Stranger's Private Trip" }); await makeTrip(orm, stranger.id, { title: "Stranger's Private Trip" });
// Add member to one of stranger's trips // Add member to one of stranger's trips
addTripMember(testDb, memberTrip.id, member.id); await addTripMember(orm, memberTrip.id, member.id);
const ownerRes = await request(app).get('/api/trips').set('Cookie', authCookie(owner.id)); const ownerRes = await request(app).get('/api/trips').set('Cookie', authCookie(owner.id));
@@ -226,10 +218,10 @@ describe('List trips', () => {
}); });
it('TRIP-005 — GET /api/trips excludes archived trips by default', async () => { it('TRIP-005 — GET /api/trips excludes archived trips by default', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const activeTrip = createTrip(testDb, user.id, { title: 'Active Trip' }); const activeTrip = await makeTrip(orm, user.id, { title: 'Active Trip' });
const archivedTrip = createTrip(testDb, user.id, { title: 'Archived Trip' }); const archivedTrip = await makeTrip(orm, user.id, { title: 'Archived Trip' });
// Archive the second trip directly in the DB // Archive the second trip directly in the DB
await updateRows(orm, Trips, { id: archivedTrip.id }, { is_archived: 1 }); await updateRows(orm, Trips, { id: archivedTrip.id }, { is_archived: 1 });
@@ -243,10 +235,10 @@ describe('List trips', () => {
}); });
it('TRIP-005 — GET /api/trips?archived=1 returns only archived trips', async () => { it('TRIP-005 — GET /api/trips?archived=1 returns only archived trips', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const activeTrip = createTrip(testDb, user.id, { title: 'Active Trip' }); const activeTrip = await makeTrip(orm, user.id, { title: 'Active Trip' });
const archivedTrip = createTrip(testDb, user.id, { title: 'Archived Trip' }); const archivedTrip = await makeTrip(orm, user.id, { title: 'Archived Trip' });
await updateRows(orm, Trips, { id: archivedTrip.id }, { is_archived: 1 }); await updateRows(orm, Trips, { id: archivedTrip.id }, { is_archived: 1 });
@@ -265,8 +257,8 @@ describe('List trips', () => {
describe('Get trip', () => { describe('Get trip', () => {
it('TRIP-006 — GET /api/trips/:id for own trip returns 200 with full trip object', async () => { it('TRIP-006 — GET /api/trips/:id for own trip returns 200 with full trip object', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'My Trip', description: 'A lovely trip' }); const trip = await makeTrip(orm, user.id, { title: 'My Trip', description: 'A lovely trip' });
const res = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id)); const res = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id));
@@ -278,9 +270,9 @@ describe('Get trip', () => {
}); });
it('TRIP-007 — GET /api/trips/:id for another users trip returns 404', async () => { it('TRIP-007 — GET /api/trips/:id for another users trip returns 404', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: other } = createUser(testDb); const { user: other } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: "Owner's Trip" }); const trip = await makeTrip(orm, owner.id, { title: "Owner's Trip" });
const res = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(other.id)); const res = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(other.id));
@@ -289,10 +281,10 @@ describe('Get trip', () => {
}); });
it('TRIP-017 — Member can access trip → 200', async () => { it('TRIP-017 — Member can access trip → 200', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Shared Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Shared Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(member.id)); const res = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(member.id));
@@ -302,7 +294,7 @@ describe('Get trip', () => {
}); });
it('TRIP-006 — GET /api/trips/:id for non-existent trip returns 404', async () => { it('TRIP-006 — GET /api/trips/:id for non-existent trip returns 404', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app).get('/api/trips/999999').set('Cookie', authCookie(user.id)); const res = await request(app).get('/api/trips/999999').set('Cookie', authCookie(user.id));
@@ -316,8 +308,8 @@ describe('Get trip', () => {
describe('Update trip', () => { describe('Update trip', () => {
it('TRIP-008 — PUT /api/trips/:id updates title and description for owner → 200', async () => { it('TRIP-008 — PUT /api/trips/:id updates title and description for owner → 200', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Original Title' }); const trip = await makeTrip(orm, user.id, { title: 'Original Title' });
const res = await request(app) const res = await request(app)
.put(`/api/trips/${trip.id}`) .put(`/api/trips/${trip.id}`)
@@ -330,8 +322,8 @@ describe('Update trip', () => {
}); });
it('TRIP-009 — Archive trip (PUT with is_archived:true) removes it from normal list', async () => { it('TRIP-009 — Archive trip (PUT with is_archived:true) removes it from normal list', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'To Archive' }); const trip = await makeTrip(orm, user.id, { title: 'To Archive' });
const archiveRes = await request(app) const archiveRes = await request(app)
.put(`/api/trips/${trip.id}`) .put(`/api/trips/${trip.id}`)
@@ -349,8 +341,8 @@ describe('Update trip', () => {
}); });
it('TRIP-009 — Unarchive trip reappears in normal list', async () => { it('TRIP-009 — Unarchive trip reappears in normal list', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Archived Trip' }); const trip = await makeTrip(orm, user.id, { title: 'Archived Trip' });
// Archive it first // Archive it first
await updateRows(orm, Trips, { id: trip.id }, { is_archived: 1 }); await updateRows(orm, Trips, { id: trip.id }, { is_archived: 1 });
@@ -372,10 +364,10 @@ describe('Update trip', () => {
}); });
it('TRIP-010 — Archive by trip member is denied when trip_archive is set to trip_owner', async () => { it('TRIP-010 — Archive by trip member is denied when trip_archive is set to trip_owner', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Members Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Members Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
// Restrict archiving to trip_owner only (this is actually the default, but set explicitly) // Restrict archiving to trip_owner only (this is actually the default, but set explicitly)
await setAppSetting(orm, 'perm_trip_archive', 'trip_owner'); await setAppSetting(orm, 'perm_trip_archive', 'trip_owner');
@@ -391,10 +383,10 @@ describe('Update trip', () => {
}); });
it('TRIP-008 — Member cannot edit trip title when trip_edit is set to trip_owner', async () => { it('TRIP-008 — Member cannot edit trip title when trip_edit is set to trip_owner', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Original' }); const trip = await makeTrip(orm, owner.id, { title: 'Original' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
// Default trip_edit is trip_owner — members should be blocked // Default trip_edit is trip_owner — members should be blocked
await setAppSetting(orm, 'perm_trip_edit', 'trip_owner'); await setAppSetting(orm, 'perm_trip_edit', 'trip_owner');
@@ -409,7 +401,7 @@ describe('Update trip', () => {
}); });
it('TRIP-008 — PUT /api/trips/:id returns 404 for non-existent trip', async () => { it('TRIP-008 — PUT /api/trips/:id returns 404 for non-existent trip', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app) const res = await request(app)
.put('/api/trips/999999') .put('/api/trips/999999')
@@ -420,15 +412,15 @@ describe('Update trip', () => {
}); });
it('TRIP-023 — Shifting trip date range preserves day assignments positionally', async () => { it('TRIP-023 — Shifting trip date range preserves day assignments positionally', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { start_date: '2026-08-01', end_date: '2026-08-05' }); const trip = await makeTrip(orm, user.id, { start_date: '2026-08-01', end_date: '2026-08-05' });
const days = await readTripDays(orm, trip.id); const days = await readTripDays(orm, trip.id);
expect(days).toHaveLength(5); expect(days).toHaveLength(5);
const place = createPlace(testDb, trip.id); const place = await makePlace(orm, trip.id);
const assignment = createDayAssignment(testDb, days[0].id, place.id); const assignment = await makeDayAssignment(orm, days[0].id, place.id);
const note = createDayNote(testDb, days[1].id, trip.id, { text: 'pack sunscreen' }); const note = await makeDayNote(orm, days[1].id, trip.id, { text: 'pack sunscreen' });
// Shift forward 10 days (zero overlap with original range) // Shift forward 10 days (zero overlap with original range)
const res = await request(app) const res = await request(app)
@@ -458,13 +450,13 @@ describe('Update trip', () => {
}); });
it('TRIP-024 — Shrinking trip date range deletes overflow days and their content', async () => { it('TRIP-024 — Shrinking trip date range deletes overflow days and their content', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { start_date: '2026-09-01', end_date: '2026-09-05' }); const trip = await makeTrip(orm, user.id, { start_date: '2026-09-01', end_date: '2026-09-05' });
const days = await readTripDays(orm, trip.id); const days = await readTripDays(orm, trip.id);
const place = createPlace(testDb, trip.id); const place = await makePlace(orm, trip.id);
const a4 = createDayAssignment(testDb, days[3].id, place.id); const a4 = await makeDayAssignment(orm, days[3].id, place.id);
const a5 = createDayAssignment(testDb, days[4].id, place.id); const a5 = await makeDayAssignment(orm, days[4].id, place.id);
// Shrink from 5 to 3 days // Shrink from 5 to 3 days
const res = await request(app) const res = await request(app)
@@ -486,18 +478,18 @@ describe('Update trip', () => {
it('TRIP-028: An earlier end takes the last day with its stay, while the hotel booking of that stay remains', async () => { it('TRIP-028: An earlier end takes the last day with its stay, while the hotel booking of that stay remains', async () => {
// Pins what the trip dialog warns about before such a save: the stay goes as // Pins what the trip dialog warns about before such a save: the stay goes as
// a whole, even with nights still inside the trip, and its booking does not. // a whole, even with nights still inside the trip, and its booking does not.
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { start_date: '2026-09-01', end_date: '2026-09-06' }); const trip = await makeTrip(orm, user.id, { start_date: '2026-09-01', end_date: '2026-09-06' });
const days = await readTripDays(orm, trip.id); const days = await readTripDays(orm, trip.id);
const place = createPlace(testDb, trip.id, { name: 'Harbour Hotel' }); const place = await makePlace(orm, trip.id, { name: 'Harbour Hotel' });
const stay = createDayAccommodation(testDb, trip.id, place.id, days[3].id, days[5].id); const stay = await makeDayAccommodation(orm, trip.id, place.id, days[3].id, days[5].id);
const booking = createReservation(testDb, trip.id, { const booking = await makeReservation(orm, trip.id, {
title: 'Harbour Hotel booking', title: 'Harbour Hotel booking',
type: 'hotel', type: 'hotel',
day_id: days[3].id, day: days[3].id,
}); });
await updateRows(orm, Reservations, { id: booking.id }, { accommodation_id: String(stay.id) }); await updateRows(orm, Reservations, { id: booking.id }, { accommodation_id: String(stay.id) });
const sightseeing = createDayAssignment(testDb, days[5].id, place.id); const sightseeing = await makeDayAssignment(orm, days[5].id, place.id);
const res = await request(app) const res = await request(app)
.put(`/api/trips/${trip.id}`) .put(`/api/trips/${trip.id}`)
@@ -521,8 +513,8 @@ describe('Update trip', () => {
describe('Delete trip', () => { describe('Delete trip', () => {
it('TRIP-018 — DELETE /api/trips/:id by owner returns 200 and trip is no longer accessible', async () => { it('TRIP-018 — DELETE /api/trips/:id by owner returns 200 and trip is no longer accessible', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'To Delete' }); const trip = await makeTrip(orm, user.id, { title: 'To Delete' });
const deleteRes = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id)); const deleteRes = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id));
@@ -536,9 +528,9 @@ describe('Delete trip', () => {
}); });
it('TRIP-019 — Regular user cannot delete another users trip → 404', async () => { it('TRIP-019 — Regular user cannot delete another users trip → 404', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: other } = createUser(testDb); const { user: other } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: "Owner's Trip" }); const trip = await makeTrip(orm, owner.id, { title: "Owner's Trip" });
const res = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(other.id)); const res = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(other.id));
@@ -553,10 +545,10 @@ describe('Delete trip', () => {
}); });
it('TRIP-019 — Trip member cannot delete trip → 403', async () => { it('TRIP-019 — Trip member cannot delete trip → 403', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Shared Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Shared Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(member.id)); const res = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(member.id));
@@ -565,12 +557,12 @@ describe('Delete trip', () => {
}); });
it('TRIP-022 — Trip with places and reservations can be deleted (cascade)', async () => { it('TRIP-022 — Trip with places and reservations can be deleted (cascade)', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Trip With Data' }); const trip = await makeTrip(orm, user.id, { title: 'Trip With Data' });
// Add associated data // Add associated data
createPlace(testDb, trip.id, { name: 'Eiffel Tower' }); await makePlace(orm, trip.id, { name: 'Eiffel Tower' });
createReservation(testDb, trip.id, { title: 'Hotel Booking', type: 'hotel' }); await makeReservation(orm, trip.id, { title: 'Hotel Booking', type: 'hotel' });
const deleteRes = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id)); const deleteRes = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id));
@@ -586,9 +578,9 @@ describe('Delete trip', () => {
}); });
it('TRIP-018 — Admin can delete another users trip', async () => { it('TRIP-018 — Admin can delete another users trip', async () => {
const { user: admin } = createAdmin(testDb); const { user: admin } = await makeAdmin(orm);
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: "User's Trip" }); const trip = await makeTrip(orm, owner.id, { title: "User's Trip" });
const res = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(admin.id)); const res = await request(app).delete(`/api/trips/${trip.id}`).set('Cookie', authCookie(admin.id));
@@ -597,7 +589,7 @@ describe('Delete trip', () => {
}); });
it('TRIP-018 — DELETE /api/trips/:id for non-existent trip returns 404', async () => { it('TRIP-018 — DELETE /api/trips/:id for non-existent trip returns 404', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app).delete('/api/trips/999999').set('Cookie', authCookie(user.id)); const res = await request(app).delete('/api/trips/999999').set('Cookie', authCookie(user.id));
@@ -611,10 +603,10 @@ describe('Delete trip', () => {
describe('Trip members', () => { describe('Trip members', () => {
it('TRIP-015 — GET /api/trips/:id/members returns owner and members list', async () => { it('TRIP-015 — GET /api/trips/:id/members returns owner and members list', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app).get(`/api/trips/${trip.id}/members`).set('Cookie', authCookie(owner.id)); const res = await request(app).get(`/api/trips/${trip.id}/members`).set('Cookie', authCookie(owner.id));
@@ -627,9 +619,9 @@ describe('Trip members', () => {
}); });
it('TRIP-013 — POST /api/trips/:id/members adds a member by email → 201', async () => { it('TRIP-013 — POST /api/trips/:id/members adds a member by email → 201', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/members`) .post(`/api/trips/${trip.id}/members`)
@@ -647,9 +639,9 @@ describe('Trip members', () => {
}); });
it('TRIP-013 — POST /api/trips/:id/members adds a member by username → 201', async () => { it('TRIP-013 — POST /api/trips/:id/members adds a member by username → 201', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/members`) .post(`/api/trips/${trip.id}/members`)
@@ -661,8 +653,8 @@ describe('Trip members', () => {
}); });
it('TRIP-013 — Adding a non-existent user returns 404', async () => { it('TRIP-013 — Adding a non-existent user returns 404', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/members`) .post(`/api/trips/${trip.id}/members`)
@@ -674,10 +666,10 @@ describe('Trip members', () => {
}); });
it('TRIP-013 — Adding a user who is already a member returns 400', async () => { it('TRIP-013 — Adding a user who is already a member returns 400', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/members`) .post(`/api/trips/${trip.id}/members`)
@@ -689,9 +681,9 @@ describe('Trip members', () => {
}); });
it('TRIP-013 — Adding a member by whitespace-padded username resolves correctly → 201', async () => { it('TRIP-013 — Adding a member by whitespace-padded username resolves correctly → 201', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb, { username: 'paddeduser' }); const { user: invitee } = await makeUser(orm, { username: 'paddeduser' });
const trip = createTrip(testDb, owner.id, { title: 'Padded Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Padded Trip' });
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/members`) .post(`/api/trips/${trip.id}/members`)
@@ -703,10 +695,10 @@ describe('Trip members', () => {
}); });
it('TRIP-014 — DELETE /api/trips/:id/members/:userId removes a member → 200', async () => { it('TRIP-014 — DELETE /api/trips/:id/members/:userId removes a member → 200', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app) const res = await request(app)
.delete(`/api/trips/${trip.id}/members/${member.id}`) .delete(`/api/trips/${trip.id}/members/${member.id}`)
@@ -721,10 +713,10 @@ describe('Trip members', () => {
}); });
it('TRIP-014 — Member can remove themselves from a trip → 200', async () => { it('TRIP-014 — Member can remove themselves from a trip → 200', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app) const res = await request(app)
.delete(`/api/trips/${trip.id}/members/${member.id}`) .delete(`/api/trips/${trip.id}/members/${member.id}`)
@@ -735,10 +727,10 @@ describe('Trip members', () => {
}); });
it('TRIP-TRANSFER-001 — owner hands the trip to a member; roles swap (#973)', async () => { it('TRIP-TRANSFER-001 — owner hands the trip to a member; roles swap (#973)', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/transfer`) .post(`/api/trips/${trip.id}/transfer`)
@@ -756,10 +748,10 @@ describe('Trip members', () => {
}); });
it('TRIP-TRANSFER-002 — a non-owner cannot transfer ownership → 403', async () => { it('TRIP-TRANSFER-002 — a non-owner cannot transfer ownership → 403', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/transfer`) .post(`/api/trips/${trip.id}/transfer`)
@@ -770,9 +762,9 @@ describe('Trip members', () => {
}); });
it('TRIP-TRANSFER-003 — cannot transfer to a non-member → 400', async () => { it('TRIP-TRANSFER-003 — cannot transfer to a non-member → 400', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: stranger } = createUser(testDb); const { user: stranger } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/transfer`) .post(`/api/trips/${trip.id}/transfer`)
@@ -783,8 +775,8 @@ describe('Trip members', () => {
}); });
it('TRIP-GUEST-001 — owner creates a guest; it appears as a member and is shielded from auth (#1362)', async () => { it('TRIP-GUEST-001 — owner creates a guest; it appears as a member and is shielded from auth (#1362)', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Camping' }); const trip = await makeTrip(orm, owner.id, { title: 'Camping' });
const created = await request(app) const created = await request(app)
.post(`/api/trips/${trip.id}/guests`) .post(`/api/trips/${trip.id}/guests`)
@@ -812,9 +804,9 @@ describe('Trip members', () => {
}); });
it('TRIP-GUEST-004 — the same guest name is allowed on two trips (no "Name 2", #1446)', async () => { it('TRIP-GUEST-004 — the same guest name is allowed on two trips (no "Name 2", #1446)', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const tripA = createTrip(testDb, owner.id, { title: 'Trip A' }); const tripA = await makeTrip(orm, owner.id, { title: 'Trip A' });
const tripB = createTrip(testDb, owner.id, { title: 'Trip B' }); const tripB = await makeTrip(orm, owner.id, { title: 'Trip B' });
const addJake = (tripId: number) => const addJake = (tripId: number) =>
request(app).post(`/api/trips/${tripId}/guests`).set('Cookie', authCookie(owner.id)).send({ name: 'Jake' }); request(app).post(`/api/trips/${tripId}/guests`).set('Cookie', authCookie(owner.id)).send({ name: 'Jake' });
@@ -834,10 +826,10 @@ describe('Trip members', () => {
}); });
it('TRIP-GUEST-002 — guest CRUD is owner-only', async () => { it('TRIP-GUEST-002 — guest CRUD is owner-only', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Camping' }); const trip = await makeTrip(orm, owner.id, { title: 'Camping' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
// A non-owner member cannot create a guest. // A non-owner member cannot create a guest.
const denied = await request(app) const denied = await request(app)
@@ -869,9 +861,9 @@ describe('Trip members', () => {
}); });
it('TRIP-GUEST-003 — a guest cannot be invited as a member to any trip (#1362)', async () => { it('TRIP-GUEST-003 — a guest cannot be invited as a member to any trip (#1362)', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Camping' }); const trip = await makeTrip(orm, owner.id, { title: 'Camping' });
const otherTrip = createTrip(testDb, owner.id, { title: 'Other' }); const otherTrip = await makeTrip(orm, owner.id, { title: 'Other' });
const created = await request(app) const created = await request(app)
.post(`/api/trips/${trip.id}/guests`) .post(`/api/trips/${trip.id}/guests`)
.set('Cookie', authCookie(owner.id)) .set('Cookie', authCookie(owner.id))
@@ -886,11 +878,11 @@ describe('Trip members', () => {
}); });
it('TRIP-013 — Non-owner member cannot add other members when member_manage is trip_owner', async () => { it('TRIP-013 — Non-owner member cannot add other members when member_manage is trip_owner', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Team Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Team Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
// Restrict member management to trip_owner (default) // Restrict member management to trip_owner (default)
await setAppSetting(orm, 'perm_member_manage', 'trip_owner'); await setAppSetting(orm, 'perm_member_manage', 'trip_owner');
@@ -906,9 +898,9 @@ describe('Trip members', () => {
}); });
it('TRIP-015 — Non-member cannot list trip members → 404', async () => { it('TRIP-015 — Non-member cannot list trip members → 404', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: stranger } = createUser(testDb); const { user: stranger } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Private Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Private Trip' });
const res = await request(app).get(`/api/trips/${trip.id}/members`).set('Cookie', authCookie(stranger.id)); const res = await request(app).get(`/api/trips/${trip.id}/members`).set('Cookie', authCookie(stranger.id));
@@ -922,8 +914,8 @@ describe('Trip members', () => {
describe('Copy trip', () => { describe('Copy trip', () => {
it('TRIP-023 — POST /api/trips/:id/copy creates a duplicate trip with 201', async () => { it('TRIP-023 — POST /api/trips/:id/copy creates a duplicate trip with 201', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Original Trip', description: 'Desc' }); const trip = await makeTrip(orm, user.id, { title: 'Original Trip', description: 'Desc' });
const res = await request(app).post(`/api/trips/${trip.id}/copy`).set('Cookie', authCookie(user.id)).send({}); const res = await request(app).post(`/api/trips/${trip.id}/copy`).set('Cookie', authCookie(user.id)).send({});
@@ -934,8 +926,8 @@ describe('Copy trip', () => {
}); });
it('TRIP-023 — copy accepts a custom title for the new trip', async () => { it('TRIP-023 — copy accepts a custom title for the new trip', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Source' }); const trip = await makeTrip(orm, user.id, { title: 'Source' });
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/copy`) .post(`/api/trips/${trip.id}/copy`)
@@ -947,10 +939,10 @@ describe('Copy trip', () => {
}); });
it('TRIP-023 — copied trip belongs to the requesting user', async () => { it('TRIP-023 — copied trip belongs to the requesting user', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Shared Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Shared Trip' });
addTripMember(testDb, trip.id, member.id); await addTripMember(orm, trip.id, member.id);
const res = await request(app).post(`/api/trips/${trip.id}/copy`).set('Cookie', authCookie(member.id)).send({}); const res = await request(app).post(`/api/trips/${trip.id}/copy`).set('Cookie', authCookie(member.id)).send({});
@@ -960,9 +952,9 @@ describe('Copy trip', () => {
}); });
it('TRIP-024 — non-member cannot copy a trip → 404', async () => { it('TRIP-024 — non-member cannot copy a trip → 404', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: stranger } = createUser(testDb); const { user: stranger } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Private Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Private Trip' });
const res = await request(app).post(`/api/trips/${trip.id}/copy`).set('Cookie', authCookie(stranger.id)).send({}); const res = await request(app).post(`/api/trips/${trip.id}/copy`).set('Cookie', authCookie(stranger.id)).send({});
@@ -970,7 +962,7 @@ describe('Copy trip', () => {
}); });
it('TRIP-024 — copy of non-existent trip returns 404', async () => { it('TRIP-024 — copy of non-existent trip returns 404', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app).post('/api/trips/999999/copy').set('Cookie', authCookie(user.id)).send({}); const res = await request(app).post('/api/trips/999999/copy').set('Cookie', authCookie(user.id)).send({});
@@ -984,8 +976,8 @@ describe('Copy trip', () => {
describe('ICS export', () => { describe('ICS export', () => {
it('TRIP-025 — GET /api/trips/:id/export.ics returns text/calendar content', async () => { it('TRIP-025 — GET /api/trips/:id/export.ics returns text/calendar content', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Calendar Trip' }); const trip = await makeTrip(orm, user.id, { title: 'Calendar Trip' });
const res = await request(app).get(`/api/trips/${trip.id}/export.ics`).set('Cookie', authCookie(user.id)); const res = await request(app).get(`/api/trips/${trip.id}/export.ics`).set('Cookie', authCookie(user.id));
@@ -996,9 +988,9 @@ describe('ICS export', () => {
}); });
it('TRIP-025 — non-member cannot export ICS → 404', async () => { it('TRIP-025 — non-member cannot export ICS → 404', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: stranger } = createUser(testDb); const { user: stranger } = await makeUser(orm);
const trip = createTrip(testDb, owner.id, { title: 'Private Trip' }); const trip = await makeTrip(orm, owner.id, { title: 'Private Trip' });
const res = await request(app).get(`/api/trips/${trip.id}/export.ics`).set('Cookie', authCookie(stranger.id)); const res = await request(app).get(`/api/trips/${trip.id}/export.ics`).set('Cookie', authCookie(stranger.id));
@@ -1006,8 +998,8 @@ describe('ICS export', () => {
}); });
it('TRIP-025 — unauthenticated export returns 401', async () => { it('TRIP-025 — unauthenticated export returns 401', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Trip' }); const trip = await makeTrip(orm, user.id, { title: 'Trip' });
const res = await request(app).get(`/api/trips/${trip.id}/export.ics`); const res = await request(app).get(`/api/trips/${trip.id}/export.ics`);
expect(res.status).toBe(401); expect(res.status).toBe(401);
@@ -1018,8 +1010,8 @@ describe('ICS export', () => {
// reads `t.*`, so without the blanking it ships in every trip response and // reads `t.*`, so without the blanking it ships in every trip response and
// gating /feed/token on share_manage would achieve nothing: any member // gating /feed/token on share_manage would achieve nothing: any member
// could read the value straight out of GET /api/trips/:id. // could read the value straight out of GET /api/trips/:id.
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Trip' }); const trip = await makeTrip(orm, user.id, { title: 'Trip' });
await updateRows(orm, Trips, { id: trip.id }, { feed_token: 'secret-feed-token' }); await updateRows(orm, Trips, { id: trip.id }, { feed_token: 'secret-feed-token' });
const one = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id)); const one = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id));
@@ -1038,8 +1030,8 @@ describe('ICS export', () => {
describe('Copy trip with data', () => { describe('Copy trip with data', () => {
it('TRIP-026 — copy preserves days, places, tags, assignments, accommodations, reservations, budget, packing, notes', async () => { it('TRIP-026 — copy preserves days, places, tags, assignments, accommodations, reservations, budget, packing, notes', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { const trip = await makeTrip(orm, user.id, {
title: 'Data-Rich Trip', title: 'Data-Rich Trip',
start_date: '2025-09-01', start_date: '2025-09-01',
end_date: '2025-09-03', end_date: '2025-09-03',
@@ -1049,8 +1041,8 @@ describe('Copy trip with data', () => {
expect(days.length).toBe(3); expect(days.length).toBe(3);
// Place with a tag // Place with a tag
const place = createPlace(testDb, trip.id, { name: 'Tower Bridge' }); const place = await makePlace(orm, trip.id, { name: 'Tower Bridge' });
const tag = createTag(testDb, user.id, { name: 'Landmark' }); const tag = await makeTag(orm, user.id, { name: 'Landmark' });
await tagPlace(orm, place.id, [tag.id]); await tagPlace(orm, place.id, [tag.id]);
// Day assignment // Day assignment
@@ -1064,19 +1056,19 @@ describe('Copy trip with data', () => {
}); });
// Accommodation spanning days 0→1 // Accommodation spanning days 0→1
createDayAccommodation(testDb, trip.id, place.id, days[0].id, days[1].id); await makeDayAccommodation(orm, trip.id, place.id, days[0].id, days[1].id);
// Reservation on day 0 // Reservation on day 0
createReservation(testDb, trip.id, { title: 'Flight Out', type: 'flight', day_id: days[0].id }); await makeReservation(orm, trip.id, { title: 'Flight Out', type: 'flight', day: days[0].id });
// Budget item // Budget item
createBudgetItem(testDb, trip.id, { name: 'Flights', total_price: 400 }); await makeBudgetItem(orm, trip.id, { name: 'Flights', total_price: 400 });
// Packing item // Packing item
createPackingItem(testDb, trip.id, { name: 'Toothbrush' }); await makePackingItem(orm, trip.id, { name: 'Toothbrush' });
// Day note // Day note
createDayNote(testDb, days[0].id, trip.id, { text: 'Pack early!' }); await makeDayNote(orm, days[0].id, trip.id, { text: 'Pack early!' });
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/copy`) .post(`/api/trips/${trip.id}/copy`)
@@ -1131,8 +1123,8 @@ describe('Copy trip with data', () => {
}); });
it('TRIP-027 — copy preserves todos (unchecked, unassigned) and budget category order', async () => { it('TRIP-027 — copy preserves todos (unchecked, unassigned) and budget category order', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { title: 'Todo Trip' }); const trip = await makeTrip(orm, user.id, { title: 'Todo Trip' });
// Two todos: one checked and assigned — both should arrive unchecked and unassigned // Two todos: one checked and assigned — both should arrive unchecked and unassigned
await insertRow(orm, TodoItems, { await insertRow(orm, TodoItems, {
@@ -1197,8 +1189,8 @@ describe('Copy trip with data', () => {
describe('Trip bundle', () => { describe('Trip bundle', () => {
it('BUNDLE-001 — returns all sub-collections for owned trip', async () => { it('BUNDLE-001 — returns all sub-collections for owned trip', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id, { start_date: '2026-07-01', end_date: '2026-07-03' }); const trip = await makeTrip(orm, user.id, { start_date: '2026-07-01', end_date: '2026-07-03' });
const res = await request(app).get(`/api/trips/${trip.id}/bundle`).set('Cookie', authCookie(user.id)); const res = await request(app).get(`/api/trips/${trip.id}/bundle`).set('Cookie', authCookie(user.id));
@@ -1216,7 +1208,7 @@ describe('Trip bundle', () => {
}); });
it('BUNDLE-002 — returns 404 for trip that does not exist', async () => { it('BUNDLE-002 — returns 404 for trip that does not exist', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app).get('/api/trips/999999/bundle').set('Cookie', authCookie(user.id)); const res = await request(app).get('/api/trips/999999/bundle').set('Cookie', authCookie(user.id));
@@ -1224,9 +1216,9 @@ describe('Trip bundle', () => {
}); });
it('BUNDLE-003 — returns 404 when user has no access to trip', async () => { it('BUNDLE-003 — returns 404 when user has no access to trip', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: other } = createUser(testDb); const { user: other } = await makeUser(orm);
const trip = createTrip(testDb, owner.id); const trip = await makeTrip(orm, owner.id);
const res = await request(app).get(`/api/trips/${trip.id}/bundle`).set('Cookie', authCookie(other.id)); const res = await request(app).get(`/api/trips/${trip.id}/bundle`).set('Cookie', authCookie(other.id));
@@ -1234,9 +1226,9 @@ describe('Trip bundle', () => {
}); });
it('BUNDLE-004 — members can fetch bundle', async () => { it('BUNDLE-004 — members can fetch bundle', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id); const trip = await makeTrip(orm, owner.id);
await insertRow(orm, TripMembers, { trip: trip.id, user: member.id }); await insertRow(orm, TripMembers, { trip: trip.id, user: member.id });
const res = await request(app).get(`/api/trips/${trip.id}/bundle`).set('Cookie', authCookie(member.id)); const res = await request(app).get(`/api/trips/${trip.id}/bundle`).set('Cookie', authCookie(member.id));
@@ -1246,8 +1238,8 @@ describe('Trip bundle', () => {
}); });
it('BUNDLE-005 — returns 401 when unauthenticated', async () => { it('BUNDLE-005 — returns 401 when unauthenticated', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id); const trip = await makeTrip(orm, user.id);
const res = await request(app).get(`/api/trips/${trip.id}/bundle`); const res = await request(app).get(`/api/trips/${trip.id}/bundle`);
@@ -1255,9 +1247,9 @@ describe('Trip bundle', () => {
}); });
it("BUNDLE-006 — packingItems are scoped to the viewer: another member's private item stays out (#858)", async () => { it("BUNDLE-006 — packingItems are scoped to the viewer: another member's private item stays out (#858)", async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: member } = createUser(testDb); const { user: member } = await makeUser(orm);
const trip = createTrip(testDb, owner.id); const trip = await makeTrip(orm, owner.id);
await insertRow(orm, TripMembers, { trip: trip.id, user: member.id }); await insertRow(orm, TripMembers, { trip: trip.id, user: member.id });
await insertRow(orm, PackingItems, { trip: trip.id, name: 'Tent', checked: 0, sort_order: 0 }); await insertRow(orm, PackingItems, { trip: trip.id, name: 'Tent', checked: 0, sort_order: 0 });
await insertRow(orm, PackingItems, { await insertRow(orm, PackingItems, {
@@ -1292,8 +1284,8 @@ describe('Trip cover upload parity', () => {
}); });
it('TRIP-P01 — cover upload returns /uploads/covers/<uuid> and writes the file', async () => { it('TRIP-P01 — cover upload returns /uploads/covers/<uuid> and writes the file', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id); const trip = await makeTrip(orm, user.id);
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/cover`) .post(`/api/trips/${trip.id}/cover`)
@@ -1306,8 +1298,8 @@ describe('Trip cover upload parity', () => {
}); });
it('TRIP-P02 — re-upload hands the previous cover to the release queue, which removes it once no undo can need it', async () => { it('TRIP-P02 — re-upload hands the previous cover to the release queue, which removes it once no undo can need it', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id); const trip = await makeTrip(orm, user.id);
const first = await request(app) const first = await request(app)
.post(`/api/trips/${trip.id}/cover`) .post(`/api/trips/${trip.id}/cover`)
@@ -1327,8 +1319,8 @@ describe('Trip cover upload parity', () => {
}); });
it('TRIP-P03 — no file → 400 "No image uploaded"', async () => { it('TRIP-P03 — no file → 400 "No image uploaded"', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id); const trip = await makeTrip(orm, user.id);
const res = await request(app).post(`/api/trips/${trip.id}/cover`).set('Cookie', authCookie(user.id)); const res = await request(app).post(`/api/trips/${trip.id}/cover`).set('Cookie', authCookie(user.id));
expect(res.status).toBe(400); expect(res.status).toBe(400);
@@ -1336,8 +1328,8 @@ describe('Trip cover upload parity', () => {
}); });
it('TRIP-P04 — non-image upload is 500 (plain-Error filter quirk — pinned, do not "fix")', async () => { it('TRIP-P04 — non-image upload is 500 (plain-Error filter quirk — pinned, do not "fix")', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const trip = createTrip(testDb, user.id); const trip = await makeTrip(orm, user.id);
const res = await request(app) const res = await request(app)
.post(`/api/trips/${trip.id}/cover`) .post(`/api/trips/${trip.id}/cover`)
@@ -1347,7 +1339,7 @@ describe('Trip cover upload parity', () => {
}); });
it('TRIP-P05 — unknown trip → 404 "Trip not found"', async () => { it('TRIP-P05 — unknown trip → 404 "Trip not found"', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app) const res = await request(app)
.post('/api/trips/999999/cover') .post('/api/trips/999999/cover')
+59 -65
View File
@@ -3,14 +3,14 @@
* Covers VACAY-001 to VACAY-025. * Covers VACAY-001 to VACAY-025.
*/ */
import { buildApp } from '../../src/bootstrap'; import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { VacayHolidayCalendars } from '../../src/db/entities/VacayHolidayCalendars.entity'; import { VacayHolidayCalendars } from '../../src/db/entities/VacayHolidayCalendars.entity';
import { VacayService } from '../../src/nest/vacay/vacay.service'; import { VacayService } from '../../src/nest/vacay/vacay.service';
import { authCookie } from '../helpers/auth'; import { authCookie } from '../helpers/auth';
import { createUser } from '../helpers/factories';
import type { FactoryOrm } from '../helpers/factories/context'; import type { FactoryOrm } from '../helpers/factories/context';
import { findRows } from '../helpers/factories/rows'; import { findRows } from '../helpers/factories/rows';
import { resetTestDb, resetRateLimits } from '../helpers/test-db'; import { makeUser } from '../helpers/factories/users';
import { resetDatabase } from '../helpers/reset-database';
import { resetRateLimits } from '../helpers/test-db';
import { MikroORM } from '@mikro-orm/core'; import { MikroORM } from '@mikro-orm/core';
import type { INestApplication } from '@nestjs/common'; import type { INestApplication } from '@nestjs/common';
@@ -18,11 +18,6 @@ import type { Application } from 'express';
import request from 'supertest'; import request from 'supertest';
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest'; import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
vi.mock('../../src/db/database', async () => {
const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock');
return buildDbMock(createSnapshotTestDb());
});
// Prevent real HTTP calls (holiday API etc.) // Prevent real HTTP calls (holiday API etc.)
vi.stubGlobal( vi.stubGlobal(
'fetch', 'fetch',
@@ -68,19 +63,18 @@ async function latestCalendarId(): Promise<number | undefined> {
} }
beforeEach(async () => { beforeEach(async () => {
resetTestDb(testDb); await resetDatabase(orm);
await resetRateLimits(nestApp); await resetRateLimits(nestApp);
}); });
afterAll(async () => { afterAll(async () => {
await nestApp.close(); await nestApp.close();
testDb.close();
vi.unstubAllGlobals(); vi.unstubAllGlobals();
}); });
describe('Vacay plan', () => { describe('Vacay plan', () => {
it('VACAY-001 — GET /api/addons/vacay/plan auto-creates plan on first access', async () => { it('VACAY-001 — GET /api/addons/vacay/plan auto-creates plan on first access', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); const res = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
expect(res.status).toBe(200); expect(res.status).toBe(200);
@@ -89,7 +83,7 @@ describe('Vacay plan', () => {
}); });
it('VACAY-001 — second GET returns same plan (no duplicate creation)', async () => { it('VACAY-001 — second GET returns same plan (no duplicate creation)', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); const res = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
@@ -98,7 +92,7 @@ describe('Vacay plan', () => {
}); });
it('VACAY-002 — PUT /api/addons/vacay/plan updates plan settings', async () => { it('VACAY-002 — PUT /api/addons/vacay/plan updates plan settings', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
// Ensure plan exists // Ensure plan exists
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
@@ -113,7 +107,7 @@ describe('Vacay plan', () => {
describe('Vacay years', () => { describe('Vacay years', () => {
it('VACAY-007 — POST /api/addons/vacay/years adds a year to the plan', async () => { it('VACAY-007 — POST /api/addons/vacay/years adds a year to the plan', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app) const res = await request(app)
@@ -125,7 +119,7 @@ describe('Vacay years', () => {
}); });
it('VACAY-025 — GET /api/addons/vacay/years lists years in plan', async () => { it('VACAY-025 — GET /api/addons/vacay/years lists years in plan', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
@@ -136,7 +130,7 @@ describe('Vacay years', () => {
}); });
it('VACAY-008 — DELETE /api/addons/vacay/years/:year removes year', async () => { it('VACAY-008 — DELETE /api/addons/vacay/years/:year removes year', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2026 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2026 });
@@ -146,7 +140,7 @@ describe('Vacay years', () => {
}); });
it('VACAY-011 — PUT /api/addons/vacay/stats/:year updates allowance', async () => { it('VACAY-011 — PUT /api/addons/vacay/stats/:year updates allowance', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
@@ -160,7 +154,7 @@ describe('Vacay years', () => {
describe('Vacay entries', () => { describe('Vacay entries', () => {
it('VACAY-003 — POST /api/addons/vacay/entries/toggle marks a day as vacation', async () => { it('VACAY-003 — POST /api/addons/vacay/entries/toggle marks a day as vacation', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
@@ -172,7 +166,7 @@ describe('Vacay entries', () => {
}); });
it('VACAY-004 — POST /api/addons/vacay/entries/toggle on a weekend is rejected when block_weekends is on', async () => { it('VACAY-004 — POST /api/addons/vacay/entries/toggle on a weekend is rejected when block_weekends is on', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
@@ -186,7 +180,7 @@ describe('Vacay entries', () => {
}); });
it('VACAY-006 — GET /api/addons/vacay/entries/:year returns vacation entries', async () => { it('VACAY-006 — GET /api/addons/vacay/entries/:year returns vacation entries', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
@@ -196,7 +190,7 @@ describe('Vacay entries', () => {
}); });
it('VACAY-009 — GET /api/addons/vacay/stats/:year returns stats for year', async () => { it('VACAY-009 — GET /api/addons/vacay/stats/:year returns stats for year', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
@@ -208,7 +202,7 @@ describe('Vacay entries', () => {
describe('Vacay color', () => { describe('Vacay color', () => {
it('VACAY-024 — PUT /api/addons/vacay/color sets user color in plan', async () => { it('VACAY-024 — PUT /api/addons/vacay/color sets user color in plan', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app) const res = await request(app)
@@ -221,7 +215,7 @@ describe('Vacay color', () => {
describe('Vacay invite flow', () => { describe('Vacay invite flow', () => {
it('VACAY-022 — cannot invite yourself', async () => { it('VACAY-022 — cannot invite yourself', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app) const res = await request(app)
@@ -232,8 +226,8 @@ describe('Vacay invite flow', () => {
}); });
it('VACAY-016 — send invite to another user', async () => { it('VACAY-016 — send invite to another user', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
const res = await request(app) const res = await request(app)
@@ -245,7 +239,7 @@ describe('Vacay invite flow', () => {
}); });
it('VACAY-023 — GET /api/addons/vacay/available-users returns users who can be invited', async () => { it('VACAY-023 — GET /api/addons/vacay/available-users returns users who can be invited', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app).get('/api/addons/vacay/available-users').set('Cookie', authCookie(user.id)); const res = await request(app).get('/api/addons/vacay/available-users').set('Cookie', authCookie(user.id));
@@ -256,7 +250,7 @@ describe('Vacay invite flow', () => {
describe('Vacay holidays', () => { describe('Vacay holidays', () => {
it('VACAY-014 — GET /api/addons/vacay/holidays/countries returns available countries', async () => { it('VACAY-014 — GET /api/addons/vacay/holidays/countries returns available countries', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
const res = await request(app).get('/api/addons/vacay/holidays/countries').set('Cookie', authCookie(user.id)); const res = await request(app).get('/api/addons/vacay/holidays/countries').set('Cookie', authCookie(user.id));
expect(res.status).toBe(200); expect(res.status).toBe(200);
@@ -264,7 +258,7 @@ describe('Vacay holidays', () => {
}); });
it('VACAY-012 — POST /api/addons/vacay/plan/holiday-calendars adds a holiday calendar', async () => { it('VACAY-012 — POST /api/addons/vacay/plan/holiday-calendars adds a holiday calendar', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app) const res = await request(app)
@@ -277,7 +271,7 @@ describe('Vacay holidays', () => {
describe('Vacay dissolve plan', () => { describe('Vacay dissolve plan', () => {
it('VACAY-020 — POST /api/addons/vacay/dissolve removes user from plan', async () => { it('VACAY-020 — POST /api/addons/vacay/dissolve removes user from plan', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app).post('/api/addons/vacay/dissolve').set('Cookie', authCookie(user.id)); const res = await request(app).post('/api/addons/vacay/dissolve').set('Cookie', authCookie(user.id));
@@ -287,7 +281,7 @@ describe('Vacay dissolve plan', () => {
describe('Vacay holiday calendar CRUD', () => { describe('Vacay holiday calendar CRUD', () => {
it('VACAY-026 — PUT /plan/holiday-calendars/:id updates an existing calendar', async () => { it('VACAY-026 — PUT /plan/holiday-calendars/:id updates an existing calendar', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
// Create a calendar first // Create a calendar first
@@ -306,7 +300,7 @@ describe('Vacay holiday calendar CRUD', () => {
}); });
it('VACAY-027 — DELETE /plan/holiday-calendars/:id removes the calendar', async () => { it('VACAY-027 — DELETE /plan/holiday-calendars/:id removes the calendar', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const createRes = await request(app) const createRes = await request(app)
@@ -324,7 +318,7 @@ describe('Vacay holiday calendar CRUD', () => {
}); });
it('VACAY-027b — DELETE /plan/holiday-calendars/:id non-existent returns 404', async () => { it('VACAY-027b — DELETE /plan/holiday-calendars/:id non-existent returns 404', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
const res = await request(app) const res = await request(app)
@@ -336,8 +330,8 @@ describe('Vacay holiday calendar CRUD', () => {
describe('Vacay invite full flow', () => { describe('Vacay invite full flow', () => {
it('VACAY-028 — POST /invite/accept joins the invitee to the owner plan', async () => { it('VACAY-028 — POST /invite/accept joins the invitee to the owner plan', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
// Owner creates plan // Owner creates plan
const planRes = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); const planRes = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
@@ -359,8 +353,8 @@ describe('Vacay invite full flow', () => {
}); });
it('VACAY-029 — POST /invite/decline removes the pending invite', async () => { it('VACAY-029 — POST /invite/decline removes the pending invite', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
const planRes = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); const planRes = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
const planId = planRes.body.plan.id; const planId = planRes.body.plan.id;
@@ -379,8 +373,8 @@ describe('Vacay invite full flow', () => {
}); });
it('VACAY-030 — POST /invite/cancel removes the pending invite from owner side', async () => { it('VACAY-030 — POST /invite/cancel removes the pending invite from owner side', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
@@ -400,7 +394,7 @@ describe('Vacay invite full flow', () => {
describe('Vacay company holidays', () => { describe('Vacay company holidays', () => {
it('VACAY-032 — POST /entries/company-holiday toggles a company holiday', async () => { it('VACAY-032 — POST /entries/company-holiday toggles a company holiday', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
@@ -412,7 +406,7 @@ describe('Vacay company holidays', () => {
}); });
it('VACAY-032b — POST /entries/company-holiday takes a half day and refuses any other size (#2439)', async () => { it('VACAY-032b — POST /entries/company-holiday takes a half day and refuses any other size (#2439)', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(user.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(user.id)).send({ year: 2025 });
const half = await request(app) const half = await request(app)
@@ -429,8 +423,8 @@ describe('Vacay company holidays', () => {
}); });
it('VACAY-033 — POST /entries/toggle with target_user_id not in plan returns 403', async () => { it('VACAY-033 — POST /entries/toggle with target_user_id not in plan returns 403', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: outsider } = createUser(testDb); const { user: outsider } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(owner.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(owner.id)).send({ year: 2025 });
@@ -444,8 +438,8 @@ describe('Vacay company holidays', () => {
describe('Vacay stats restrictions', () => { describe('Vacay stats restrictions', () => {
it('VACAY-034 — PUT /stats/:year for user not in plan returns 403', async () => { it('VACAY-034 — PUT /stats/:year for user not in plan returns 403', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: outsider } = createUser(testDb); const { user: outsider } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(owner.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(owner.id)).send({ year: 2025 });
@@ -459,8 +453,8 @@ describe('Vacay stats restrictions', () => {
describe('Vacay color restriction', () => { describe('Vacay color restriction', () => {
it('VACAY-036 — PUT /color with target_user_id not in plan returns 403', async () => { it('VACAY-036 — PUT /color with target_user_id not in plan returns 403', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: outsider } = createUser(testDb); const { user: outsider } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
const res = await request(app) const res = await request(app)
@@ -473,8 +467,8 @@ describe('Vacay color restriction', () => {
describe('Vacay toggle entry for plan member', () => { describe('Vacay toggle entry for plan member', () => {
it('VACAY-038 — POST /entries/toggle with target_user_id in plan toggles their entry', async () => { it('VACAY-038 — POST /entries/toggle with target_user_id in plan toggles their entry', async () => {
const { user: owner } = createUser(testDb); const { user: owner } = await makeUser(orm);
const { user: invitee } = createUser(testDb); const { user: invitee } = await makeUser(orm);
const planRes = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id)); const planRes = await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(owner.id));
const planId = planRes.body.plan.id; const planId = planRes.body.plan.id;
@@ -501,8 +495,8 @@ describe('Vacay toggle entry for plan member', () => {
describe('Vacay read-only calendar shares', () => { describe('Vacay read-only calendar shares', () => {
it('VACAY-039 — POST /shares shares the calendar with another user', async () => { it('VACAY-039 — POST /shares shares the calendar with another user', async () => {
const { user: a } = createUser(testDb); const { user: a } = await makeUser(orm);
const { user: b } = createUser(testDb); const { user: b } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id));
const res = await request(app) const res = await request(app)
@@ -514,8 +508,8 @@ describe('Vacay read-only calendar shares', () => {
}); });
it('VACAY-040 — GET /shares lists the share as outgoing for A and incoming for B', async () => { it('VACAY-040 — GET /shares lists the share as outgoing for A and incoming for B', async () => {
const { user: a } = createUser(testDb); const { user: a } = await makeUser(orm);
const { user: b } = createUser(testDb); const { user: b } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id));
await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id }); await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id });
@@ -534,8 +528,8 @@ describe('Vacay read-only calendar shares', () => {
}); });
it('VACAY-041 — GET /shares/calendars/:year exposes A entries and company holidays to B', async () => { it('VACAY-041 — GET /shares/calendars/:year exposes A entries and company holidays to B', async () => {
const { user: a } = createUser(testDb); const { user: a } = await makeUser(orm);
const { user: b } = createUser(testDb); const { user: b } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id));
await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(a.id)).send({ year: 2025 }); await request(app).post('/api/addons/vacay/years').set('Cookie', authCookie(a.id)).send({ year: 2025 });
await request(app) await request(app)
@@ -562,8 +556,8 @@ describe('Vacay read-only calendar shares', () => {
}); });
it('VACAY-042 — PUT /shares/:id lets B hide the shared calendar', async () => { it('VACAY-042 — PUT /shares/:id lets B hide the shared calendar', async () => {
const { user: a } = createUser(testDb); const { user: a } = await makeUser(orm);
const { user: b } = createUser(testDb); const { user: b } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id));
await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id }); await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id });
const list = await request(app).get('/api/addons/vacay/shares').set('Cookie', authCookie(b.id)); const list = await request(app).get('/api/addons/vacay/shares').set('Cookie', authCookie(b.id));
@@ -581,8 +575,8 @@ describe('Vacay read-only calendar shares', () => {
}); });
it('VACAY-043 — DELETE /shares/:id lets B remove the share', async () => { it('VACAY-043 — DELETE /shares/:id lets B remove the share', async () => {
const { user: a } = createUser(testDb); const { user: a } = await makeUser(orm);
const { user: b } = createUser(testDb); const { user: b } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id));
await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id }); await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id });
const list = await request(app).get('/api/addons/vacay/shares').set('Cookie', authCookie(b.id)); const list = await request(app).get('/api/addons/vacay/shares').set('Cookie', authCookie(b.id));
@@ -599,9 +593,9 @@ describe('Vacay read-only calendar shares', () => {
}); });
it('VACAY-044 — PUT/DELETE on a foreign share id returns 404', async () => { it('VACAY-044 — PUT/DELETE on a foreign share id returns 404', async () => {
const { user: a } = createUser(testDb); const { user: a } = await makeUser(orm);
const { user: b } = createUser(testDb); const { user: b } = await makeUser(orm);
const { user: c } = createUser(testDb); const { user: c } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id));
await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id }); await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id });
const list = await request(app).get('/api/addons/vacay/shares').set('Cookie', authCookie(b.id)); const list = await request(app).get('/api/addons/vacay/shares').set('Cookie', authCookie(b.id));
@@ -618,8 +612,8 @@ describe('Vacay read-only calendar shares', () => {
}); });
it('VACAY-045 — sharing with the same user twice returns 400', async () => { it('VACAY-045 — sharing with the same user twice returns 400', async () => {
const { user: a } = createUser(testDb); const { user: a } = await makeUser(orm);
const { user: b } = createUser(testDb); const { user: b } = await makeUser(orm);
await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id)); await request(app).get('/api/addons/vacay/plan').set('Cookie', authCookie(a.id));
await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id }); await request(app).post('/api/addons/vacay/shares').set('Cookie', authCookie(a.id)).send({ user_id: b.id });
@@ -634,7 +628,7 @@ describe('Vacay read-only calendar shares', () => {
describe('Vacay public holidays', () => { describe('Vacay public holidays', () => {
it('VACAY-035 — returns 502 when the external API fetch fails', async () => { it('VACAY-035 — returns 502 when the external API fetch fails', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
vi.mocked(global.fetch as any).mockRejectedValueOnce(new Error('Network error')); vi.mocked(global.fetch as any).mockRejectedValueOnce(new Error('Network error'));
const res = await request(app).get('/api/addons/vacay/holidays/2099/ZZ').set('Cookie', authCookie(user.id)); const res = await request(app).get('/api/addons/vacay/holidays/2099/ZZ').set('Cookie', authCookie(user.id));
@@ -642,7 +636,7 @@ describe('Vacay public holidays', () => {
}); });
it('VACAY-037 — adapts a Nager v4 record when the external API succeeds', async () => { it('VACAY-037 — adapts a Nager v4 record when the external API succeeds', async () => {
const { user } = createUser(testDb); const { user } = await makeUser(orm);
vi.mocked(global.fetch as any).mockResolvedValueOnce({ vi.mocked(global.fetch as any).mockResolvedValueOnce({
ok: true, ok: true,
json: () => json: () =>
@@ -1,6 +1,4 @@
[ [
"tests/integration/trips.test.ts",
"tests/integration/vacay.test.ts",
"tests/unit/mcp/demo-tool-gate.test.ts", "tests/unit/mcp/demo-tool-gate.test.ts",
"tests/unit/mcp/tools-addon-gating.test.ts", "tests/unit/mcp/tools-addon-gating.test.ts",
"tests/unit/mcp/tools-airtrail.test.ts", "tests/unit/mcp/tools-airtrail.test.ts",