feat(connect): table bookings from the online ordering app; food fired to the kitchen before arrival

Plan phase 3S, step S.6.
- Pull: "reservation" / "preorder" orders become Reservations waiting for an answer
  (status "requested"; services/online_reservations.py), with the food ordered ahead kept on
  the booking (items_json at the cloud's prices, the site's price check) — no order yet.
  Migration 0020 (reservations: online_order_cloud_id, online_ref, items_json, total,
  online_price_diff, fire_at, order_id, response_note).
- Confirm → the food's fire time = booking time − fire minutes (setting); the fire worker
  (connect_orders, every 20 s) turns the food into an order at that time (needs an open
  business day; waits otherwise): kitchen tickets, KDS (reference and time). Early arrival
  fires at once. Seating moves the order to the table (refused if the table has an open
  order). Decline / cancel / no-show with a reason. Every step mirrored to the cloud.
- Found: the KDS filter dropped every online order without an online status (SQL NULL in
  NOT(a AND b)) — made NULL-safe.
- Counter: Online → Bookings (requests first, then upcoming), BookingPanel (confirm,
  decline with reasons, food and when it goes to the kitchen, seat at a free table, cancel,
  no-show); the Online badge and chime count booking requests.
- Manager: Online ordering → Table bookings settings (on, food ahead, hours, slot, notice,
  days ahead, party size, fire minutes); the dashboard's reservations card confirms /
  declines online requests; the reservations router delegates online bookings' status steps.
- Tests: tests/test_online_bookings.py (8), unit tests (terminal, manager), e2e: order app
  (book with food → the venue confirms), terminal (request → confirm → the two dishes reach
  the KDS at the fire time, not before → seated), manager (booking settings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 19:31:44 +02:00
co-authored by Claude Opus 5.5
parent 0ca700279a
commit 70c8f2bb57
33 changed files with 1402 additions and 105 deletions
+38 -1
View File
@@ -39,7 +39,7 @@ const cloudServer = http.createServer((req, res) => {
})
await new Promise(res => cloudServer.listen(0, '127.0.0.1', res))
const backend = await startBackend({ port: 8059, siteId: 'test-site-1', cloudUrl: `http://127.0.0.1:${cloudServer.address().port}`,
env: { LICENSE_MODE: 'off', CONNECT_SYNC_INTERVAL_SECONDS: '1' } })
env: { LICENSE_MODE: 'off', CONNECT_SYNC_INTERVAL_SECONDS: '1', XENIA_FIRE_CHECK_SECONDS: '2' } })
const term = await startTerminalVite({ port: 5187, backendUrl: backend.url })
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
const r = reporter('terminal: pairing, sign-in, app states (paired screens)')
@@ -607,6 +607,43 @@ try {
r.check('3.3d: …and it leaves the New list', await page.waitForFunction(() => !document.querySelector('[data-testid="online-order"]'), null, { timeout: 5000 })
.then(() => true).catch(() => false))
// ── S.6: a table booking with two dishes: confirmed, the dishes reach the KDS at the fire time ──
const ordering = await api('GET', '/api/connect/fees/ordering', { token: boss })
await api('PUT', '/api/connect/fees/ordering', { token: boss, body: { ...ordering,
reservations: { ...ordering.reservations, enabled: true, with_food: true, fire_minutes: 1 } } })
const arriving = new Date(Date.now() + 90_000) // the kitchen gets it a minute before: in ~30 s
cloud.queue.push(cloudOrder(43, 'preorder', 'Eleni Booking', 0, { party_size: 4, requested_for: arriving.toISOString(), sales_point: 'online_preorder',
customer_address: null }))
await page.getByTestId('online-list-bookings').click()
const bookingCard = page.locator('[data-testid="booking"][data-status="requested"]').first()
r.check('S.6: a booking request reaches the counter (Online → Bookings), waiting for an answer',
await bookingCard.waitFor({ timeout: 15_000 }).then(() => true).catch(() => false) && (await bookingCard.textContent()).includes('Eleni Booking'))
await bookingCard.click()
r.check('S.6: …it shows the party and the two dishes ordered ahead', await shown(page, 'booking-panel', 5000)
&& (await page.getByTestId('booking-guest').textContent()).includes('4 people') && (await page.getByTestId('booking-food').textContent()).includes(`2× ${simple.name}`))
await page.screenshot({ path: path.join(OUT, 'terminal-pos-booking.png') })
await page.getByTestId('booking-confirm').click()
await page.waitForFunction(() => document.querySelector('[data-testid="booking-panel"]')?.dataset.status === 'pending', null, { timeout: 8000 }).catch(() => {})
for (let i = 0; i < 30 && !cloud.statuses.some(x => x.id === 43); i++) await sleep(100)
r.check('S.6: Confirm → confirmed, and the customer is told', await page.getByTestId('booking-panel').getAttribute('data-status') === 'pending'
&& cloud.statuses.some(x => x.id === 43 && x.status === 'accepted'), JSON.stringify(cloud.statuses.filter(x => x.id === 43)))
const bookingOnKds = async () => (await api('GET', '/api/kds/orders', { token: boss })).orders.find(o => o.online_ref === 'ORD-0043')
r.check('S.6: …the kitchen does not get the dishes at once', !(await bookingOnKds())
&& (await page.getByTestId('booking-food').textContent()).includes('kitchen'))
let fired = null
for (let i = 0; i < 90 && !fired; i++) { fired = await bookingOnKds(); if (!fired) await sleep(1000) }
const firedAt = Date.now()
r.check('S.6: …at the fire time (a minute before arrival) the two dishes are on the KDS, with the time',
!!fired && fired.items.reduce((s, i) => s + i.quantity, 0) === 2 && !!fired.requested_for && firedAt < arriving.getTime() - 50_000,
JSON.stringify(fired?.items?.map(i => [i.product_name, i.quantity])))
const freeTable = (await api('GET', '/api/pos/tables', { token: boss })).tables.find(x => !x.order)
await page.getByTestId('booking-table').selectOption(String(freeTable.id))
await page.getByTestId('booking-arrive').click()
for (let i = 0; i < 30 && !cloud.statuses.some(x => x.id === 43 && x.status === 'delivered'); i++) await sleep(100)
const seated = await api('GET', `/api/orders/${fired?.id}`, { token: boss }).catch(() => null)
r.check('S.6: the guests arrive and are seated → their order moves to the table; the customer\'s page says welcome',
seated?.table_id === freeTable.id && cloud.statuses.some(x => x.id === 43 && x.status === 'delivered'))
// ── 3.3e: refunds ───────────────────────────────────────────────────────
// fiscal receipts on, with today's text-file bridge: it can't take credit notes yet, so the
// cashier is told to issue it on the machine (owner decision 2026-11-15)