From 3a8b54d7614e21555245d5f98256d58e6a253073 Mon Sep 17 00:00:00 2001 From: jubnl Date: Tue, 22 Sep 2026 04:38:12 +0200 Subject: [PATCH] fix(server): the journey hooks are awaited by their callers, not detached --- .../accommodations/accommodations.service.ts | 2 +- .../assignments/assignments.controller.ts | 10 +- .../src/nest/assignments/assignments.mcp.ts | 8 +- .../nest/assignments/assignments.service.ts | 10 +- server/src/nest/assignments/itinerary.rpc.ts | 4 +- .../dawarich-suggestions.service.ts | 2 +- server/src/nest/places/places.controller.ts | 12 +- server/src/nest/places/places.rpc.ts | 14 +- server/src/nest/places/places.service.ts | 21 ++- .../src/nest/roadtrip/google-route.service.ts | 2 +- .../integration/journey-place-order.test.ts | 129 ++++++++++++++++++ .../unit/nest/assignments.controller.test.ts | 18 +-- 12 files changed, 182 insertions(+), 50 deletions(-) create mode 100644 server/tests/integration/journey-place-order.test.ts diff --git a/server/src/nest/accommodations/accommodations.service.ts b/server/src/nest/accommodations/accommodations.service.ts index 04de23c29..1867dd8e4 100644 --- a/server/src/nest/accommodations/accommodations.service.ts +++ b/server/src/nest/accommodations/accommodations.service.ts @@ -218,7 +218,7 @@ export class AccommodationsService { // anchors it holds against the order it holds, and the two have to land together. for (const day of mirror.vias ?? []) send('roadtripVia:changed', day); - if (mirror.created || mirror.moved || mirror.removed.length > 0) this.assignments.reconcile(tripId, socketId); + if (mirror.created || mirror.moved || mirror.removed.length > 0) await this.assignments.reconcile(tripId, socketId); } /** Days whose stop order this write can have changed, each named once. */ diff --git a/server/src/nest/assignments/assignments.controller.ts b/server/src/nest/assignments/assignments.controller.ts index 5f317f5e5..09ce6f6a3 100644 --- a/server/src/nest/assignments/assignments.controller.ts +++ b/server/src/nest/assignments/assignments.controller.ts @@ -72,7 +72,7 @@ export class DayAssignmentsController { } const assignment = await this.assignments.createAssignment(dayId, body.place_id, body.notes); this.assignments.broadcast(tripId, 'assignment:created', { assignment }, socketId); - this.assignments.reconcile(tripId, socketId); + await this.assignments.reconcile(tripId, socketId); return { assignment }; } @@ -95,7 +95,7 @@ export class DayAssignmentsController { @RequirePermission('day_edit') @Delete(':id') - remove( + async remove( @CurrentUser() user: User, @Param('tripId') tripId: string, @Param('dayId') dayId: string, @@ -107,7 +107,7 @@ export class DayAssignmentsController { } this.assignments.deleteAssignment(id); this.assignments.broadcast(tripId, 'assignment:deleted', { assignmentId: Number(id), dayId: Number(dayId) }, socketId); - this.assignments.reconcile(tripId, socketId); + await this.assignments.reconcile(tripId, socketId); return { success: true }; } } @@ -143,7 +143,7 @@ export class AssignmentOpsController { } const { assignment, oldDayId } = await this.assignments.moveAssignment(id, body.new_day_id, body.order_index); this.assignments.broadcast(tripId, 'assignment:moved', { assignment, oldDayId: Number(oldDayId), newDayId: Number(body.new_day_id) }, socketId); - this.assignments.reconcile(tripId, socketId); + await this.assignments.reconcile(tripId, socketId); return { assignment }; } @@ -178,7 +178,7 @@ export class AssignmentOpsController { // replayed from the offline queue has no reload after it at all. if (reordered) this.assignments.broadcast(tripId, 'assignment:reordered', reordered, undefined); if (vias) this.assignments.broadcast(tripId, 'roadtripVia:changed', vias, undefined); - this.assignments.reconcile(tripId, socketId); + await this.assignments.reconcile(tripId, socketId); return { assignment }; } diff --git a/server/src/nest/assignments/assignments.mcp.ts b/server/src/nest/assignments/assignments.mcp.ts index 9cd5bdbf5..ca999d715 100644 --- a/server/src/nest/assignments/assignments.mcp.ts +++ b/server/src/nest/assignments/assignments.mcp.ts @@ -53,7 +53,7 @@ export class AssignmentsMcp { if (!this.assignments.placeExists(placeId, tripId)) return errorResult('Place not found.'); const assignment = await this.assignments.createAssignment(dayId, placeId, notes || null); this.guards.safeBroadcast(tripId, 'assignment:created', { assignment }); - this.assignments.reconcile(tripId); + await this.assignments.reconcile(tripId); return ok({ assignment }); } @@ -103,7 +103,7 @@ export class AssignmentsMcp { return errorResult('Assignment not found.'); this.assignments.deleteAssignment(assignmentId); this.guards.safeBroadcast(tripId, 'assignment:deleted', { assignmentId, dayId }); - this.assignments.reconcile(tripId); + await this.assignments.reconcile(tripId); return ok({ success: true }); } @@ -139,7 +139,7 @@ export class AssignmentsMcp { this.guards.safeBroadcast(tripId, 'assignment:updated', { assignment }); if (reordered) this.guards.safeBroadcast(tripId, 'assignment:reordered', reordered); if (vias) this.guards.safeBroadcast(tripId, 'roadtripVia:changed', vias); - this.assignments.reconcile(tripId); + await this.assignments.reconcile(tripId); return ok({ assignment }); } @@ -228,7 +228,7 @@ export class AssignmentsMcp { // per-day assignment map on newDayId, so omitting it filed the moved assignment // under "undefined" on collaborator screens. this.guards.safeBroadcast(tripId, 'assignment:moved', { assignment: result.assignment, oldDayId: result.oldDayId, newDayId }); - this.assignments.reconcile(tripId); + await this.assignments.reconcile(tripId); return ok({ assignment: result.assignment }); } diff --git a/server/src/nest/assignments/assignments.service.ts b/server/src/nest/assignments/assignments.service.ts index 260a614c5..96909a301 100644 --- a/server/src/nest/assignments/assignments.service.ts +++ b/server/src/nest/assignments/assignments.service.ts @@ -83,12 +83,10 @@ export class AssignmentsService { * suggestions. Called after any assignment mutation (create/delete/move/time) so * the journey stays in sync. Non-fatal, like the route's try/catch. */ - reconcile(tripId: string | number, socketId?: string): void { - // R1.5: reconcile() is called fire-and-forget from a dozen sync call sites across - // this domain; reconcileTripSkeletons is now async, so the rejection is caught here - // instead of escaping as an unhandled promise rejection — same "non-fatal" contract - // the try/catch gave it before the sweep. - void this.journey.reconcileTripSkeletons(Number(tripId), socketId).catch(() => { /* non-fatal */ }); + async reconcile(tripId: string | number, socketId?: string): Promise { + try { + await this.journey.reconcileTripSkeletons(Number(tripId), socketId); + } catch { /* non-fatal */ } } /** diff --git a/server/src/nest/assignments/itinerary.rpc.ts b/server/src/nest/assignments/itinerary.rpc.ts index 32f51f486..a3823a8ec 100644 --- a/server/src/nest/assignments/itinerary.rpc.ts +++ b/server/src/nest/assignments/itinerary.rpc.ts @@ -36,7 +36,7 @@ export class ItineraryRpc { if (!this.assignments.placeExists(placeId, tripId)) throw new ForbiddenResource(`no place ${placeId} on trip ${tripId}`); const assignment = await this.assignments.createAssignment(dayId, placeId, notes); this.realtime.broadcast(tripId, 'assignment:created', { assignment }); - this.assignments.reconcile(tripId); + await this.assignments.reconcile(tripId); return assignment; } @@ -55,7 +55,7 @@ export class ItineraryRpc { // Create, delete, move and time re-mirror the linked journey skeletons afterwards, // in the controller and the MCP tool alike; reorder, transport and participants do // not. Without it an open journey keeps the removed place until the next reload. - this.assignments.reconcile(tripId); + await this.assignments.reconcile(tripId); return { deleted: true }; } } diff --git a/server/src/nest/integrations/dawarich-suggestions.service.ts b/server/src/nest/integrations/dawarich-suggestions.service.ts index f2a8c93cc..193ac7eb1 100644 --- a/server/src/nest/integrations/dawarich-suggestions.service.ts +++ b/server/src/nest/integrations/dawarich-suggestions.service.ts @@ -271,7 +271,7 @@ export class DawarichSuggestionsService { // a place somebody added to the trip. Skipping them is why an accepted stay // used to need a page reload to show up. this.places.broadcast(String(tripId), 'place:created', { place: created }, sid); - this.places.onCreated(String(tripId), placeId); + await this.places.onCreated(String(tripId), placeId); if (assignment) { this.assignments.broadcast(String(tripId), 'assignment:created', { assignment }, sid); } diff --git a/server/src/nest/places/places.controller.ts b/server/src/nest/places/places.controller.ts index 90cf375a9..b81879594 100644 --- a/server/src/nest/places/places.controller.ts +++ b/server/src/nest/places/places.controller.ts @@ -158,7 +158,7 @@ export class PlacesController { await this.requireEdit(trip, user); const place = this.places.create(tripId, body as never); this.places.broadcast(tripId, 'place:created', { place }, socketId); - this.places.onCreated(tripId, place.id); + await this.places.onCreated(tripId, place.id); return { place }; } @@ -318,7 +318,7 @@ export class PlacesController { // the DELETE — journey_entries.source_place_id is ON DELETE SET NULL, so // afterwards there is nothing left to detach. const scoped = this.places.scopedIds(tripId, ids); - for (const id of scoped) this.places.onDeleted(id); + for (const id of scoped) await this.places.onDeleted(id); // Read the linked expenses before the delete — afterwards the link is gone (#1298). const expenseIds = this.places.linkedExpenseIds(tripId, scoped); const { deleted, cancelled } = await this.places.removeMany(tripId, ids); @@ -364,7 +364,7 @@ export class PlacesController { const updated = await this.places.updateMany(tripId, ids, { category_id: body.category_id as number | null }); for (const place of updated) { this.places.broadcast(tripId, 'place:updated', { place }, socketId); - this.places.onUpdated(place.id); + await this.places.onUpdated(place.id); } return { updated: updated.map((p) => p.id), count: updated.length }; } @@ -410,7 +410,7 @@ export class PlacesController { } const place = result; this.places.broadcast(tripId, 'place:updated', { place }, socketId); - this.places.onUpdated(place.id); + await this.places.onUpdated(place.id); return { place }; } @@ -485,7 +485,7 @@ export class PlacesController { } const place = result; this.places.broadcast(tripId, 'place:updated', { place }, socketId); - this.places.onUpdated(place.id); + await this.places.onUpdated(place.id); return { place }; } @@ -498,7 +498,7 @@ export class PlacesController { if (!this.places.get(tripId, id)) { throw new HttpException({ error: 'Place not found' }, 404); } - this.places.onDeleted(Number(id)); + await this.places.onDeleted(Number(id)); const expenseIds = this.places.linkedExpenseIds(tripId, [id]); const { deleted, cancelled } = await this.places.remove(tripId, id); if (!deleted) { diff --git a/server/src/nest/places/places.rpc.ts b/server/src/nest/places/places.rpc.ts index d6ef6ff36..3aae2749c 100644 --- a/server/src/nest/places/places.rpc.ts +++ b/server/src/nest/places/places.rpc.ts @@ -62,7 +62,7 @@ export class PlacesRpc { await this.guards.requireTripEdit(tripId, actor, PLACE_EDIT_ACTION); const place = this.places.create(String(tripId), parsed.data as unknown as PlaceCreateInput); this.realtime.broadcast(tripId, 'place:created', { place }); - this.mirrorJourneys(() => this.journey.onPlaceCreated(tripId, place.id)); + await this.mirrorJourneys(() => this.journey.onPlaceCreated(tripId, place.id)); return place; } @@ -82,7 +82,7 @@ export class PlacesRpc { const place = await this.places.update(String(tripId), String(placeId), parsed.data as PlaceUpdateInput); if (place === null) throw new ForbiddenResource(`no place ${placeId} on trip ${tripId}`); this.realtime.broadcast(tripId, 'place:updated', { place }); - this.mirrorJourneys(() => this.journey.onPlaceUpdated(placeId)); + await this.mirrorJourneys(() => this.journey.onPlaceUpdated(placeId)); return place; } @@ -101,7 +101,7 @@ export class PlacesRpc { // Ahead of the DELETE, like the REST route and the MCP tool: // journey_entries.source_place_id is ON DELETE SET NULL, so afterwards the hook // finds nothing left to detach and the entries linger as orphans. - this.mirrorJourneys(() => this.journey.onPlaceDeleted(placeId)); + await this.mirrorJourneys(() => this.journey.onPlaceDeleted(placeId)); // The link is gone once the place is, so read it first (#1298). const expenseIds = this.places.linkedExpenseIds(tripId, [placeId]); // remove is async (it deletes the place's storage object): await it so the @@ -121,14 +121,10 @@ export class PlacesRpc { /** * Journey mirroring never fails a write that already succeeded. - * - * R1.5: `run` wraps a now-async `this.journey.onPlace*` call; its rejection is - * swallowed here (void + catch) rather than left unhandled — same "non-fatal" - * contract the synchronous try/catch gave it before the sweep. */ - private mirrorJourneys(run: () => Promise): void { + private async mirrorJourneys(run: () => Promise): Promise { try { - void run().catch(() => { /* non-fatal */ }); + await run(); } catch { /* non-fatal */ } diff --git a/server/src/nest/places/places.service.ts b/server/src/nest/places/places.service.ts index 0f69676ad..aa9985753 100644 --- a/server/src/nest/places/places.service.ts +++ b/server/src/nest/places/places.service.ts @@ -1594,10 +1594,19 @@ export class PlacesService { } // Journey hooks — non-fatal, mirroring the route's try/catch wrappers. - // R1.5: called fire-and-forget from several sync call sites; onPlace* are now async, - // so the rejection is swallowed here (void + catch) rather than left unhandled — - // same "non-fatal" contract the try/catch gave it before the sweep. - onCreated(tripId: string, placeId: number): void { void this.journey.onPlaceCreated(Number(tripId), placeId).catch(() => { /* non-fatal */ }); } - onUpdated(placeId: number): void { void this.journey.onPlaceUpdated(placeId).catch(() => { /* non-fatal */ }); } - onDeleted(placeId: number): void { void this.journey.onPlaceDeleted(placeId).catch(() => { /* non-fatal */ }); } + async onCreated(tripId: string, placeId: number): Promise { + try { + await this.journey.onPlaceCreated(Number(tripId), placeId); + } catch { /* non-fatal */ } + } + async onUpdated(placeId: number): Promise { + try { + await this.journey.onPlaceUpdated(placeId); + } catch { /* non-fatal */ } + } + async onDeleted(placeId: number): Promise { + try { + await this.journey.onPlaceDeleted(placeId); + } catch { /* non-fatal */ } + } } diff --git a/server/src/nest/roadtrip/google-route.service.ts b/server/src/nest/roadtrip/google-route.service.ts index 1cd817b74..6e3a68d2b 100644 --- a/server/src/nest/roadtrip/google-route.service.ts +++ b/server/src/nest/roadtrip/google-route.service.ts @@ -81,7 +81,7 @@ export class GoogleRouteService { this.places.broadcast(String(tripId), 'place:created', { place }, socketId); this.assignments.broadcast(String(tripId), 'assignment:created', { assignment }, socketId); } - this.assignments.reconcile(tripId, socketId); + await this.assignments.reconcile(tripId, socketId); return { imported: imported.length }; } } diff --git a/server/tests/integration/journey-place-order.test.ts b/server/tests/integration/journey-place-order.test.ts new file mode 100644 index 000000000..fa98b114a --- /dev/null +++ b/server/tests/integration/journey-place-order.test.ts @@ -0,0 +1,129 @@ +/** + * Regression for the Task 11 fix-round finding: PlacesService.onDeleted wraps + * a now-async JourneyDomainService.onPlaceDeleted call. The controller must + * await it before the place row (and its `journey_entries.source_place_id` + * FK, ON DELETE SET NULL) is actually deleted — otherwise the hook either + * never runs, or races the delete and finds nothing left to annotate. + * + * Wires PlacesController → PlacesService → JourneyDomainService for real + * (no journey mock), through the real buildApp() HTTP surface, so a future + * change that turns the await back into fire-and-forget shows up here rather + * than only in a unit test with a stub. + */ +import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest'; +import request from 'supertest'; +import type { Application } from 'express'; +import type { INestApplication } from '@nestjs/common'; + +vi.mock('../../src/db/database', async () => { + const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock'); + return buildDbMock(createSnapshotTestDb()); +}); +vi.mock('../../src/config', () => ({ + JWT_SECRET: 'test-jwt-secret-for-trek-testing-only', + ENCRYPTION_KEY: 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2', + updateJwtSecret: () => {}, + SESSION_DURATION: '24h', + SESSION_DURATION_MS: 86400000, + SESSION_DURATION_SECONDS: 86400, + DEFAULT_LANGUAGE: 'en', +})); +vi.mock('../../src/websocket', () => ({ + broadcast: vi.fn(), + broadcastToUser: vi.fn(), + getOnlineUserIds: vi.fn(() => []), +})); + +import { db as testDb } from '../../src/db/database'; +import { buildApp } from '../../src/bootstrap'; +import { resetTestDb, resetRateLimits } from '../helpers/test-db'; +import { createUser, createTrip, createPlace, createJourney, linkTripToJourney } from '../helpers/factories'; +import { authCookie } from '../helpers/auth'; +import { invalidatePermissionsCache } from '../../src/nest/permissions/permissions-cache'; + +let nestApp: INestApplication; +let app: Application; + +beforeAll(async () => { + nestApp = await buildApp(); + app = nestApp.getHttpAdapter().getInstance(); +}); +beforeEach(() => { + resetTestDb(testDb); + resetRateLimits(nestApp); + invalidatePermissionsCache(); + // Enable the journey addon. + testDb.prepare( + "INSERT OR REPLACE INTO addons (id, name, description, type, icon, enabled, sort_order) VALUES ('journey', 'Journey', 'Travel journal', 'global', 'Compass', 1, 35)" + ).run(); +}); +afterAll(async () => { + await nestApp.close(); + testDb.close(); +}); + +describe('deleting a place detaches its journey entry ahead of the FK cascade', () => { + it('annotates a filled entry with the removal note instead of leaving it silently orphaned', async () => { + const { user } = createUser(testDb); + const trip = createTrip(testDb, user.id); + const place = createPlace(testDb, trip.id, { name: 'Café de Flore' }); + const journey = createJourney(testDb, user.id); + linkTripToJourney(testDb, journey.id, trip.id); + + // A filled entry (not a bare skeleton) sourced from this place, the way + // onPlaceDeleted documents: it survives the delete but gets detached and + // annotated, rather than deleted outright (that path is for content-less + // skeletons) or left dangling with a stale source_place_id. + const now = Date.now(); + const entryId = testDb.prepare(` + INSERT INTO journey_entries (journey_id, source_trip_id, source_place_id, author_id, type, title, story, entry_date, visibility, sort_order, created_at, updated_at) + VALUES (?, ?, ?, ?, 'entry', ?, ?, '2026-01-15', 'private', 0, ?, ?) + `).run(journey.id, trip.id, place.id, user.id, 'A café', 'Lovely coffee.', now, now).lastInsertRowid; + + const res = await request(app) + .delete(`/api/trips/${trip.id}/places/${place.id}`) + .set('Cookie', authCookie(user.id)); + expect(res.status).toBe(200); + expect(res.body).toEqual({ success: true }); + + // The place is gone. + expect(testDb.prepare('SELECT 1 FROM places WHERE id = ?').get(place.id)).toBeUndefined(); + + // The entry survives, detached and annotated — the FK's ON DELETE SET + // NULL alone would null source_place_id but would never touch story or + // type; only onPlaceDeleted having actually run produces the note. + const entry = testDb.prepare('SELECT * FROM journey_entries WHERE id = ?').get(entryId) as { + source_place_id: number | null; + source_trip_id: number | null; + type: string; + story: string; + }; + expect(entry.source_place_id).toBeNull(); + expect(entry.source_trip_id).toBeNull(); + expect(entry.type).toBe('entry'); + expect(entry.story).toContain('the original trip place was removed from the trip plan'); + }); + + it('deletes a content-less skeleton outright rather than leaving an orphaned row behind', async () => { + const { user } = createUser(testDb); + const trip = createTrip(testDb, user.id); + const place = createPlace(testDb, trip.id, { name: 'Musée Rodin' }); + const journey = createJourney(testDb, user.id); + linkTripToJourney(testDb, journey.id, trip.id); + + const now = Date.now(); + const entryId = testDb.prepare(` + INSERT INTO journey_entries (journey_id, source_trip_id, source_place_id, author_id, type, title, entry_date, visibility, sort_order, created_at, updated_at) + VALUES (?, ?, ?, ?, 'skeleton', ?, '2026-01-16', 'private', 0, ?, ?) + `).run(journey.id, trip.id, place.id, user.id, place.name, now, now).lastInsertRowid; + + const res = await request(app) + .delete(`/api/trips/${trip.id}/places/${place.id}`) + .set('Cookie', authCookie(user.id)); + expect(res.status).toBe(200); + + // onPlaceDeleted ran (and completed) as part of the request: the + // content-less skeleton is gone, not merely detached. + expect(testDb.prepare('SELECT 1 FROM journey_entries WHERE id = ?').get(entryId)).toBeUndefined(); + }); +}); diff --git a/server/tests/unit/nest/assignments.controller.test.ts b/server/tests/unit/nest/assignments.controller.test.ts index e9f739aa8..d465f4415 100644 --- a/server/tests/unit/nest/assignments.controller.test.ts +++ b/server/tests/unit/nest/assignments.controller.test.ts @@ -10,7 +10,7 @@ const trip = { user_id: 1 }; function svc(o: Partial = {}): AssignmentsService { return { verifyTripAccess: vi.fn().mockReturnValue(trip), canEdit: vi.fn().mockReturnValue(true), broadcast: vi.fn(), - dayExists: vi.fn().mockReturnValue(true), placeExists: vi.fn().mockReturnValue(true), reconcile: vi.fn(), + dayExists: vi.fn().mockReturnValue(true), placeExists: vi.fn().mockReturnValue(true), reconcile: vi.fn().mockResolvedValue(undefined), ...o, } as unknown as AssignmentsService; } @@ -49,7 +49,7 @@ describe('DayAssignmentsController (parity with the legacy day-assignments route describe('POST', () => { it('404 place not found; then creates + hooks', async () => { expect(await thrownAsync(() => new DayAssignmentsController(svc({ placeExists: vi.fn().mockReturnValue(false) } as Partial)).create(user, '5', '3', { place_id: 2 }))).toEqual({ status: 404, body: { error: 'Place not found' } }); - const createAssignment = vi.fn().mockReturnValue({ id: 9 }); const broadcast = vi.fn(); const reconcile = vi.fn(); + const createAssignment = vi.fn().mockReturnValue({ id: 9 }); const broadcast = vi.fn(); const reconcile = vi.fn().mockResolvedValue(undefined); const s = svc({ createAssignment, broadcast, reconcile } as Partial); expect(await new DayAssignmentsController(s).create(user, '5', '3', { place_id: 2, notes: 'n' }, 'sock')).toEqual({ assignment: { id: 9 } }); expect(createAssignment).toHaveBeenCalledWith('3', 2, 'n'); @@ -66,11 +66,11 @@ describe('DayAssignmentsController (parity with the legacy day-assignments route expect(broadcast).toHaveBeenCalledWith('5', 'assignment:reordered', { dayId: 3, orderedIds: [2, 1] }, 'sock'); }); - it('DELETE /:id 404 when not in day, else success', () => { - expect(thrown(() => new DayAssignmentsController(svc({ assignmentExistsInDay: vi.fn().mockReturnValue(false) } as Partial)).remove(user, '5', '3', '9'))).toEqual({ status: 404, body: { error: 'Assignment not found' } }); - const reconcile = vi.fn(); + it('DELETE /:id 404 when not in day, else success', async () => { + expect(await thrownAsync(() => new DayAssignmentsController(svc({ assignmentExistsInDay: vi.fn().mockReturnValue(false) } as Partial)).remove(user, '5', '3', '9'))).toEqual({ status: 404, body: { error: 'Assignment not found' } }); + const reconcile = vi.fn().mockResolvedValue(undefined); const s = svc({ assignmentExistsInDay: vi.fn().mockReturnValue(true), deleteAssignment: vi.fn(), reconcile } as Partial); - expect(new DayAssignmentsController(s).remove(user, '5', '3', '9', 'sock')).toEqual({ success: true }); + expect(await new DayAssignmentsController(s).remove(user, '5', '3', '9', 'sock')).toEqual({ success: true }); expect(reconcile).toHaveBeenCalledWith('5', 'sock'); }); }); @@ -91,7 +91,7 @@ describe('AssignmentOpsController (parity with the per-assignment op routes)', ( it('PUT /:id/move 404 assignment, 404 target day, else moves', async () => { expect(await thrownAsync(() => new AssignmentOpsController(svc({ getAssignmentForTrip: vi.fn().mockReturnValue(undefined) } as Partial)).move(user, '5', '9', { new_day_id: 4 }))).toEqual({ status: 404, body: { error: 'Assignment not found' } }); expect(await thrownAsync(() => new AssignmentOpsController(svc({ getAssignmentForTrip: vi.fn().mockReturnValue({ day_id: 3 }), dayExists: vi.fn().mockReturnValue(false) } as Partial)).move(user, '5', '9', { new_day_id: 4 }))).toEqual({ status: 404, body: { error: 'Target day not found' } }); - const moveAssignment = vi.fn().mockReturnValue({ assignment: { id: 9 }, oldDayId: 3 }); const broadcast = vi.fn(); const reconcile = vi.fn(); + const moveAssignment = vi.fn().mockReturnValue({ assignment: { id: 9 }, oldDayId: 3 }); const broadcast = vi.fn(); const reconcile = vi.fn().mockResolvedValue(undefined); const s = svc({ getAssignmentForTrip: vi.fn().mockReturnValue({ day_id: 3 }), moveAssignment, broadcast, reconcile } as Partial); expect(await new AssignmentOpsController(s).move(user, '5', '9', { new_day_id: 4, order_index: 0 }, 'sock')).toEqual({ assignment: { id: 9 } }); expect(moveAssignment).toHaveBeenCalledWith('9', 4, 0); @@ -108,7 +108,7 @@ describe('AssignmentOpsController (parity with the per-assignment op routes)', ( it('PUT /:id/time 404 missing, else updates', async () => { expect(await thrownAsync(() => new AssignmentOpsController(svc({ getAssignmentForTrip: vi.fn().mockReturnValue(undefined) } as Partial)).time(user, '5', '9', {}))).toEqual({ status: 404, body: { error: 'Assignment not found' } }); - const updateTime = vi.fn().mockReturnValue({ assignment: { id: 9 }, reordered: null, vias: null }); const broadcast = vi.fn(); const reconcile = vi.fn(); + const updateTime = vi.fn().mockReturnValue({ assignment: { id: 9 }, reordered: null, vias: null }); const broadcast = vi.fn(); const reconcile = vi.fn().mockResolvedValue(undefined); const s = svc({ getAssignmentForTrip: vi.fn().mockReturnValue({ id: 9 }), updateTime, broadcast, reconcile } as Partial); expect(await new AssignmentOpsController(s).time(user, '5', '9', { place_time: '10:00' }, 'sock')).toEqual({ assignment: { id: 9 } }); expect(updateTime).toHaveBeenCalledWith('9', '10:00', undefined); @@ -136,7 +136,7 @@ describe('AssignmentOpsController (parity with the per-assignment op routes)', ( it('PUT /:id/notes 404 missing, else updates + broadcasts (#2163)', async () => { expect(await thrownAsync(() => new AssignmentOpsController(svc({ getAssignmentForTrip: vi.fn().mockReturnValue(undefined) } as Partial)).notes(user, '5', '9', { notes: 'n' }))).toEqual({ status: 404, body: { error: 'Assignment not found' } }); - const updateNotes = vi.fn().mockReturnValue({ id: 9, notes: 'Book the 10:00 entry' }); const broadcast = vi.fn(); const reconcile = vi.fn(); + const updateNotes = vi.fn().mockReturnValue({ id: 9, notes: 'Book the 10:00 entry' }); const broadcast = vi.fn(); const reconcile = vi.fn().mockResolvedValue(undefined); const s = svc({ getAssignmentForTrip: vi.fn().mockReturnValue({ id: 9 }), updateNotes, broadcast, reconcile } as Partial); expect(await new AssignmentOpsController(s).notes(user, '5', '9', { notes: 'Book the 10:00 entry' }, 'sock')).toEqual({ assignment: { id: 9, notes: 'Book the 10:00 entry' } }); expect(updateNotes).toHaveBeenCalledWith('9', 'Book the 10:00 entry');