test(db): run the files and collab suites on the real database module

They reset through resetDatabase and seed through the ORM factories
instead of the SQLite snapshot mock, so they run in the Postgres lane as
well.
This commit is contained in:
Maurice
2026-11-17 16:25:48 +01:00
parent 8c1395c8f1
commit f5fbd60b5e
4 changed files with 175 additions and 185 deletions
-2
View File
@@ -54,9 +54,7 @@
"tests/e2e/weather.e2e.test.ts": 1,
"tests/integration/admin.test.ts": 1,
"tests/integration/auth.test.ts": 1,
"tests/integration/collab.test.ts": 1,
"tests/integration/dayReorder.test.ts": 1,
"tests/integration/files.test.ts": 1,
"tests/integration/journey-place-order.test.ts": 1,
"tests/integration/journey.test.ts": 1,
"tests/integration/leg-mode-incoming.test.ts": 1,
+98 -101
View File
@@ -6,13 +6,14 @@
* Link preview (COLLAB-025/026) would need fetch mocking — skipped here.
*/
import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { StorageReleaseQueue } from '../../src/db/entities/StorageReleaseQueue.entity';
import { CollabService } from '../../src/nest/collab/collab.service';
import { authCookie, generateToken } from '../helpers/auth';
import { createUser, createTrip, addTripMember } from '../helpers/factories';
import { findRow } from '../helpers/factories/rows';
import { resetTestDb, resetRateLimits } from '../helpers/test-db';
import { addTripMember, makeTrip } from '../helpers/factories/trips';
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 type { INestApplication } from '@nestjs/common';
@@ -22,11 +23,6 @@ import path from 'path';
import request from 'supertest';
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());
});
// Spy on the DI-native service's linkPreview so the SSRF-guarded fetch never
// runs; the rest of CollabService exercises its real SQL through the container.
// The original is kept so the guard cases below can put it back for one call —
@@ -38,6 +34,7 @@ const linkPreviewSpy = vi
let nestApp: INestApplication;
let app: Application;
let orm: MikroORM;
const FIXTURE_PDF = path.join(__dirname, '../fixtures/test.pdf');
// Ensure uploads/files dir exists for collab file uploads
@@ -46,17 +43,17 @@ const uploadsDir = path.join(__dirname, '../../uploads/files');
beforeAll(async () => {
nestApp = await buildApp();
app = nestApp.getHttpAdapter().getInstance();
orm = nestApp.get(MikroORM);
if (!fs.existsSync(uploadsDir)) fs.mkdirSync(uploadsDir, { recursive: true });
});
beforeEach(async () => {
resetTestDb(testDb);
await resetDatabase(orm);
await resetRateLimits(nestApp);
});
afterAll(async () => {
await nestApp.close();
testDb.close();
});
// ─────────────────────────────────────────────────────────────────────────────
@@ -65,8 +62,8 @@ afterAll(async () => {
describe('Collab notes', () => {
it('COLLAB-001 — POST /collab/notes creates a note', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -78,8 +75,8 @@ describe('Collab notes', () => {
});
it('COLLAB-001 — POST without title returns 400', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -89,9 +86,9 @@ describe('Collab notes', () => {
});
it('COLLAB-001 — non-member cannot create collab note', async () => {
const { user: owner } = createUser(testDb);
const { user: other } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
const { user: owner } = await makeUser(orm);
const { user: other } = await makeUser(orm);
const trip = await makeTrip(orm, owner.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -101,8 +98,8 @@ describe('Collab notes', () => {
});
it('COLLAB-002 — GET /collab/notes returns all notes', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -119,8 +116,8 @@ describe('Collab notes', () => {
});
it('COLLAB-003 — PUT /collab/notes/:id updates a note', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -138,8 +135,8 @@ describe('Collab notes', () => {
});
it('COLLAB-003 — PUT non-existent note returns 404', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.put(`/api/trips/${trip.id}/collab/notes/99999`)
@@ -149,8 +146,8 @@ describe('Collab notes', () => {
});
it('COLLAB-004 — DELETE /collab/notes/:id removes note', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -169,8 +166,8 @@ describe('Collab notes', () => {
});
it('COLLAB-005 — POST /collab/notes/:id/files uploads a file to a note', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -187,8 +184,8 @@ describe('Collab notes', () => {
});
it('COLLAB-006 — uploading blocked extension to note is rejected', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -211,8 +208,8 @@ describe('Collab notes', () => {
});
it('COLLAB-007 — DELETE /collab/notes/:noteId/files/:fileId removes file from note', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -234,8 +231,8 @@ describe('Collab notes', () => {
});
it('COLLAB-P01 — attachment filename is stored bare (category + name; no files/ prefix)', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -258,8 +255,8 @@ describe('Collab notes', () => {
});
it('COLLAB-P02 — deleting a note file hands its bytes to the release queue', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -287,8 +284,8 @@ describe('Collab notes', () => {
});
it('COLLAB-P03 — deleting a note hands its attachments’ bytes to the release queue', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -314,8 +311,8 @@ describe('Collab notes', () => {
});
it('COLLAB-028 — uploaded note file URL uses authenticated download path, not /uploads/', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -335,8 +332,8 @@ describe('Collab notes', () => {
});
it('COLLAB-029 — note attachments in listing use authenticated download URLs', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -359,8 +356,8 @@ describe('Collab notes', () => {
});
it('COLLAB-030 — note file is downloadable via files endpoint with ephemeral token', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -388,8 +385,8 @@ describe('Collab notes', () => {
});
it('COLLAB-031 — note file download without auth returns 401', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/notes`)
@@ -415,8 +412,8 @@ describe('Collab notes', () => {
describe('Polls', () => {
it('COLLAB-008 — POST /collab/polls creates a poll', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -428,8 +425,8 @@ describe('Polls', () => {
});
it('COLLAB-008 — POST without question returns 400', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -439,8 +436,8 @@ describe('Polls', () => {
});
it('COLLAB-009 — GET /collab/polls returns polls', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -453,8 +450,8 @@ describe('Polls', () => {
});
it('COLLAB-010 — POST /collab/polls/:id/vote casts a vote', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -471,8 +468,8 @@ describe('Polls', () => {
});
it('COLLAB-011 — PUT /collab/polls/:id/close closes a poll', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -488,8 +485,8 @@ describe('Polls', () => {
});
it('COLLAB-012 — cannot vote on closed poll', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -507,8 +504,8 @@ describe('Polls', () => {
});
it('COLLAB-013 — DELETE /collab/polls/:id removes poll', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const create = await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -530,8 +527,8 @@ describe('Polls', () => {
describe('Messages', () => {
it('COLLAB-014 — POST /collab/messages sends a message', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -542,8 +539,8 @@ describe('Messages', () => {
});
it('COLLAB-014 — POST without text returns 400', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -553,9 +550,9 @@ describe('Messages', () => {
});
it('COLLAB-014 — non-member cannot send message', async () => {
const { user: owner } = createUser(testDb);
const { user: other } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
const { user: owner } = await makeUser(orm);
const { user: other } = await makeUser(orm);
const trip = await makeTrip(orm, owner.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -565,8 +562,8 @@ describe('Messages', () => {
});
it('COLLAB-015 — GET /collab/messages returns messages in order', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -583,8 +580,8 @@ describe('Messages', () => {
});
it('COLLAB-016 — POST /collab/messages with reply_to links reply', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const parent = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -601,8 +598,8 @@ describe('Messages', () => {
});
it('COLLAB-017 — DELETE /collab/messages/:id removes own message', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const msg = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -618,10 +615,10 @@ describe('Messages', () => {
});
it("COLLAB-017 — cannot delete another user's message", async () => {
const { user: owner } = createUser(testDb);
const { user: member } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
addTripMember(testDb, trip.id, member.id);
const { user: owner } = await makeUser(orm);
const { user: member } = await makeUser(orm);
const trip = await makeTrip(orm, owner.id);
await addTripMember(orm, trip.id, member.id);
const msg = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -642,8 +639,8 @@ describe('Messages', () => {
describe('Message reactions', () => {
it('COLLAB-018 — POST /collab/messages/:id/react adds a reaction', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const msg = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -660,8 +657,8 @@ describe('Message reactions', () => {
});
it('COLLAB-018 — POST react without emoji returns 400', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const msg = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -683,8 +680,8 @@ describe('Message reactions', () => {
describe('Collab validation', () => {
it('COLLAB-018 — message text exceeding 5000 chars is rejected', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -694,8 +691,8 @@ describe('Collab validation', () => {
});
it('COLLAB-008 — poll with fewer than 2 options returns 400', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/collab/polls`)
@@ -711,9 +708,9 @@ describe('Collab validation', () => {
describe('Link preview', () => {
it('COLLAB-025 — GET /collab/link-preview as a non-member returns 404 (trip-access check added post-migration)', async () => {
const { user: owner } = createUser(testDb);
const { user: outsider } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
const { user: owner } = await makeUser(orm);
const { user: outsider } = await makeUser(orm);
const trip = await makeTrip(orm, owner.id);
const res = await request(app)
.get(`/api/trips/${trip.id}/collab/link-preview?url=https://example.com`)
@@ -724,8 +721,8 @@ describe('Link preview', () => {
});
it('COLLAB-025 — GET /collab/link-preview without url returns 400', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app).get(`/api/trips/${trip.id}/collab/link-preview`).set('Cookie', authCookie(user.id));
@@ -734,8 +731,8 @@ describe('Link preview', () => {
});
it('COLLAB-025 — GET /collab/link-preview returns preview for valid URL', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
linkPreviewSpy.mockResolvedValueOnce({
title: 'Example Domain',
@@ -753,8 +750,8 @@ describe('Link preview', () => {
});
it('COLLAB-026 — GET /collab/link-preview returns 400 when fetchLinkPreview returns error', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
linkPreviewSpy.mockResolvedValueOnce({
title: null,
@@ -783,8 +780,8 @@ describe('Link preview', () => {
// pass the guard: it is not '::1', and it does not start with '0.'.
['the unspecified address', 'http://[::]:9/'],
])('COLLAB-032 — GET /collab/link-preview refuses %s (%s) through the real guard', async (_label, url) => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
linkPreviewSpy.mockImplementationOnce(realLinkPreview);
const res = await request(app)
@@ -798,8 +795,8 @@ describe('Link preview', () => {
});
it('COLLAB-027 — GET /collab/link-preview catches thrown errors and returns fallback', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
linkPreviewSpy.mockRejectedValueOnce(new Error('Unexpected error'));
@@ -814,8 +811,8 @@ describe('Link preview', () => {
describe('Message reactions toggle', () => {
it('COLLAB-028 — POST /collab/messages/:msgId/react adds a reaction', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const msgRes = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
@@ -837,8 +834,8 @@ describe('Message reactions toggle', () => {
});
it('COLLAB-029 — POST /collab/messages/:msgId/react on same emoji removes it (toggle)', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const msgRes = await request(app)
.post(`/api/trips/${trip.id}/collab/messages`)
+77 -80
View File
@@ -8,12 +8,15 @@
* - FILE-009 (ephemeral token download) is covered via the /api/auth/resource-token endpoint
*/
import { buildApp } from '../../src/bootstrap';
import { db as testDb } from '../../src/db/database';
import { authCookie, generateToken } from '../helpers/auth';
import { createUser, createTrip, createReservation, createPlace, addTripMember } from '../helpers/factories';
import type { FactoryOrm } from '../helpers/factories/context';
import { makePlace } from '../helpers/factories/places';
import { makeReservation } from '../helpers/factories/reservations';
import { setAppSetting } from '../helpers/factories/settings';
import { resetTestDb, resetRateLimits } from '../helpers/test-db';
import { makeTrip } from '../helpers/factories/trips';
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 type { INestApplication } from '@nestjs/common';
@@ -21,12 +24,7 @@ import type { Application } from 'express';
import fs from 'fs';
import path from 'path';
import request from 'supertest';
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());
});
import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';
let nestApp: INestApplication;
let app: Application;
@@ -47,7 +45,7 @@ beforeAll(async () => {
});
beforeEach(async () => {
resetTestDb(testDb);
await resetDatabase(orm);
await resetRateLimits(nestApp);
// Re-seed allowed_file_types after reset
await setAppSetting(orm, 'allowed_file_types', '*');
@@ -55,7 +53,6 @@ beforeEach(async () => {
afterAll(async () => {
await nestApp.close();
testDb.close();
fs.rmSync(uploadsDir, { recursive: true, force: true });
});
@@ -74,8 +71,8 @@ async function uploadFile(tripId: number, userId: number, fixturePath = FIXTURE_
describe('Upload file', () => {
it('FILE-001 — POST uploads a file and returns file metadata', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await uploadFile(trip.id, user.id, FIXTURE_PDF);
expect(res.status).toBe(201);
@@ -85,8 +82,8 @@ describe('Upload file', () => {
});
it('FILE-002 — uploading a blocked extension (.svg) is rejected', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
// Create a temp .svg file
const svgPath = path.join(uploadsDir, 'test_blocked.svg');
@@ -105,8 +102,8 @@ describe('Upload file', () => {
});
it('FILE-P01 — stored filename is a bare uuid name and the bytes land in uploads/files', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await uploadFile(trip.id, user.id, FIXTURE_PDF);
expect(res.status).toBe(201);
@@ -120,8 +117,8 @@ describe('Upload file', () => {
});
it('FILE-P02 — non-video over 50 MB is rejected with no bytes left anywhere', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const BIG = 51 * 1024 * 1024;
// Other suites share the real uploads/ tree when the whole tier runs in
@@ -148,8 +145,8 @@ describe('Upload file', () => {
});
it('FILE-P03 — non-ASCII original filenames are preserved (defParamCharset utf8)', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/files`)
@@ -160,9 +157,9 @@ describe('Upload file', () => {
});
it('FILE-021 — non-member cannot upload file', async () => {
const { user: owner } = createUser(testDb);
const { user: other } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
const { user: owner } = await makeUser(orm);
const { user: other } = await makeUser(orm);
const trip = await makeTrip(orm, owner.id);
const res = await request(app)
.post(`/api/trips/${trip.id}/files`)
@@ -178,8 +175,8 @@ describe('Upload file', () => {
describe('List files', () => {
it('FILE-006 — GET returns all non-trashed files', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
await uploadFile(trip.id, user.id, FIXTURE_PDF);
await uploadFile(trip.id, user.id, FIXTURE_IMG);
@@ -189,8 +186,8 @@ describe('List files', () => {
});
it('FILE-007 — GET ?trash=true returns only trashed files', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -210,8 +207,8 @@ describe('List files', () => {
describe('Star/unstar file', () => {
it('FILE-011 — PATCH /:id/star toggles starred status', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -235,8 +232,8 @@ describe('Star/unstar file', () => {
describe('Soft delete, restore, permanent delete', () => {
it('FILE-012 — DELETE moves file to trash', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -251,8 +248,8 @@ describe('Soft delete, restore, permanent delete', () => {
});
it('FILE-013 — POST /:id/restore restores from trash', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -266,8 +263,8 @@ describe('Soft delete, restore, permanent delete', () => {
});
it('FILE-014 — DELETE /:id/permanent permanently deletes from trash', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -281,8 +278,8 @@ describe('Soft delete, restore, permanent delete', () => {
});
it('FILE-015 — DELETE /:id/permanent on non-trashed file returns 404', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -294,8 +291,8 @@ describe('Soft delete, restore, permanent delete', () => {
});
it('FILE-016 — DELETE /trash/empty empties all trash', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const f1 = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const f2 = await uploadFile(trip.id, user.id, FIXTURE_IMG);
@@ -318,8 +315,8 @@ describe('Soft delete, restore, permanent delete', () => {
describe('Update file metadata', () => {
it('FILE-017 — PUT updates description', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -338,9 +335,9 @@ describe('Update file metadata', () => {
describe('File links', () => {
it('FILE-018/019/020 — link file to reservation, list links, unlink', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const resv = createReservation(testDb, trip.id, { title: 'My Flight', type: 'flight' });
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const resv = await makeReservation(orm, trip.id, { title: 'My Flight', type: 'flight' });
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -380,11 +377,11 @@ describe('File links', () => {
describe('Cross-trip link isolation', () => {
it('SEC-FILE-LINK-001 — linking a file to a reservation from another trip is rejected (no title leak)', async () => {
const { user: attacker } = createUser(testDb);
const { user: victim } = createUser(testDb);
const attackerTrip = createTrip(testDb, attacker.id, { title: 'Attacker Trip' });
const victimTrip = createTrip(testDb, victim.id, { title: 'Victim Trip' });
const victimReservation = createReservation(testDb, victimTrip.id, {
const { user: attacker } = await makeUser(orm);
const { user: victim } = await makeUser(orm);
const attackerTrip = await makeTrip(orm, attacker.id, { title: 'Attacker Trip' });
const victimTrip = await makeTrip(orm, victim.id, { title: 'Victim Trip' });
const victimReservation = await makeReservation(orm, victimTrip.id, {
title: 'Victim Secret Flight',
type: 'flight',
});
@@ -407,11 +404,11 @@ describe('Cross-trip link isolation', () => {
});
it('SEC-FILE-LINK-002 — uploading a file with a foreign reservation_id is rejected (no title leak)', async () => {
const { user: attacker } = createUser(testDb);
const { user: victim } = createUser(testDb);
const attackerTrip = createTrip(testDb, attacker.id);
const victimTrip = createTrip(testDb, victim.id);
const victimReservation = createReservation(testDb, victimTrip.id, {
const { user: attacker } = await makeUser(orm);
const { user: victim } = await makeUser(orm);
const attackerTrip = await makeTrip(orm, attacker.id);
const victimTrip = await makeTrip(orm, victim.id);
const victimReservation = await makeReservation(orm, victimTrip.id, {
title: 'Victim Secret Flight',
type: 'flight',
});
@@ -426,11 +423,11 @@ describe('Cross-trip link isolation', () => {
});
it('SEC-FILE-LINK-003 — updating a file with a foreign reservation_id is rejected (no title leak)', async () => {
const { user: attacker } = createUser(testDb);
const { user: victim } = createUser(testDb);
const attackerTrip = createTrip(testDb, attacker.id);
const victimTrip = createTrip(testDb, victim.id);
const victimReservation = createReservation(testDb, victimTrip.id, {
const { user: attacker } = await makeUser(orm);
const { user: victim } = await makeUser(orm);
const attackerTrip = await makeTrip(orm, attacker.id);
const victimTrip = await makeTrip(orm, victim.id);
const victimReservation = await makeReservation(orm, victimTrip.id, {
title: 'Victim Secret Flight',
type: 'flight',
});
@@ -446,11 +443,11 @@ describe('Cross-trip link isolation', () => {
});
it('SEC-FILE-LINK-004 — linking a file to a place from another trip is rejected', async () => {
const { user: attacker } = createUser(testDb);
const { user: victim } = createUser(testDb);
const attackerTrip = createTrip(testDb, attacker.id);
const victimTrip = createTrip(testDb, victim.id);
const victimPlace = createPlace(testDb, victimTrip.id, { name: 'Victim Secret Place' });
const { user: attacker } = await makeUser(orm);
const { user: victim } = await makeUser(orm);
const attackerTrip = await makeTrip(orm, attacker.id);
const victimTrip = await makeTrip(orm, victim.id);
const victimPlace = await makePlace(orm, victimTrip.id, { name: 'Victim Secret Place' });
const upload = await uploadFile(attackerTrip.id, attacker.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -467,9 +464,9 @@ describe('Cross-trip link isolation', () => {
});
it('SEC-FILE-LINK-005 — same-trip reservation links and uploads still succeed', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const resv = createReservation(testDb, trip.id, { title: 'My Own Flight', type: 'flight' });
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const resv = await makeReservation(orm, trip.id, { title: 'My Own Flight', type: 'flight' });
// Upload carrying the trip's own reservation id is accepted.
const upload = await request(app)
@@ -495,8 +492,8 @@ describe('Cross-trip link isolation', () => {
describe('File download', () => {
it('FILE-010 — GET /:id/download without auth returns 401', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -505,8 +502,8 @@ describe('File download', () => {
});
it('FILE-008 — GET /:id/download with Bearer JWT downloads file', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -520,8 +517,8 @@ describe('File download', () => {
});
it('FILE-011 — GET /:id/download with trek_session cookie downloads file', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
@@ -534,8 +531,8 @@ describe('File download', () => {
});
it('FILE-P04 — download serves the exact bytes with Content-Type, ETag, and Range support', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
const fixtureBytes = fs.readFileSync(FIXTURE_PDF);
@@ -557,8 +554,8 @@ describe('File download', () => {
});
it('FILE-P05 — Apple Wallet passes are served inline with the canonical MIME types', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
for (const [ext, mime] of [
['pkpass', 'application/vnd.apple.pkpass'],
@@ -580,8 +577,8 @@ describe('File download', () => {
});
it('FILE-P06 — a DB row whose bytes are gone answers 404 File not found', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
const upload = await uploadFile(trip.id, user.id, FIXTURE_PDF);
const fileId = upload.body.file.id;
fs.rmSync(path.join(uploadsDir, upload.body.file.filename), { force: true });
@@ -1,8 +1,6 @@
[
"tests/integration/admin.test.ts",
"tests/integration/auth.test.ts",
"tests/integration/collab.test.ts",
"tests/integration/files.test.ts",
"tests/integration/journey-place-order.test.ts",
"tests/integration/journey.test.ts",
"tests/integration/leg-mode-incoming.test.ts",