test(tours): bring the server tests in line with the tours board

Expectations follow createAssignment's options, the stage_ends column, the editor's trip access and the broadcasts of the take-over. Refusals in the run and ski e2e tests go one by one so supertest does not reset a connection under another request. A parity test keeps the source hint enums in step with the contract.
This commit is contained in:
Maurice
2026-10-20 17:51:27 +02:00
parent 0f600d04f5
commit 4d81180fc1
9 changed files with 55 additions and 9 deletions
@@ -386,6 +386,7 @@ describe('ToursRepository writes', () => {
ski_technique: null,
track_started_at: null,
track_ended_at: null,
stage_ends: 0,
});
});
@@ -0,0 +1,20 @@
import { TourSourceHintsReason, TourSourceHintsState } from '../../../src/db/entities/TourSourceHints.entity';
import { tourSourceHintReasonSchema, tourSourceHintStateSchema } from '@trek/shared';
import { describe, expect, it } from 'vitest';
/**
* WAN-02: a hint's state and reason are CHECK lists (migration 046120) the
* entity carries as enums, and the contract holds its own. A value one side
* knows and the other refuses would be a hint the watch can find and the
* database cannot store, or one stored that the answer cannot describe.
*/
describe('wanderer source hint columns match the contract', () => {
it('TOURHINTCOL-001: knows the same states as the hint contract', () => {
expect(Object.values(TourSourceHintsState).sort()).toEqual([...tourSourceHintStateSchema.options].sort());
});
it('TOURHINTCOL-002: knows the same reasons as the hint contract', () => {
expect(Object.values(TourSourceHintsReason).sort()).toEqual([...tourSourceHintReasonSchema.options].sort());
});
});
@@ -159,6 +159,8 @@ describe('CollectionToursService', () => {
it('LIB3-SVC-002: keeps it under another name, an editor may keep one too', async () => {
const f = await fixture();
// An editor of the list keeps only a tour of a trip they can open themselves.
await addTripMember(orm, f.alps.id, f.editor.id);
const { tour } = await service.save(f.editor.id, f.list.id, {
source_trip_id: f.alps.id,
source_place_id: f.ridge.id,
@@ -231,11 +231,11 @@ describe('TourChangeMcp (MCP-T02)', () => {
});
expect(read(await prepare(f.trip.id, f.bakery.id, changes, f.user.id))).toEqual({ error: 'Tour not found.' });
const failure = new Error('database gone');
const prepare = vi.spyOn(t.get(TourChangePreviewService), 'prepare').mockRejectedValueOnce(failure);
const servicePrepare = vi.spyOn(t.get(TourChangePreviewService), 'prepare').mockRejectedValueOnce(failure);
try {
await expect(prepare(f.trip.id, f.walk.id, changes, f.user.id)).rejects.toBe(failure);
} finally {
prepare.mockRestore();
servicePrepare.mockRestore();
}
});
@@ -193,7 +193,7 @@ describe('Tours deletion and assignment authorization (mock-only)', () => {
if (handler === 'create') {
expect(assignments.dayExists).toHaveBeenCalledWith('11', '7');
expect(assignments.placeExists).toHaveBeenCalledWith(42, '7');
expect(assignments.createAssignment).toHaveBeenCalledWith('11', 42, 'Tour');
expect(assignments.createAssignment).toHaveBeenCalledWith('11', 42, 'Tour', {});
expect(assignments.deleteAssignment).not.toHaveBeenCalled();
expect(assignments.broadcast).toHaveBeenCalledWith('7', 'assignment:created', { assignment }, 'socket');
} else {