mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
fix(roadtrip): sort a booked night by its check-in, and clear the lint the cut left
Pinning an afternoon stop sorted that one and left the hotel it was booked around sitting behind it. The day's auto-sort reads each stop's own hour, and a booked night has none: nobody types a time into a hotel row, they type a check-in, and that lives on the booking. It counts now, so the night moves with everything else instead of staying where it was dropped. The assignments e2e builds its own tables and had neither the accommodation column nor day_accommodations, so every create in that file 500'd as soon as the insert learned to carry a booking id. Both are there now. And the shared lint, which is stricter than the other two and which I had not run: three leftovers from taking the check-out out of the chain, none of them used any more.
This commit is contained in:
@@ -34,7 +34,13 @@ const { db } = vi.hoisted(() => {
|
||||
tmp.exec(`CREATE TABLE day_assignments (id INTEGER PRIMARY KEY AUTOINCREMENT, day_id INTEGER NOT NULL,
|
||||
place_id INTEGER NOT NULL, order_index INTEGER NOT NULL DEFAULT 0, notes TEXT,
|
||||
assignment_time TEXT, assignment_end_time TEXT, leg_transport_mode TEXT,
|
||||
accommodation_id INTEGER,
|
||||
created_at TEXT DEFAULT (datetime('now')));`);
|
||||
// The auto-sort reads a booked night's hour off its booking, so the table has to be
|
||||
// here even though nothing in this file books one.
|
||||
tmp.exec(`CREATE TABLE day_accommodations (id INTEGER PRIMARY KEY AUTOINCREMENT, trip_id INTEGER,
|
||||
place_id INTEGER, start_day_id INTEGER, end_day_id INTEGER, check_in TEXT, check_in_end TEXT,
|
||||
check_out TEXT, confirmation TEXT, notes TEXT, created_at TEXT DEFAULT (datetime('now')));`);
|
||||
tmp.exec(`CREATE TABLE assignment_participants (assignment_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
|
||||
UNIQUE(assignment_id, user_id));`);
|
||||
tmp.exec(`CREATE TABLE tags (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, color TEXT, created_at TEXT);`);
|
||||
|
||||
@@ -369,6 +369,25 @@ describe('updateTime', () => {
|
||||
expect([order(a.id), order(c.id), order(b.id)]).toEqual([0, 1, 2]);
|
||||
});
|
||||
|
||||
it('ASG-SVC-022b: a booked night sorts by its check-in, which is where its hour lives', () => {
|
||||
// Nobody types a time into a hotel row, they type a check-in, and it sits on the
|
||||
// booking. Counted as untimed, the night stayed wherever it had been dropped: pin an
|
||||
// afternoon stop and the hotel it was booked around ended up behind it.
|
||||
const { trip, day, place } = fixture();
|
||||
const hotel = createPlace(testDb, trip.id, { name: 'Billstedt' });
|
||||
const afternoon = createDayAssignment(testDb, day.id, place.id, { order_index: 0 });
|
||||
const night = createDayAssignment(testDb, day.id, hotel.id, { order_index: 1 });
|
||||
const stay = testDb.prepare(
|
||||
"INSERT INTO day_accommodations (trip_id, place_id, start_day_id, end_day_id, check_in) VALUES (?, ?, ?, ?, '11:00')"
|
||||
).run(trip.id, hotel.id, day.id, day.id);
|
||||
testDb.prepare('UPDATE day_assignments SET accommodation_id = ? WHERE id = ?').run(Number(stay.lastInsertRowid), night.id);
|
||||
|
||||
svc.updateTime(afternoon.id, '16:00', null);
|
||||
|
||||
const order = (id: number) => (testDb.prepare('SELECT order_index FROM day_assignments WHERE id = ?').get(id) as { order_index: number }).order_index;
|
||||
expect(order(night.id)).toBeLessThan(order(afternoon.id));
|
||||
});
|
||||
|
||||
it('ASG-SVC-023: clearing with null persists but skips the auto-sort (falsy gate)', () => {
|
||||
const { day, place } = fixture();
|
||||
const a = createDayAssignment(testDb, day.id, place.id, { order_index: 0 });
|
||||
|
||||
Reference in New Issue
Block a user