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:
@@ -109,6 +109,7 @@ const UNNUMBERED = [
|
||||
'Migration20200101046390_a_trip_can_keep_its_costs_as_totals_only',
|
||||
'Migration20200101046400_a_booked_flight_shows_where_it_is',
|
||||
'Migration20200101046410_a_forwarded_booking_mail_lands_in_its_trip',
|
||||
'Migration20200101046420_a_visit_keeps_its_own_stay',
|
||||
];
|
||||
// The last step the positional runner ever had; planLegacyBaseline refuses a
|
||||
// schema_version past it.
|
||||
|
||||
@@ -1078,7 +1078,7 @@ const LEGACY_LIST_ROADTRIP_VISITS = `
|
||||
SELECT a.id, a.day_id, a.order_index, a.place_id, p.name, p.lat, p.lng,
|
||||
COALESCE(a.assignment_time, p.place_time) AS time,
|
||||
COALESCE(a.assignment_end_time, p.end_time) AS end_time,
|
||||
p.duration_minutes, a.end_day,
|
||||
COALESCE(a.stay_minutes, p.duration_minutes) AS duration_minutes, a.end_day,
|
||||
a.leg_transport_mode, a.incoming_leg_transport_mode, p.stop_type, p.fill_percent,
|
||||
a.accommodation_id, stay.id AS stay_id, stay.check_in, stay.check_out, checkout.day_number AS checkout_day
|
||||
FROM day_assignments a
|
||||
@@ -1170,6 +1170,26 @@ describe('DayAssignmentsRepository.listRoadtripVisits (RPL2, roadtrip-plan.servi
|
||||
});
|
||||
});
|
||||
|
||||
it('ASSIGNREPO-036: two visits of one place keep their own stay, an unset one reads the place (#3092)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
const place = createPlace(testDb, trip.id, { name: 'Viewpoint' });
|
||||
await updateRows(t, Places, { id: place.id }, { duration_minutes: 45 });
|
||||
const stopped = createDayAssignment(testDb, day.id, place.id, { order_index: 0 });
|
||||
const passed = createDayAssignment(testDb, day.id, place.id, { order_index: 1 });
|
||||
|
||||
await withRequestContext(t.orm, () => assignments.setStayMinutes(passed.id, 0));
|
||||
|
||||
const visits = await assignments.listRoadtripVisits(trip.id);
|
||||
expect(visits.map((v) => [v.id, v.duration_minutes])).toEqual([
|
||||
[stopped.id, 45],
|
||||
[passed.id, 0],
|
||||
]);
|
||||
expect(await assignmentCols(stopped.id, 'stay_minutes')).toEqual({ stay_minutes: null });
|
||||
expect((await findRow(t, Places, { id: place.id }))?.duration_minutes).toBe(45);
|
||||
});
|
||||
|
||||
it('ASSIGNREPO-033: empty array for a trip with no assignments', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
|
||||
@@ -110,7 +110,31 @@ describe('Tool: assign_place_to_day', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('MDT-MCP-001: puts one stage of a multi-day tour on a day, refusing as REST does', async () => {
|
||||
it('set_assignment_stay: changes the stay of one visit and leaves the other visit of the place alone (#3092)', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
const place = createPlace(testDb, trip.id);
|
||||
const first = createDayAssignment(testDb, day.id, place.id);
|
||||
const second = createDayAssignment(testDb, day.id, place.id);
|
||||
await withHarness(user.id, async (h) => {
|
||||
const changed = await h.client.callTool({
|
||||
name: 'set_assignment_stay',
|
||||
arguments: { tripId: trip.id, assignmentId: second.id, stay_minutes: 5 },
|
||||
});
|
||||
expect(parseToolResult(changed)).toMatchObject({ assignment: { id: second.id, stay_minutes: 5 } });
|
||||
const other = createTrip(testDb, user.id);
|
||||
const refused = await h.client.callTool({
|
||||
name: 'set_assignment_stay',
|
||||
arguments: { tripId: other.id, assignmentId: second.id, stay_minutes: 5 },
|
||||
});
|
||||
expect(refused.isError).toBe(true);
|
||||
});
|
||||
const rows = await findRows(orm, DayAssignments, { id: { $in: [first.id, second.id] } }, { id: 'asc' });
|
||||
expect(rows.map((r) => r.stay_minutes)).toEqual([null, 5]);
|
||||
});
|
||||
|
||||
it('MDT-MCP-001:puts one stage of a multi-day tour on a day, refusing as REST does', async () => {
|
||||
const { user } = createUser(testDb);
|
||||
const trip = createTrip(testDb, user.id);
|
||||
const day = createDay(testDb, trip.id);
|
||||
|
||||
@@ -57,6 +57,7 @@ function makeRow(overrides: Partial<AssignmentWithPlaceRow> = {}): AssignmentWit
|
||||
tour_place_id: null,
|
||||
tour_route_geometry: null,
|
||||
tour_stage_key: null,
|
||||
stay_minutes: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user