mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
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:
@@ -89,6 +89,42 @@ describe('Create assignment', () => {
|
||||
await request(app).put(url).send({ end_day: true }).expect(401);
|
||||
});
|
||||
|
||||
it('ASSIGN-STAY: two visits of one place keep their own stay, the other falls back to the place (#3092)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { trip, day, place } = setupAssignmentFixtures(user.id);
|
||||
await updateRows(orm, Places, { id: place.id }, { duration_minutes: 60 });
|
||||
const cookie = authCookie(user.id);
|
||||
const plan = `/api/trips/${trip.id}/days/${day.id}/assignments`;
|
||||
const first = (await request(app).post(plan).set('Cookie', cookie).send({ place_id: place.id }).expect(201)).body
|
||||
.assignment;
|
||||
const second = (await request(app).post(plan).set('Cookie', cookie).send({ place_id: place.id }).expect(201)).body
|
||||
.assignment;
|
||||
expect(first.stay_minutes).toBeNull();
|
||||
|
||||
const url = `/api/trips/${trip.id}/assignments/${second.id}/stay`;
|
||||
const changed = await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: 0 }).expect(200);
|
||||
expect(changed.body.assignment).toMatchObject({ id: second.id, stay_minutes: 0 });
|
||||
|
||||
// The other visit and the place itself are untouched.
|
||||
const listed = await request(app).get(`/api/trips/${trip.id}/days`).set('Cookie', cookie).expect(200);
|
||||
const visits = listed.body.days[0].assignments as Array<{ id: number; stay_minutes: number | null }>;
|
||||
expect(visits.find((a) => a.id === first.id)?.stay_minutes).toBeNull();
|
||||
expect(visits.find((a) => a.id === second.id)?.stay_minutes).toBe(0);
|
||||
expect((await findRows(orm, Places, { id: place.id }))[0]?.duration_minutes).toBe(60);
|
||||
|
||||
await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: -5 }).expect(400);
|
||||
await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: 1.5 }).expect(400);
|
||||
const foreign = createTrip(testDb, user.id);
|
||||
await request(app)
|
||||
.put(`/api/trips/${foreign.id}/assignments/${second.id}/stay`)
|
||||
.set('Cookie', cookie)
|
||||
.send({ stay_minutes: 10 })
|
||||
.expect(404);
|
||||
const reset = await request(app).put(url).set('Cookie', cookie).send({ stay_minutes: null }).expect(200);
|
||||
expect(reset.body.assignment.stay_minutes).toBeNull();
|
||||
await request(app).put(url).send({ stay_minutes: 10 }).expect(401);
|
||||
});
|
||||
|
||||
it('ASSIGN-001 — POST creates assignment linking place to day', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const { trip, day, place } = setupAssignmentFixtures(user.id);
|
||||
|
||||
@@ -227,6 +227,13 @@ export const plan: CaseGroup = {
|
||||
rest: { method: 'put', path: (s) => `${assignmentPath(s)}/end-day`, body: () => ({ end_day: true }) },
|
||||
expect: ['assignment:updated'],
|
||||
},
|
||||
{
|
||||
tool: 'set_assignment_stay',
|
||||
needs: ['assignment'],
|
||||
args: (s) => ({ ...onAssignment(s), stay_minutes: 15 }),
|
||||
rest: { method: 'put', path: (s) => `${assignmentPath(s)}/stay`, body: () => ({ stay_minutes: 15 }) },
|
||||
expect: ['assignment:updated'],
|
||||
},
|
||||
{
|
||||
tool: 'unassign_place',
|
||||
needs: ['assignment'],
|
||||
|
||||
Reference in New Issue
Block a user