feat: add trip and trip settings with optimistic locking

This commit is contained in:
Bastian Wagner
2026-08-17 15:06:00 +02:00
parent 2eb1692216
commit ddf1d03447
13 changed files with 615 additions and 1 deletions

View File

@@ -0,0 +1,73 @@
import { TripsController } from './trips.controller';
import type { AuthenticatedUser } from '../../../../libs/auth/src';
describe('TripsController', () => {
const currentUser: AuthenticatedUser = {
id: 'u1',
externalSubjectId: 'sub-1',
displayName: 'Alex',
email: 'a@example.com',
};
it('GET /trips lists trips for the current user', async () => {
const tripsService = {
listTripsForUser: jest
.fn()
.mockResolvedValue([{ id: 't1', name: 'Slovenia 2027' }]),
};
const controller = new TripsController(tripsService as never);
await expect(controller.list(currentUser)).resolves.toEqual([
{ id: 't1', name: 'Slovenia 2027' },
]);
expect(tripsService.listTripsForUser).toHaveBeenCalledWith('u1');
});
it('POST /trips creates a trip owned by the current user', async () => {
const created = {
id: 't1',
name: 'Slovenia 2027',
ownerId: 'u1',
version: 1,
};
const tripsService = { createTrip: jest.fn().mockResolvedValue(created) };
const controller = new TripsController(tripsService as never);
await expect(
controller.create(currentUser, { name: 'Slovenia 2027' }),
).resolves.toEqual(created);
expect(tripsService.createTrip).toHaveBeenCalledWith('u1', {
name: 'Slovenia 2027',
});
});
it('GET /trips/:tripId returns a single trip', async () => {
const trip = { id: 't1', name: 'Slovenia 2027' };
const tripsService = { getTrip: jest.fn().mockResolvedValue(trip) };
const controller = new TripsController(tripsService as never);
await expect(controller.getOne('t1')).resolves.toEqual(trip);
});
it('PATCH /trips/:tripId forwards the update dto including version', async () => {
const updated = { id: 't1', name: 'New name', version: 2 };
const tripsService = { updateTrip: jest.fn().mockResolvedValue(updated) };
const controller = new TripsController(tripsService as never);
await expect(
controller.update('t1', { name: 'New name', version: 1 }),
).resolves.toEqual(updated);
expect(tripsService.updateTrip).toHaveBeenCalledWith('t1', {
name: 'New name',
version: 1,
});
});
it('DELETE /trips/:tripId deletes the trip', async () => {
const tripsService = { deleteTrip: jest.fn().mockResolvedValue(undefined) };
const controller = new TripsController(tripsService as never);
await controller.remove('t1');
expect(tripsService.deleteTrip).toHaveBeenCalledWith('t1');
});
});