mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
fix(tours): prevent duplicate day assignments
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user