mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 06:26:26 +00:00
fix(server): the booked night settles in one pass, and the sibling paths seat it too
The audit over the 4.3.1 release found the seating rule reading a night by one value and its neighbours by another, so two nights on one day never agreed: the migration reported moves that changed nothing, flipped the pair on the next run and dropped the road drawn between them, and in the service every notes edit swapped them. One rule now lives in accommodations/night-seat.ts, measures every night by its own check-in, breaks a tie by the booking made first, and carries the vias; the service, the reseat migration and a trip date change all seat through it, the last of which used to append the night at the end of its day again. An account created by a first SSO login writes the user.register row the password path writes. Tests cover the equal and absent check-ins, the date change, the booking form path and a day that is nothing but its night.
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
*
|
||||
* A night's stop used to go last on its check-in day unless a stop pinned to a later
|
||||
* hour pulled it forward, and the backfill for older bookings appended it as well. The
|
||||
* night leads its day now (AccommodationsService.positionForCheckIn), and this step
|
||||
* brings the trips planned under the old rule along, drawn roads included.
|
||||
* night leads its day now (night-seat.ts, the rule AccommodationsService applies), and
|
||||
* this step brings the trips planned under the old rule along, drawn roads included.
|
||||
*
|
||||
* The rules live in reseat-booked-nights.ts and are tested there directly on a fully
|
||||
* migrated database: the columns the step reads (assignment_time, accommodation_id)
|
||||
@@ -189,6 +189,108 @@ describe('booked night reseat', () => {
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
});
|
||||
|
||||
it('RESEAT-011: two nights with the same check-in, booked in that order, stay put with their roads', () => {
|
||||
// Each used to count the other as "at or before" its check-in, so the step reported
|
||||
// two moves it never made and the reanchor dropped the road between them.
|
||||
const db = freshDb();
|
||||
const [first, second] = [place(db, 'Adlon'), place(db, 'Mercure')];
|
||||
stop(db, first, 0, null, night(db, first, '15:00'));
|
||||
stop(db, second, 1, null, night(db, second, '15:00'));
|
||||
const between = via(db, 0);
|
||||
const intoTomorrow = via(db, 1);
|
||||
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
|
||||
expect(order(db)).toEqual([first, second]);
|
||||
expect(vias(db)).toEqual([
|
||||
{ id: between, after_order_index: 0, sequence: 0 },
|
||||
{ id: intoTomorrow, after_order_index: 1, sequence: 0 },
|
||||
]);
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
});
|
||||
|
||||
it('RESEAT-012: two nights with the same check-in settle by their booking, and only once', () => {
|
||||
const db = freshDb();
|
||||
const [fuel, first, second] = [place(db, 'Aral'), place(db, 'Adlon'), place(db, 'Mercure')];
|
||||
const firstNight = night(db, first, '15:00');
|
||||
const secondNight = night(db, second, '15:00');
|
||||
stop(db, fuel, 0);
|
||||
stop(db, second, 1, null, secondNight);
|
||||
stop(db, first, 2, null, firstNight);
|
||||
|
||||
expect(reseatBookedNights(db)).toBe(2);
|
||||
|
||||
expect(order(db)).toEqual([first, second, fuel]);
|
||||
expect(indexes(db)).toEqual([0, 1, 2]);
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
expect(order(db)).toEqual([first, second, fuel]);
|
||||
});
|
||||
|
||||
it('RESEAT-013: two nights without a check-in settle by their booking too', () => {
|
||||
// Both used to want the front, and every pass swapped them.
|
||||
const db = freshDb();
|
||||
const [first, second] = [place(db, 'Adlon'), place(db, 'Mercure')];
|
||||
const firstNight = night(db, first, null);
|
||||
const secondNight = night(db, second, null);
|
||||
stop(db, second, 0, null, secondNight);
|
||||
stop(db, first, 1, null, firstNight);
|
||||
|
||||
expect(reseatBookedNights(db)).toBe(1);
|
||||
|
||||
expect(order(db)).toEqual([first, second]);
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
expect(order(db)).toEqual([first, second]);
|
||||
});
|
||||
|
||||
it('RESEAT-014: a night without a check-in leads one with a clock', () => {
|
||||
const db = freshDb();
|
||||
const [fuel, clocked, open] = [place(db, 'Aral'), place(db, 'Adlon'), place(db, 'Mercure')];
|
||||
stop(db, fuel, 0);
|
||||
stop(db, clocked, 1, null, night(db, clocked, '15:00'));
|
||||
stop(db, open, 2, null, night(db, open, null));
|
||||
|
||||
reseatBookedNights(db);
|
||||
|
||||
expect(order(db)).toEqual([open, clocked, fuel]);
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
expect(order(db)).toEqual([open, clocked, fuel]);
|
||||
});
|
||||
|
||||
it('RESEAT-015: an hour pinned on a night own stop is not what the other nights read it by', () => {
|
||||
// The stop carries eight, the booking carries three, and a night seats itself by
|
||||
// its check-in. Read the pinned hour off the row instead and the two of them
|
||||
// answer the same question differently: each counts the other as ahead, the step
|
||||
// reports two moves on every run for ever, and the swap in between drops the road.
|
||||
const db = freshDb();
|
||||
const [first, second] = [place(db, 'Adlon'), place(db, 'Mercure')];
|
||||
const firstNight = night(db, first, '15:00');
|
||||
const secondNight = night(db, second, '15:00');
|
||||
stop(db, first, 0, null, firstNight);
|
||||
stop(db, second, 1, '08:00', secondNight);
|
||||
const between = via(db, 0);
|
||||
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
|
||||
expect(order(db)).toEqual([first, second]);
|
||||
expect(vias(db)).toEqual([{ id: between, after_order_index: 0, sequence: 0 }]);
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
});
|
||||
|
||||
it('RESEAT-016: a night without a check-in leads on its booking, whatever hour its place carries', () => {
|
||||
const db = freshDb();
|
||||
const [first, second] = [place(db, 'Adlon', '09:00'), place(db, 'Mercure')];
|
||||
const firstNight = night(db, first, null);
|
||||
const secondNight = night(db, second, null);
|
||||
stop(db, second, 0, null, secondNight);
|
||||
stop(db, first, 1, null, firstNight);
|
||||
|
||||
expect(reseatBookedNights(db)).toBe(1);
|
||||
|
||||
expect(order(db)).toEqual([first, second]);
|
||||
expect(reseatBookedNights(db)).toBe(0);
|
||||
expect(order(db)).toEqual([first, second]);
|
||||
});
|
||||
|
||||
it('RESEAT-008: runs again without moving anything', () => {
|
||||
const db = freshDb();
|
||||
const [fuel, hotel] = [place(db, 'Aral'), place(db, 'Rostock')];
|
||||
|
||||
Reference in New Issue
Block a user