fix(tours): prevent duplicate day assignments

This commit is contained in:
elmocito
2026-10-05 23:53:11 +02:00
parent a9f9a23908
commit af7dbce105
14 changed files with 313 additions and 15 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest';
import { HttpException } from '@nestjs/common';
import { ConflictException, HttpException } from '@nestjs/common';
import { DayAssignmentsController, AssignmentOpsController } from '../../../src/nest/assignments/assignments.controller';
import type { AssignmentsService } from '../../../src/nest/assignments/assignments.service';
import type { User } from '../../../src/types';
@@ -47,6 +47,18 @@ describe('DayAssignmentsController (parity with the legacy day-assignments route
expect(broadcast).toHaveBeenCalledWith('5', 'assignment:created', { assignment: { id: 9 } }, 'sock');
expect(reconcile).toHaveBeenCalledWith('5', 'sock');
});
it('409 duplicate Tour assignment propagates without announcing a new assignment', () => {
const broadcast = vi.fn();
const reconcile = vi.fn();
const createAssignment = vi.fn(() => { throw new ConflictException('Tour is already assigned to this day') });
const controller = new DayAssignmentsController(svc({ createAssignment, broadcast, reconcile } as Partial<AssignmentsService>));
expect(thrown(() => controller.create(user, '5', '3', { place_id: 42 }))).toMatchObject({ status: 409 });
expect(createAssignment).toHaveBeenCalledWith('3', 42, undefined);
expect(broadcast).not.toHaveBeenCalled();
expect(reconcile).not.toHaveBeenCalled();
});
});
it('PUT /reorder 404 day, else reorders + broadcasts', () => {