mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
test(server): seed the collab, budget, MCP and OAuth token specs through the factories
The collab and budget e2e suites, the MCP integration suite, the budget MCP tools and the OAuth token repository suite seed and read through the ORM factories. The collab e2e suite moves off its hand-rolled CREATE TABLE set onto the migrated snapshot, the way the factories guide asks of a suite that converts: an entity reads and writes every mapped column, which a trimmed table does not have. Its users are seeded with the ids the session cookies are signed for. The recursive chain statement in the token suite stays raw, marked as the legacy oracle collectChainIds is held to.
This commit is contained in:
@@ -15,19 +15,11 @@ import { RealtimeModule } from '../../src/nest/realtime/realtime.module';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { sessionCookie } from './harness';
|
||||
|
||||
const { canAccessTrip } = vi.hoisted(() => ({ canAccessTrip: vi.fn() }));
|
||||
|
||||
vi.mock('../../src/db/database', async () => {
|
||||
const { createSnapshotTestDb } = await import('../helpers/db-mock');
|
||||
const db = createSnapshotTestDb();
|
||||
return {
|
||||
db,
|
||||
closeDb: () => {},
|
||||
reinitialize: () => {},
|
||||
canAccessTrip,
|
||||
getPlaceWithTags: () => null,
|
||||
isOwner: () => false,
|
||||
};
|
||||
// Trip access reads through TripsRepository now; the module only hands out the handle.
|
||||
return { db, closeDb: () => {}, reinitialize: () => {} };
|
||||
});
|
||||
vi.mock('../../src/websocket', () => ({ broadcast: vi.fn() }));
|
||||
|
||||
@@ -45,7 +37,32 @@ import { ExchangeRatesService } from '../../src/nest/budget/exchange-rates.servi
|
||||
import { TrekExceptionFilter } from '../../src/nest/common/trek-exception.filter';
|
||||
import { ZodValidationPipe } from '../../src/nest/common/zod-validation.pipe';
|
||||
import { TestUnitOfWorkModule } from '../helpers/test-uow';
|
||||
import { createTestMikroOrmModule } from '../helpers/test-orm';
|
||||
import { createTestMikroOrmModule, createTestOrm, type TestOrm } from '../helpers/test-orm';
|
||||
import { countRows, deleteRows, findRow, insertRow } from '../helpers/factories/rows';
|
||||
import { makeUser } from '../helpers/factories/users';
|
||||
import { addTripMember, makeTrip } from '../helpers/factories/trips';
|
||||
import { makePlace } from '../helpers/factories/places';
|
||||
import { makeReservation } from '../helpers/factories/reservations';
|
||||
import { BudgetItems } from '../../src/db/entities/BudgetItems.entity';
|
||||
import { BudgetSettlements } from '../../src/db/entities/BudgetSettlements.entity';
|
||||
import { Reservations } from '../../src/db/entities/Reservations.entity';
|
||||
import { Trips } from '../../src/db/entities/Trips.entity';
|
||||
|
||||
let orm: TestOrm;
|
||||
|
||||
/** The stored expense; fails the case when it is gone. */
|
||||
async function budgetRow(id: number) {
|
||||
const row = await findRow(orm, BudgetItems, { id });
|
||||
if (!row) throw new Error(`no budget item ${id}`);
|
||||
return row;
|
||||
}
|
||||
|
||||
/** The stored settlement; fails the case when it is gone. */
|
||||
async function settlementRow(id: number) {
|
||||
const row = await findRow(orm, BudgetSettlements, { id });
|
||||
if (!row) throw new Error(`no settlement ${id}`);
|
||||
return row;
|
||||
}
|
||||
|
||||
describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
let server: Server;
|
||||
@@ -71,18 +88,15 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
// The temp db carries the real schema (password_hash NOT NULL), so seed the
|
||||
// auth users directly instead of via the trimmed-DDL seedUser helper.
|
||||
db.prepare(
|
||||
"INSERT INTO users (id, username, email, password_hash, role, password_version) VALUES (1, 'e2e-user', 'e2e@example.test', 'x', 'user', 0)",
|
||||
).run();
|
||||
db.prepare(
|
||||
"INSERT INTO users (id, username, email, password_hash, role, password_version) VALUES (2, 'e2e-peer', 'peer@example.test', 'x', 'user', 0)",
|
||||
).run();
|
||||
tripId = Number(db.prepare("INSERT INTO trips (user_id, title, currency) VALUES (1, 'E2E Trip', 'EUR')").run().lastInsertRowid);
|
||||
// The temp db carries the real schema, so the auth users go in through the
|
||||
// factories, pinned to the ids the session cookies are signed for.
|
||||
orm = await createTestOrm(db);
|
||||
await makeUser(orm, { id: 1, username: 'e2e-user', email: 'e2e@example.test', role: 'user', password_version: 0 });
|
||||
await makeUser(orm, { id: 2, username: 'e2e-peer', email: 'peer@example.test', role: 'user', password_version: 0 });
|
||||
tripId = (await makeTrip(orm, 1, { title: 'E2E Trip', currency: 'EUR' })).id;
|
||||
// The peer settles up with the owner below, so they have to be on the trip:
|
||||
// a settlement between people who do not share one is refused.
|
||||
db.prepare('INSERT INTO trip_members (trip_id, user_id) VALUES (?, 2)').run(tripId);
|
||||
await addTripMember(orm, tripId, 2);
|
||||
app = await build();
|
||||
checkPermission = vi.spyOn(app.get(PermissionsService), 'checkPermission');
|
||||
server = app.getHttpServer();
|
||||
@@ -99,6 +113,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
await orm.close();
|
||||
});
|
||||
|
||||
it('401 without a session cookie', async () => {
|
||||
@@ -112,14 +127,14 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
// longer intercepts it. The trip row is seeded once in `beforeAll` (not
|
||||
// re-seeded per test), so it is removed and restored around this one
|
||||
// assertion instead.
|
||||
db.prepare('DELETE FROM trips WHERE id = ?').run(tripId);
|
||||
await deleteRows(orm, Trips, { id: tripId });
|
||||
try {
|
||||
const res = await request(server).get(`/api/trips/${tripId}/budget`).set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
} finally {
|
||||
db.prepare("INSERT INTO trips (id, user_id, title, currency) VALUES (?, 1, 'E2E Trip', 'EUR')").run(tripId);
|
||||
db.prepare('INSERT INTO trip_members (trip_id, user_id) VALUES (?, 2)').run(tripId);
|
||||
await insertRow(orm, Trips, { id: tripId, user: 1, title: 'E2E Trip', currency: 'EUR' });
|
||||
await addTripMember(orm, tripId, 2);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -131,8 +146,8 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
expect(created.status).toBe(201);
|
||||
expect(created.body.item).toMatchObject({ name: 'Hotel', total_price: 200, category: 'other', members: [], payers: [] });
|
||||
|
||||
const row = db.prepare('SELECT name, total_price FROM budget_items WHERE id = ?').get(created.body.item.id);
|
||||
expect(row).toEqual({ name: 'Hotel', total_price: 200 });
|
||||
const row = await budgetRow(created.body.item.id);
|
||||
expect({ name: row.name, total_price: row.total_price }).toEqual({ name: 'Hotel', total_price: 200 });
|
||||
|
||||
const list = await request(server).get(`/api/trips/${tripId}/budget`).set('Cookie', sessionCookie(1));
|
||||
expect(list.status).toBe(200);
|
||||
@@ -184,8 +199,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
expect(refund.status).toBe(201);
|
||||
expect(refund.body.item).toMatchObject({ total_price: -30 });
|
||||
expect(refund.body.item.payers).toEqual([expect.objectContaining({ user_id: 1, amount: -30 })]);
|
||||
const row = db.prepare('SELECT total_price FROM budget_items WHERE id = ?').get(refund.body.item.id) as { total_price: number };
|
||||
expect(row.total_price).toBe(-30);
|
||||
expect((await budgetRow(refund.body.item.id)).total_price).toBe(-30);
|
||||
|
||||
const settlement = await request(server)
|
||||
.get(`/api/trips/${tripId}/budget/settlement`)
|
||||
@@ -279,8 +293,8 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.settlement).toMatchObject({ id: created.body.settlement.id, from_user_id: 2, to_user_id: 1, amount: 15, settled_at: '2026-01-09' });
|
||||
|
||||
const row = db.prepare('SELECT amount, settled_at FROM budget_settlements WHERE id = ?').get(created.body.settlement.id);
|
||||
expect(row).toEqual({ amount: 15, settled_at: '2026-01-09' });
|
||||
const row = await settlementRow(created.body.settlement.id);
|
||||
expect({ amount: row.amount, settled_at: row.settled_at }).toEqual({ amount: 15, settled_at: '2026-01-09' });
|
||||
});
|
||||
|
||||
it('200 on settlement update that clears the day, leaving NULL in the column', async () => {
|
||||
@@ -297,8 +311,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.settlement.settled_at).toBeNull();
|
||||
|
||||
const row = db.prepare('SELECT settled_at FROM budget_settlements WHERE id = ?').get(created.body.settlement.id);
|
||||
expect(row).toEqual({ settled_at: null });
|
||||
expect((await settlementRow(created.body.settlement.id)).settled_at).toBeNull();
|
||||
});
|
||||
|
||||
it('keeps a note on a settlement, leaves it alone when omitted and clears it on blank (#2340)', async () => {
|
||||
@@ -359,24 +372,26 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
let luggageId: number;
|
||||
let seatId: number;
|
||||
|
||||
const metadataOf = (id: number) => {
|
||||
const row = db.prepare('SELECT metadata FROM reservations WHERE id = ?').get(id) as { metadata: string | null };
|
||||
const metadataOf = async (id: number) => {
|
||||
const row = await findRow(orm, Reservations, { id });
|
||||
if (!row) throw new Error(`no reservation ${id}`);
|
||||
return row.metadata ? JSON.parse(row.metadata) : null;
|
||||
};
|
||||
const linkOf = (id: number) =>
|
||||
db.prepare('SELECT reservation_id FROM budget_items WHERE id = ?').get(id) as { reservation_id: number | null } | undefined;
|
||||
/** The expense's booking link, or undefined once the expense is gone. */
|
||||
const linkOf = async (id: number) => {
|
||||
const row = await findRow(orm, BudgetItems, { id });
|
||||
return row ? { reservation_id: row.reservation_id ?? null } : undefined;
|
||||
};
|
||||
const put = (id: number, body: Record<string, unknown>) =>
|
||||
request(server).put(`/api/trips/${tripId}/budget/${id}`).set('Cookie', sessionCookie(1)).send(body);
|
||||
const create = (body: Record<string, unknown>) =>
|
||||
request(server).post(`/api/trips/${tripId}/budget`).set('Cookie', sessionCookie(1)).send(body);
|
||||
|
||||
beforeAll(async () => {
|
||||
bookingId = Number(db.prepare(
|
||||
"INSERT INTO reservations (trip_id, title, type, metadata) VALUES (?, 'Flight', 'flight', ?)",
|
||||
).run(tripId, JSON.stringify({ seat: '12A' })).lastInsertRowid);
|
||||
const otherTripId = Number(db.prepare("INSERT INTO trips (user_id, title, currency) VALUES (1, 'Other Trip', 'EUR')").run().lastInsertRowid);
|
||||
foreignBookingId = Number(db.prepare("INSERT INTO reservations (trip_id, title, type) VALUES (?, 'Elsewhere', 'flight')").run(otherTripId).lastInsertRowid);
|
||||
foreignPlaceId = Number(db.prepare("INSERT INTO places (trip_id, name) VALUES (?, 'Elsewhere')").run(otherTripId).lastInsertRowid);
|
||||
bookingId = (await makeReservation(orm, tripId, { title: 'Flight', type: 'flight', metadata: JSON.stringify({ seat: '12A' }) })).id;
|
||||
const otherTripId = (await makeTrip(orm, 1, { title: 'Other Trip', currency: 'EUR' })).id;
|
||||
foreignBookingId = (await makeReservation(orm, otherTripId, { title: 'Elsewhere', type: 'flight' })).id;
|
||||
foreignPlaceId = (await makePlace(orm, otherTripId, { name: 'Elsewhere', lat: null, lng: null, category: null })).id;
|
||||
});
|
||||
|
||||
it('200 on linking two expenses to one booking, which then mirrors their sum', async () => {
|
||||
@@ -390,11 +405,11 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
const first = await put(fareId, { reservation_id: bookingId });
|
||||
expect(first.status).toBe(200);
|
||||
expect(first.body.item).toMatchObject({ id: fareId, reservation_id: bookingId, total_price: 120 });
|
||||
expect(metadataOf(bookingId)).toEqual({ seat: '12A', price: '120' });
|
||||
expect(await metadataOf(bookingId)).toEqual({ seat: '12A', price: '120' });
|
||||
|
||||
const second = await put(luggageId, { reservation_id: bookingId });
|
||||
expect(second.status).toBe(200);
|
||||
expect(metadataOf(bookingId)).toEqual({ seat: '12A', price: '150.5' });
|
||||
expect(await metadataOf(bookingId)).toEqual({ seat: '12A', price: '150.5' });
|
||||
|
||||
const list = await request(server).get(`/api/trips/${tripId}/budget`).set('Cookie', sessionCookie(1));
|
||||
const linked = (list.body.items as { id: number; reservation_id: number | null }[])
|
||||
@@ -406,34 +421,34 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
const relink = await put(fareId, { reservation_id: foreignBookingId, name: 'Hijacked' });
|
||||
expect(relink.status).toBe(400);
|
||||
expect(relink.body).toEqual({ error: 'reservation_id does not belong to this trip.' });
|
||||
expect(linkOf(fareId)).toEqual({ reservation_id: bookingId });
|
||||
expect(db.prepare('SELECT name FROM budget_items WHERE id = ?').get(fareId)).toEqual({ name: 'Fare' });
|
||||
expect(metadataOf(foreignBookingId)).toBeNull();
|
||||
expect(await linkOf(fareId)).toEqual({ reservation_id: bookingId });
|
||||
expect((await budgetRow(fareId)).name).toBe('Fare');
|
||||
expect(await metadataOf(foreignBookingId)).toBeNull();
|
||||
|
||||
const place = await put(fareId, { place_id: foreignPlaceId });
|
||||
expect(place.status).toBe(400);
|
||||
expect(place.body).toEqual({ error: 'place_id does not belong to this trip.' });
|
||||
|
||||
const before = (db.prepare('SELECT COUNT(*) AS n FROM budget_items').get() as { n: number }).n;
|
||||
const before = await countRows(orm, BudgetItems);
|
||||
const created = await create({ name: 'Smuggled', total_price: 5, reservation_id: foreignBookingId });
|
||||
expect(created.status).toBe(400);
|
||||
expect(created.body).toEqual({ error: 'reservation_id does not belong to this trip.' });
|
||||
expect((db.prepare('SELECT COUNT(*) AS n FROM budget_items').get() as { n: number }).n).toBe(before);
|
||||
expect(await countRows(orm, BudgetItems)).toBe(before);
|
||||
});
|
||||
|
||||
it('400 on a reservation_id that is not a positive integer (Zod pipe envelope)', async () => {
|
||||
const res = await put(fareId, { reservation_id: 0 });
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.body.error).toContain('reservation_id');
|
||||
expect(linkOf(fareId)).toEqual({ reservation_id: bookingId });
|
||||
expect(await linkOf(fareId)).toEqual({ reservation_id: bookingId });
|
||||
});
|
||||
|
||||
it('200 on unlinking: the expense stays and the booking price is worked out again', async () => {
|
||||
const res = await put(luggageId, { reservation_id: null });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.item).toMatchObject({ id: luggageId, reservation_id: null, total_price: 30.5 });
|
||||
expect(linkOf(luggageId)).toEqual({ reservation_id: null });
|
||||
expect(metadataOf(bookingId)).toEqual({ seat: '12A', price: '120' });
|
||||
expect(await linkOf(luggageId)).toEqual({ reservation_id: null });
|
||||
expect(await metadataOf(bookingId)).toEqual({ seat: '12A', price: '120' });
|
||||
});
|
||||
|
||||
it('201 on a second expense created straight onto the booking, which raises its price to the sum', async () => {
|
||||
@@ -441,7 +456,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
expect(seat.status).toBe(201);
|
||||
expect(seat.body.item.reservation_id).toBe(bookingId);
|
||||
seatId = seat.body.item.id;
|
||||
expect(metadataOf(bookingId)).toEqual({ seat: '12A', price: '135' });
|
||||
expect(await metadataOf(bookingId)).toEqual({ seat: '12A', price: '135' });
|
||||
});
|
||||
|
||||
it('200 on new payers for a linked expense, whose derived total the booking price follows', async () => {
|
||||
@@ -451,30 +466,30 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
.send({ payers: [{ user_id: 1, amount: 12 }, { user_id: 2, amount: 6 }] });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.item).toMatchObject({ id: seatId, total_price: 18 });
|
||||
expect(metadataOf(bookingId)).toEqual({ seat: '12A', price: '138' });
|
||||
expect(await metadataOf(bookingId)).toEqual({ seat: '12A', price: '138' });
|
||||
});
|
||||
|
||||
it('200 on a currency-only change of a linked expense, which re-names the booking price', async () => {
|
||||
const trainId = Number(db.prepare("INSERT INTO reservations (trip_id, title, type) VALUES (?, 'Train', 'train')").run(tripId).lastInsertRowid);
|
||||
const trainId = (await makeReservation(orm, tripId, { title: 'Train', type: 'train' })).id;
|
||||
const ticket = await create({ name: 'Ticket', total_price: 60, reservation_id: trainId });
|
||||
expect(ticket.status).toBe(201);
|
||||
// In the trip currency, so the price carries no currency of its own.
|
||||
expect(metadataOf(trainId)).toEqual({ price: '60' });
|
||||
expect(await metadataOf(trainId)).toEqual({ price: '60' });
|
||||
|
||||
const chf = await put(ticket.body.item.id, { currency: 'CHF' });
|
||||
expect(chf.status).toBe(200);
|
||||
expect(chf.body.item).toMatchObject({ currency: 'CHF', total_price: 60 });
|
||||
expect(metadataOf(trainId)).toEqual({ price: '60', priceCurrency: 'CHF' });
|
||||
expect(await metadataOf(trainId)).toEqual({ price: '60', priceCurrency: 'CHF' });
|
||||
|
||||
const back = await put(ticket.body.item.id, { currency: null });
|
||||
expect(back.status).toBe(200);
|
||||
expect(metadataOf(trainId)).toEqual({ price: '60' });
|
||||
expect(await metadataOf(trainId)).toEqual({ price: '60' });
|
||||
|
||||
// An expense with no currency and one naming the trip's own (EUR, in any
|
||||
// case) are in the same money, so the booking shows their sum.
|
||||
const bike = await create({ name: 'Bike ticket', total_price: 9.5, currency: 'eur', reservation_id: trainId });
|
||||
expect(bike.status).toBe(201);
|
||||
expect(metadataOf(trainId)).toEqual({ price: '69.5', priceCurrency: 'EUR' });
|
||||
expect(await metadataOf(trainId)).toEqual({ price: '69.5', priceCurrency: 'EUR' });
|
||||
});
|
||||
|
||||
it('deleting the booking removes every expense linked to it, and only those', async () => {
|
||||
@@ -486,10 +501,10 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body).toEqual({ success: true });
|
||||
|
||||
expect(db.prepare('SELECT id FROM reservations WHERE id = ?').get(bookingId)).toBeUndefined();
|
||||
expect(linkOf(fareId)).toBeUndefined();
|
||||
expect(linkOf(seatId)).toBeUndefined();
|
||||
expect(linkOf(unlinkedId)).toEqual({ reservation_id: null });
|
||||
expect(await findRow(orm, Reservations, { id: bookingId })).toBeNull();
|
||||
expect(await linkOf(fareId)).toBeUndefined();
|
||||
expect(await linkOf(seatId)).toBeUndefined();
|
||||
expect(await linkOf(unlinkedId)).toEqual({ reservation_id: null });
|
||||
|
||||
const list = await request(server).get(`/api/trips/${tripId}/budget`).set('Cookie', sessionCookie(1));
|
||||
const ids = (list.body.items as { id: number }[]).map(i => i.id);
|
||||
@@ -504,16 +519,16 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
// are the ones the browser lends.
|
||||
describe('rows no rate can convert', () => {
|
||||
/** A fresh AUD trip the owner shares with user 2, so these cases never meet the ledger above. */
|
||||
function audTrip(): number {
|
||||
const id = Number(db.prepare("INSERT INTO trips (user_id, title, currency) VALUES (1, 'AUD Trip', 'AUD')").run().lastInsertRowid);
|
||||
db.prepare('INSERT INTO trip_members (trip_id, user_id) VALUES (?, 2)').run(id);
|
||||
async function audTrip(): Promise<number> {
|
||||
const id = (await makeTrip(orm, 1, { title: 'AUD Trip', currency: 'AUD' })).id;
|
||||
await addTripMember(orm, id, 2);
|
||||
return id;
|
||||
}
|
||||
const balanceOf = (body: { balances: { user_id: number; balance: number }[] }, uid: number) =>
|
||||
body.balances.find(b => b.user_id === uid)!.balance;
|
||||
|
||||
it('VND/AUD regression: unfrozen VND bill is listed as unconverted, freeze-rates heals it from the browser quote, settlement nets 489.00, second freeze heals nothing', async () => {
|
||||
const trip = audTrip();
|
||||
const trip = await audTrip();
|
||||
const bill = await request(server)
|
||||
.post(`/api/trips/${trip}/budget`)
|
||||
.set('Cookie', sessionCookie(1))
|
||||
@@ -550,11 +565,11 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
.send({ fallback_fx: { base: 'AUD', rates: { VND: 25000 } } });
|
||||
expect(again.status).toBe(200);
|
||||
expect(again.body).toEqual({ items: [], settlements: [], unresolved: [] });
|
||||
expect((db.prepare('SELECT exchange_rate FROM budget_items WHERE id = ?').get(bill.body.item.id) as { exchange_rate: number }).exchange_rate).toBe(18241.3);
|
||||
expect((await budgetRow(bill.body.item.id)).exchange_rate).toBe(18241.3);
|
||||
});
|
||||
|
||||
it('POST with fallback_fx freezes at entry', async () => {
|
||||
const trip = audTrip();
|
||||
const trip = await audTrip();
|
||||
const res = await request(server)
|
||||
.post(`/api/trips/${trip}/budget`)
|
||||
.set('Cookie', sessionCookie(1))
|
||||
@@ -565,7 +580,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
});
|
||||
|
||||
it('POST /settlements in EUR with fallback_fx freezes the transfer', async () => {
|
||||
const trip = audTrip();
|
||||
const trip = await audTrip();
|
||||
const res = await request(server)
|
||||
.post(`/api/trips/${trip}/budget/settlements`)
|
||||
.set('Cookie', sessionCookie(1))
|
||||
@@ -582,7 +597,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
});
|
||||
|
||||
it('GET /settlement?base=EUR answers in AUD without base_rate and in EUR with it', async () => {
|
||||
const trip = audTrip();
|
||||
const trip = await audTrip();
|
||||
const dinner = await request(server)
|
||||
.post(`/api/trips/${trip}/budget`)
|
||||
.set('Cookie', sessionCookie(1))
|
||||
@@ -602,7 +617,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
});
|
||||
|
||||
it('PUT currency change to VND without a rate stores 1 instead of the USD rate', async () => {
|
||||
const trip = audTrip();
|
||||
const trip = await audTrip();
|
||||
const created = await request(server)
|
||||
.post(`/api/trips/${trip}/budget`)
|
||||
.set('Cookie', sessionCookie(1))
|
||||
@@ -615,12 +630,13 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
.send({ currency: 'VND' });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.item).toMatchObject({ currency: 'VND', exchange_rate: 1 });
|
||||
expect(db.prepare('SELECT currency, exchange_rate FROM budget_items WHERE id = ?').get(created.body.item.id))
|
||||
const stored = await budgetRow(created.body.item.id);
|
||||
expect({ currency: stored.currency, exchange_rate: stored.exchange_rate })
|
||||
.toEqual({ currency: 'VND', exchange_rate: 1 });
|
||||
});
|
||||
|
||||
it('freeze-rates 403 without budget_edit, 400 on malformed fallback_fx, other base heals nothing (unresolved VND)', async () => {
|
||||
const trip = audTrip();
|
||||
const trip = await audTrip();
|
||||
const bill = await request(server)
|
||||
.post(`/api/trips/${trip}/budget`)
|
||||
.set('Cookie', sessionCookie(1))
|
||||
@@ -644,7 +660,7 @@ describe('Budget e2e (real auth guard + temp SQLite, real budget SQL)', () => {
|
||||
const otherBase = await freeze({ fallback_fx: { base: 'EUR', rates: { VND: 27000 } } });
|
||||
expect(otherBase.status).toBe(200);
|
||||
expect(otherBase.body).toEqual({ items: [], settlements: [], unresolved: ['VND'] });
|
||||
expect((db.prepare('SELECT exchange_rate FROM budget_items WHERE id = ?').get(bill.body.item.id) as { exchange_rate: number }).exchange_rate).toBe(1);
|
||||
expect((await budgetRow(bill.body.item.id)).exchange_rate).toBe(1);
|
||||
});
|
||||
|
||||
it('400 on base_rate=abc', async () => {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/**
|
||||
* Collab module e2e — exercises the migrated /api/trips/:tripId/collab endpoints
|
||||
* through the real JwtAuthGuard against a temp SQLite db, running CollabService's
|
||||
* real SQL (DI-injected, no service mock). canAccessTrip, the permission check,
|
||||
* the WebSocket broadcast and the chat/note notification are mocked; this focuses
|
||||
* through the real JwtAuthGuard against a real migrated temp SQLite db
|
||||
* (createSnapshotTestDb(), no hand-rolled CREATE TABLEs), running CollabService's
|
||||
* real queries (DI-injected, no service mock). The permission check, the
|
||||
* WebSocket broadcast and the chat/note notification are mocked; this focuses
|
||||
* on auth, trip-access 404, permission 403, the create-201 status codes, the
|
||||
* vote/react 200 overrides and the persisted rows.
|
||||
* vote/react 200 overrides and the persisted rows. Rows are seeded and read
|
||||
* through the factories in tests/helpers/factories.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll, afterAll, beforeEach, vi, type MockInstance } from 'vitest';
|
||||
import request from 'supertest';
|
||||
@@ -12,59 +14,12 @@ import cookieParser from 'cookie-parser';
|
||||
import type { Server } from 'http';
|
||||
import { RealtimeModule } from '../../src/nest/realtime/realtime.module';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import { seedUser, sessionCookie } from './harness';
|
||||
import { sessionCookie } from './harness';
|
||||
|
||||
const { db } = vi.hoisted(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const Database = require('better-sqlite3');
|
||||
const tmp = new Database(':memory:');
|
||||
tmp.exec('PRAGMA journal_mode = WAL');
|
||||
// The note/message/poll formatters join users for username + avatar.
|
||||
tmp.exec(`CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE, role TEXT NOT NULL DEFAULT 'user', password_version INTEGER NOT NULL DEFAULT 0,
|
||||
avatar TEXT);`);
|
||||
// The note/message notifications read the trip title fire-and-forget; the table
|
||||
// must exist so that query doesn't throw after the test has torn down.
|
||||
tmp.exec('CREATE TABLE trips (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, user_id INTEGER, currency TEXT);');
|
||||
// TripAccessGuard now reads TripsRepository.findAccessible directly
|
||||
// (Plan 3c Task 0b), a real join against trip_members.
|
||||
tmp.exec('CREATE TABLE trip_members (trip_id INTEGER NOT NULL, user_id INTEGER NOT NULL);');
|
||||
// CollabService's real SQL (DI-injected, no mock) — the collab tables as the
|
||||
// real schema + migrations shape them (website on notes, deleted on messages,
|
||||
// note_id on trip_files).
|
||||
tmp.exec(`CREATE TABLE collab_notes (id INTEGER PRIMARY KEY AUTOINCREMENT, trip_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL, category TEXT DEFAULT 'General', title TEXT NOT NULL, content TEXT,
|
||||
color TEXT DEFAULT '#6366f1', pinned INTEGER DEFAULT 0, website TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP);`);
|
||||
tmp.exec(`CREATE TABLE collab_links (id INTEGER PRIMARY KEY AUTOINCREMENT, trip_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL, title TEXT NOT NULL, url TEXT NOT NULL, pinned INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP);`);
|
||||
tmp.exec(`CREATE TABLE collab_polls (id INTEGER PRIMARY KEY AUTOINCREMENT, trip_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL, question TEXT NOT NULL, options TEXT NOT NULL, multiple INTEGER DEFAULT 0,
|
||||
closed INTEGER DEFAULT 0, deadline TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP);`);
|
||||
tmp.exec(`CREATE TABLE collab_poll_votes (id INTEGER PRIMARY KEY AUTOINCREMENT, poll_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL, option_index INTEGER NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(poll_id, user_id, option_index));`);
|
||||
tmp.exec(`CREATE TABLE collab_messages (id INTEGER PRIMARY KEY AUTOINCREMENT, trip_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL, text TEXT NOT NULL, reply_to INTEGER, deleted INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP);`);
|
||||
tmp.exec(`CREATE TABLE collab_message_reactions (id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
message_id INTEGER NOT NULL, user_id INTEGER NOT NULL, emoji TEXT NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP);`);
|
||||
tmp.exec(`CREATE TABLE trip_files (id INTEGER PRIMARY KEY AUTOINCREMENT, trip_id INTEGER NOT NULL,
|
||||
note_id INTEGER, message_id INTEGER, filename TEXT NOT NULL, original_name TEXT NOT NULL,
|
||||
file_size INTEGER, mime_type TEXT, uploaded_by INTEGER, deleted_at DATETIME,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP);`);
|
||||
// StorageRegistryService (behind StorageModule, now in this module chain) reads
|
||||
// this at onModuleInit.
|
||||
tmp.exec('CREATE TABLE app_settings (key TEXT PRIMARY KEY, value TEXT);');
|
||||
return { db: tmp };
|
||||
vi.mock('../../src/db/database', async () => {
|
||||
const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock');
|
||||
return buildDbMock(createSnapshotTestDb());
|
||||
});
|
||||
|
||||
const { canAccessTrip } = vi.hoisted(() => ({ canAccessTrip: vi.fn() }));
|
||||
vi.mock('../../src/db/database', () => ({
|
||||
db, canAccessTrip, getPlaceWithTags: vi.fn(), closeDb: () => {}, reinitialize: () => {},
|
||||
}));
|
||||
vi.mock('../../src/websocket', () => ({ broadcast: vi.fn() }));
|
||||
|
||||
import { PermissionsService } from '../../src/nest/permissions/permissions.service';
|
||||
@@ -77,8 +32,21 @@ import { CollabModule } from '../../src/nest/collab/collab.module';
|
||||
import { ZodValidationPipe } from '../../src/nest/common/zod-validation.pipe';
|
||||
import { TrekExceptionFilter } from '../../src/nest/common/trek-exception.filter';
|
||||
import { RateLimitService } from '../../src/nest/common/rate-limit.service';
|
||||
import { db } from '../../src/db/database';
|
||||
import { TestUnitOfWorkModule } from '../helpers/test-uow';
|
||||
import { createTestMikroOrmModule } from '../helpers/test-orm';
|
||||
import { createTestMikroOrmModule, createTestOrm, type TestOrm } from '../helpers/test-orm';
|
||||
import { makeUser } from '../helpers/factories/users';
|
||||
import { countRows, deleteRows, findRow, insertRow } from '../helpers/factories/rows';
|
||||
import { CollabLinks } from '../../src/db/entities/CollabLinks.entity';
|
||||
import { CollabMessageReactions } from '../../src/db/entities/CollabMessageReactions.entity';
|
||||
import { CollabMessages } from '../../src/db/entities/CollabMessages.entity';
|
||||
import { CollabNotes } from '../../src/db/entities/CollabNotes.entity';
|
||||
import { CollabPollVotes } from '../../src/db/entities/CollabPollVotes.entity';
|
||||
import { CollabPolls } from '../../src/db/entities/CollabPolls.entity';
|
||||
import { TripFiles } from '../../src/db/entities/TripFiles.entity';
|
||||
import { Trips } from '../../src/db/entities/Trips.entity';
|
||||
|
||||
let orm: TestOrm;
|
||||
|
||||
describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
let server: Server;
|
||||
@@ -98,31 +66,33 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
seedUser(db as never, { id: 1 });
|
||||
orm = await createTestOrm(db);
|
||||
// Pinned id: sessionCookie(1) signs for exactly this user.
|
||||
await makeUser(orm, { id: 1, username: 'e2e-user', email: 'e2e@example.test', role: 'user', password_version: 0 });
|
||||
app = await build();
|
||||
checkPermission = vi.spyOn(app.get(PermissionsService), 'checkPermission');
|
||||
server = app.getHttpServer();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
// Plan 3c Task 0b: TripAccessGuard reads TripsRepository.findAccessible
|
||||
// directly now, a real query — `canAccessTrip.mockReturnValue(...)` no
|
||||
// longer intercepts it, so trip 5's real row is (re-)seeded every test
|
||||
// instead, owned by user 1, matching what the mock used to fake.
|
||||
db.prepare('DELETE FROM trips WHERE id = 5').run();
|
||||
db.prepare("INSERT INTO trips (id, title, user_id) VALUES (5, 'Trip', 1)").run();
|
||||
// directly now, a real query, so trip 5's real row is (re-)seeded every
|
||||
// test, owned by user 1.
|
||||
await deleteRows(orm, Trips, { id: 5 });
|
||||
await insertRow(orm, Trips, { id: 5, title: 'Trip', user: 1 });
|
||||
checkPermission.mockReturnValue(true);
|
||||
db.prepare('DELETE FROM collab_message_reactions').run();
|
||||
db.prepare('DELETE FROM collab_poll_votes').run();
|
||||
db.prepare('DELETE FROM collab_messages').run();
|
||||
db.prepare('DELETE FROM collab_polls').run();
|
||||
db.prepare('DELETE FROM trip_files').run();
|
||||
db.prepare('DELETE FROM collab_notes').run();
|
||||
db.prepare('DELETE FROM collab_links').run();
|
||||
await deleteRows(orm, CollabMessageReactions);
|
||||
await deleteRows(orm, CollabPollVotes);
|
||||
await deleteRows(orm, CollabMessages);
|
||||
await deleteRows(orm, CollabPolls);
|
||||
await deleteRows(orm, TripFiles);
|
||||
await deleteRows(orm, CollabNotes);
|
||||
await deleteRows(orm, CollabLinks);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
await orm.close();
|
||||
});
|
||||
|
||||
it('401 without a session cookie', async () => {
|
||||
@@ -130,7 +100,7 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('200 list notes for an accessible trip', async () => {
|
||||
db.prepare("INSERT INTO collab_notes (id, trip_id, user_id, title) VALUES (1, 5, 1, 'N')").run();
|
||||
await insertRow(orm, CollabNotes, { id: 1, trip: 5, user: 1, title: 'N' });
|
||||
const res = await request(server).get('/api/trips/5/collab/notes').set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.notes).toHaveLength(1);
|
||||
@@ -138,7 +108,7 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('404 when the trip is not accessible', async () => {
|
||||
db.prepare('DELETE FROM trips WHERE id = 5').run();
|
||||
await deleteRows(orm, Trips, { id: 5 });
|
||||
const res = await request(server).get('/api/trips/5/collab/notes').set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Trip not found' });
|
||||
@@ -148,8 +118,8 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
const res = await request(server).post('/api/trips/5/collab/notes').set('Cookie', sessionCookie(1)).send({ title: 'N' });
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.note).toMatchObject({ title: 'N', category: 'General', color: '#6366f1', pinned: 0 });
|
||||
const row = db.prepare('SELECT * FROM collab_notes WHERE trip_id = 5').get() as { title: string };
|
||||
expect(row.title).toBe('N');
|
||||
const row = await findRow(orm, CollabNotes, { trip: 5 });
|
||||
expect(row?.title).toBe('N');
|
||||
});
|
||||
|
||||
it('403 on note create without permission', async () => {
|
||||
@@ -160,37 +130,36 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('200 on poll vote (not 201), vote persisted', async () => {
|
||||
db.prepare('INSERT INTO collab_polls (id, trip_id, user_id, question, options) VALUES (7, 5, 1, ?, ?)')
|
||||
.run('Q?', JSON.stringify(['A', 'B']));
|
||||
await insertRow(orm, CollabPolls, { id: 7, trip: 5, user: 1, question: 'Q?', options: JSON.stringify(['A', 'B']) });
|
||||
const res = await request(server).post('/api/trips/5/collab/polls/7/vote').set('Cookie', sessionCookie(1)).send({ option_index: 0 });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.poll).toMatchObject({ id: 7, is_closed: false });
|
||||
expect(res.body.poll.options[0].voters).toHaveLength(1);
|
||||
const vote = db.prepare('SELECT * FROM collab_poll_votes WHERE poll_id = 7').get() as { option_index: number };
|
||||
expect(vote.option_index).toBe(0);
|
||||
const vote = await findRow(orm, CollabPollVotes, { poll: 7 });
|
||||
expect(vote?.option_index).toBe(0);
|
||||
});
|
||||
|
||||
it('201 on message create, row persisted', async () => {
|
||||
const res = await request(server).post('/api/trips/5/collab/messages').set('Cookie', sessionCookie(1)).send({ text: 'hi' });
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.message).toMatchObject({ text: 'hi', trip_id: 5, user_id: 1 });
|
||||
const row = db.prepare('SELECT * FROM collab_messages WHERE trip_id = 5').get() as { text: string };
|
||||
expect(row.text).toBe('hi');
|
||||
const row = await findRow(orm, CollabMessages, { trip: 5 });
|
||||
expect(row?.text).toBe('hi');
|
||||
});
|
||||
|
||||
it('200 on react (not 201), reaction persisted and toggled', async () => {
|
||||
db.prepare("INSERT INTO collab_messages (id, trip_id, user_id, text) VALUES (3, 5, 1, 'react me')").run();
|
||||
await insertRow(orm, CollabMessages, { id: 3, trip: 5, user: 1, text: 'react me' });
|
||||
const res = await request(server).post('/api/trips/5/collab/messages/3/react').set('Cookie', sessionCookie(1)).send({ emoji: '👍' });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.reactions).toHaveLength(1);
|
||||
expect(res.body.reactions[0]).toMatchObject({ emoji: '👍', count: 1 });
|
||||
expect(db.prepare('SELECT COUNT(*) as c FROM collab_message_reactions WHERE message_id = 3').get()).toEqual({ c: 1 });
|
||||
expect(await countRows(orm, CollabMessageReactions, { message: 3 })).toBe(1);
|
||||
});
|
||||
|
||||
// The advisory this route was reported under: it answered anyone with a session,
|
||||
// for any trip id, and drove an outbound fetch from that.
|
||||
it('404 on link-preview for a trip the caller cannot reach', async () => {
|
||||
db.prepare('DELETE FROM trips WHERE id = 5').run();
|
||||
await deleteRows(orm, Trips, { id: 5 });
|
||||
const res = await request(server)
|
||||
.get('/api/trips/5/collab/link-preview?url=https://example.com/')
|
||||
.set('Cookie', sessionCookie(1));
|
||||
@@ -248,7 +217,7 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('404 when the trip is not accessible', async () => {
|
||||
db.prepare('DELETE FROM trips WHERE id = 5').run();
|
||||
await deleteRows(orm, Trips, { id: 5 });
|
||||
const res = await request(server).get('/api/trips/5/collab/links').set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
@@ -258,7 +227,7 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
.send({ title: 'Ferry', url: 'https://example.com/ferry' });
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.link).toMatchObject({ title: 'Ferry', url: 'https://example.com/ferry' });
|
||||
const row = db.prepare('SELECT * FROM collab_links WHERE trip_id = 5').get() as { title: string; user_id: number };
|
||||
const row = await findRow(orm, CollabLinks, { trip: 5 });
|
||||
expect(row).toMatchObject({ title: 'Ferry', user_id: 1 });
|
||||
});
|
||||
|
||||
@@ -275,15 +244,15 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('200 on list, pinned first', async () => {
|
||||
db.prepare("INSERT INTO collab_links (id, trip_id, user_id, title, url, pinned) VALUES (1, 5, 1, 'Plain', 'https://a.test', 0)").run();
|
||||
db.prepare("INSERT INTO collab_links (id, trip_id, user_id, title, url, pinned) VALUES (2, 5, 1, 'Pinned', 'https://b.test', 1)").run();
|
||||
await insertRow(orm, CollabLinks, { id: 1, trip: 5, user: 1, title: 'Plain', url: 'https://a.test', pinned: 0 });
|
||||
await insertRow(orm, CollabLinks, { id: 2, trip: 5, user: 1, title: 'Pinned', url: 'https://b.test', pinned: 1 });
|
||||
const res = await request(server).get('/api/trips/5/collab/links').set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.links.map((l: { title: string }) => l.title)).toEqual(['Pinned', 'Plain']);
|
||||
});
|
||||
|
||||
it('200 on update and the pin lands in the row', async () => {
|
||||
db.prepare("INSERT INTO collab_links (id, trip_id, user_id, title, url) VALUES (1, 5, 1, 'Plain', 'https://a.test')").run();
|
||||
await insertRow(orm, CollabLinks, { id: 1, trip: 5, user: 1, title: 'Plain', url: 'https://a.test' });
|
||||
const res = await request(server).put('/api/trips/5/collab/links/1').set('Cookie', sessionCookie(1)).send({ pinned: true });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.link).toMatchObject({ id: 1, pinned: 1 });
|
||||
@@ -295,14 +264,14 @@ describe('Collab e2e (real auth guard + temp SQLite)', () => {
|
||||
});
|
||||
|
||||
it('200 on delete and the row is gone', async () => {
|
||||
db.prepare("INSERT INTO collab_links (id, trip_id, user_id, title, url) VALUES (1, 5, 1, 'Plain', 'https://a.test')").run();
|
||||
await insertRow(orm, CollabLinks, { id: 1, trip: 5, user: 1, title: 'Plain', url: 'https://a.test' });
|
||||
const res = await request(server).delete('/api/trips/5/collab/links/1').set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(200);
|
||||
expect(db.prepare('SELECT COUNT(*) c FROM collab_links').get()).toEqual({ c: 0 });
|
||||
expect(await countRows(orm, CollabLinks)).toBe(0);
|
||||
});
|
||||
|
||||
it('403 on delete without collab_edit', async () => {
|
||||
db.prepare("INSERT INTO collab_links (id, trip_id, user_id, title, url) VALUES (1, 5, 1, 'Plain', 'https://a.test')").run();
|
||||
await insertRow(orm, CollabLinks, { id: 1, trip: 5, user: 1, title: 'Plain', url: 'https://a.test' });
|
||||
checkPermission.mockReturnValue(false);
|
||||
expect((await request(server).delete('/api/trips/5/collab/links/1').set('Cookie', sessionCookie(1))).status).toBe(403);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user