fix(roadtrip): keep the stay on each visit, not on the place (#3092)

A nullable day_assignments.stay_minutes holds the stay of one visit; a visit without one keeps reading the place's duration, so existing trips drive as before. REST PUT /trips/:tripId/assignments/:id/stay and the MCP tool set_assignment_stay write it with day_edit.
This commit is contained in:
Maurice
2026-11-14 17:48:57 +01:00
parent 535761dbd5
commit bac4599d64
40 changed files with 510 additions and 96 deletions
+20
View File
@@ -3,12 +3,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { assignmentRepo } from './assignmentRepo'
import { offlineDb, clearAll } from '../db/offlineDb'
import { saveAssignmentEndDay } from '../api/assignmentEndDay'
import { saveAssignmentStay } from '../api/assignmentStay'
import { isEffectivelyOffline } from '../sync/networkMode'
import { mutationQueue } from '../sync/mutationQueue'
import { apiClient, assignmentsApi } from '../api/client'
import type { Assignment, Day } from '../types'
vi.mock('../api/assignmentEndDay', () => ({ saveAssignmentEndDay: vi.fn() }))
vi.mock('../api/assignmentStay', () => ({ saveAssignmentStay: vi.fn() }))
vi.mock('../sync/networkMode', () => ({ isEffectivelyOffline: vi.fn(() => true) }))
vi.mock('../sync/authGate', () => ({ isAuthed: () => true }))
vi.mock('../api/client', () => ({ apiClient: { request: vi.fn() }, assignmentsApi: { updateTime: vi.fn(), updateNotes: vi.fn(), clearDay: vi.fn() } }))
@@ -51,6 +53,24 @@ describe('assignment day-end persistence', () => {
})
})
describe('assignment stay persistence (#3092)', () => {
it('stores the stay on the one visit offline with a replayable write', async () => {
await assignmentRepo.setStay(9, assignment, 0)
expect((await offlineDb.days.get(1))?.assignments?.[0]).toMatchObject({ id: 7, stay_minutes: 0 })
expect(await offlineDb.mutationQueue.toArray()).toEqual([expect.objectContaining({
url: '/trips/9/assignments/7/stay', method: 'PUT', body: { stay_minutes: 0 }, resource: 'assignments', entityId: 7,
})])
})
it('saves through the online API and caches what came back', async () => {
vi.mocked(isEffectivelyOffline).mockReturnValue(false)
vi.mocked(saveAssignmentStay).mockResolvedValue({ ...assignment, stay_minutes: 20 })
await assignmentRepo.setStay(9, assignment, 20)
expect(saveAssignmentStay).toHaveBeenCalledWith(9, 7, { stay_minutes: 20 })
expect((await offlineDb.days.get(1))?.assignments?.[0].stay_minutes).toBe(20)
})
})
describe('assignment time persistence', () => {
const times = { place_time: '07:00', end_time: null }