- auth.single_session_waiter gains 'ask', the new default (Alembic 0051 moves venues on 'off'
to it): a second phone gets auth.session_elsewhere {device, since}; Continue retries with
replace=true and the first phone is signed out at once (live session.ended, reason
"replaced") and says why on its sign-in page. Only phones count (terminal sessions are
their own client). refuse_new / end_old unchanged.
- auth.session_ended now carries the reason; the waiter app keeps it until the next sign-in.
- The waiter app sends queued offline ops on every (re)connection, so an order queued on a
phone that was signed out by another goes out after the next sign-in there (e2e checked).
- auth.terminal_require_username (venue) + Device.require_username (per device, wins):
GET /api/devices/me/users lists nobody, the screen asks for a username then PIN/password,
a picked user_id is refused (auth.username_required), "tap" falls back to PIN.
- Manager: Sign-in settings (ask, the new switch), the device dialog's usernames choice.
Plan platform-v2 6F.7.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
710 lines
52 KiB
JavaScript
710 lines
52 KiB
JavaScript
// Waiter app suite (plan phase 4): sign-in v2 on the phone (4.2): each login mode, wrong PIN,
|
|
// one session per waiter, lock / unlock / idle sign-out, a manager's approval on the phone;
|
|
// what a waiter may do from permission keys and the venue's role defaults (4.3); orders priced
|
|
// by the server: the cart's total from a quote, lines sent by id, an offline order priced when
|
|
// the phone is back and a refused line shown to the waiter (4.4).
|
|
// Starts its own backend (:8061) and the venue-mode dev build (:5181), phone-sized Edge.
|
|
// node waiter.mjs
|
|
import path from 'node:path'
|
|
import { chromium } from 'playwright'
|
|
import { execFileSync } from 'node:child_process'
|
|
import { BROWSER_CHANNEL, OUT, PYTHON, reporter, sleep, waitFor } from './lib/env.mjs'
|
|
import { login, startBackend, startViteNative } from './lib/proc.mjs'
|
|
|
|
const backend = await startBackend({ port: 8061, siteId: 'test-site-1', env: { LICENSE_MODE: 'off' } })
|
|
const vite = await startViteNative({ port: 5181, backendUrl: backend.url })
|
|
const APP = 'http://localhost:5181'
|
|
const TOKEN_KEY = 'xenia:dev:token'
|
|
const browser = await chromium.launch(BROWSER_CHANNEL ? { channel: BROWSER_CHANNEL } : {})
|
|
const r = reporter('waiter: sign-in v2, lock, approvals (4.2), keys (4.3), server prices (4.4), languages (4.5), table history (4.7), look (4.6), owner choices (4.8)')
|
|
const errors = []
|
|
let failures = 0
|
|
|
|
async function api(method, url, { token, body, raw = false } = {}) {
|
|
const res = await fetch(backend.url + url, {
|
|
method, headers: { 'content-type': 'application/json', ...(token ? { authorization: `Bearer ${token}` } : {}) },
|
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
})
|
|
if (raw) return res
|
|
const text = await res.text()
|
|
let data = null
|
|
try { data = JSON.parse(text) } catch { data = text }
|
|
if (!res.ok) throw new Error(`${method} ${url} → ${res.status} ${text.slice(0, 200)}`)
|
|
return data
|
|
}
|
|
|
|
const phone = () => browser.newContext({ viewport: { width: 393, height: 852 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true })
|
|
async function open(ctx, url = `${APP}/login`) {
|
|
const page = await ctx.newPage()
|
|
page.on('pageerror', e => errors.push(e.message))
|
|
await page.goto(url)
|
|
return page
|
|
}
|
|
const shown = (page, testId, timeout = 10_000) => page.getByTestId(testId).first().waitFor({ timeout }).then(() => true).catch(() => false)
|
|
const gone = (page, testId, timeout = 10_000) => page.getByTestId(testId).first().waitFor({ state: 'detached', timeout }).then(() => true).catch(() => false)
|
|
async function pin(page, digits) {
|
|
for (const d of digits) await page.getByRole('button', { name: d, exact: true }).first().click()
|
|
}
|
|
const tokenOf = page => page.evaluate(k => localStorage.getItem(k), TOKEN_KEY)
|
|
const pathOf = page => page.evaluate(() => location.pathname)
|
|
const setting = (boss, key, value) => api('PUT', `/api/settings/${key}`, { token: boss, body: { value } })
|
|
|
|
try {
|
|
const boss = await login(backend.url)
|
|
await api('POST', '/api/business-day/open', { token: boss, body: {} }).catch(() => {})
|
|
const waiters = await api('GET', '/api/auth/waiters')
|
|
const maria = waiters.find(w => (w.full_name || '').includes('Κωνσταντίνου'))
|
|
// no shift left from the demo data: the phone then shows the start-shift gate (6F.2 checks it)
|
|
for (const sh of (await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.filter(x => x.waiter_id === maria?.id)) {
|
|
await api('POST', `/api/shifts/manager/end/${sh.id}`, { token: boss, body: {} }).catch(() => {})
|
|
}
|
|
|
|
// ── login-by-id is gone ────────────────────────────────────────────────────
|
|
const old = await api('POST', '/api/auth/login-by-id', { body: { waiter_id: maria?.id, pin: '3302' }, raw: true })
|
|
r.check('POST /api/auth/login-by-id is gone (404)', old.status === 404, String(old.status))
|
|
|
|
// ── PIN mode: pick your name, wrong PIN, right PIN ─────────────────────────
|
|
const ctxA = await phone()
|
|
const a = await open(ctxA)
|
|
r.check('PIN mode: the phone lists the waiters to pick from', await shown(a, 'waiter-card'))
|
|
await a.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click()
|
|
r.check('PIN mode: then the PIN pad', await shown(a, 'login-secret') && await a.getByTestId('login-secret').getAttribute('data-mode') === 'pin')
|
|
await a.evaluate(() => { window.__noReload = true })
|
|
await pin(a, '0000')
|
|
r.check('wrong PIN: a message, no reload, still on the PIN pad',
|
|
await shown(a, 'login-error', 5000) && await a.evaluate(() => window.__noReload === true) && await pathOf(a) === '/login',
|
|
await a.getByTestId('login-error').textContent().catch(() => ''))
|
|
await pin(a, '3302')
|
|
await a.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
|
|
const tokenA = await tokenOf(a)
|
|
r.check('right PIN: signed in (a session token, off the login page)', !!tokenA && await pathOf(a) !== '/login', await pathOf(a))
|
|
const sessions = await api('GET', '/api/auth/sessions', { token: boss })
|
|
r.check('the session is a "waiter" session', sessions.some(s => s.username === 'demo_maria' && s.client === 'waiter'), JSON.stringify(sessions.map(s => [s.username, s.client])))
|
|
|
|
// start the shift on the phone (the gate after sign-in), the starting cash typed with a comma (6F.2)
|
|
const cashBox = a.getByPlaceholder('0,00')
|
|
await cashBox.fill('abc', { timeout: 10_000 }).catch(() => {})
|
|
await a.getByRole('button', { name: /Start shift/ }).click({ timeout: 10_000 }).catch(() => {})
|
|
await sleep(500)
|
|
r.check('starting cash that is not a number: a message, the gate stays, no shift', await cashBox.isVisible()
|
|
&& (await a.getByText('Type an amount').count()) > 0
|
|
&& !(await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.some(x => x.waiter_id === maria?.id))
|
|
await cashBox.fill('25,50').catch(() => {})
|
|
await a.getByRole('button', { name: /Start shift/ }).click({ timeout: 10_000 }).catch(() => {})
|
|
await cashBox.waitFor({ state: 'detached', timeout: 10_000 }).catch(() => {})
|
|
const started = (await api('GET', '/api/shifts/?active_only=true', { token: boss })).shifts.find(x => x.waiter_id === maria?.id)
|
|
r.check('starting cash "25,50" is kept as €25.50', started?.starting_cash === 25.5, JSON.stringify(started?.starting_cash))
|
|
await sleep(1500)
|
|
|
|
// ── One session per waiter (refuse_new) ────────────────────────────────────
|
|
await setting(boss, 'auth.single_session_waiter', 'refuse_new')
|
|
const ctxB = await phone()
|
|
const b = await open(ctxB)
|
|
await b.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
|
|
await pin(b, '3302')
|
|
r.check('second phone, same waiter (refuse_new): refused with a message, stays on sign-in',
|
|
await shown(b, 'login-error', 5000) && await pathOf(b) === '/login' && !(await tokenOf(b)),
|
|
await b.getByTestId('login-error').textContent().catch(() => ''))
|
|
|
|
// ── Lock from the menu, wrong PIN, right PIN (same session) ────────────────
|
|
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
|
|
await a.getByTestId('menu-lock').click()
|
|
r.check('menu "Lock" locks the phone', await shown(a, 'lock-screen', 5000))
|
|
await a.reload()
|
|
r.check('still locked after the app is reopened', await shown(a, 'lock-screen', 10_000))
|
|
await pin(a, '0000')
|
|
const lockErr = await a.getByTestId('unlock-error').textContent({ timeout: 5000 }).catch(() => '')
|
|
r.check('wrong PIN on the lock: tries left shown', /4/.test(lockErr), lockErr)
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-lock.png') })
|
|
await pin(a, '3302')
|
|
r.check('right PIN unlocks: same session, same token', await gone(a, 'lock-screen', 5000) && await tokenOf(a) === tokenA)
|
|
|
|
// ── A manager's approval on the same phone (cancel without the key) ─────────
|
|
const tables = await api('GET', '/api/tables/', { token: boss })
|
|
const table = tables.find(t => !t.open_order_id && !t.current_order_id) || tables[0]
|
|
const order = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: table.id } })
|
|
await a.evaluate(id => {
|
|
window.__res = window.__xeniaClient.delete(`/api/orders/${id}`)
|
|
.then(res => ({ ok: true, status: res.status }), e => ({ ok: false, code: e.xenia?.code }))
|
|
}, order.id)
|
|
const dialog = a.getByRole('dialog')
|
|
await dialog.waitFor({ timeout: 10_000 }).catch(() => {})
|
|
r.check('approval dialog opens on the phone for ordering.orders.cancel', await a.getByTestId('override-key').textContent().catch(() => '') === 'ordering.orders.cancel')
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-approval.png') })
|
|
const inputs = dialog.locator('input')
|
|
await inputs.nth(0).fill('manager')
|
|
await inputs.nth(1).fill('1234')
|
|
await inputs.nth(1).press('Enter')
|
|
const result = await a.evaluate(() => window.__res)
|
|
r.check("the manager's PIN completes the cancel on the phone", result.ok === true, JSON.stringify(result))
|
|
|
|
// ── 4.3: what a waiter may do comes from permission keys ───────────────────
|
|
const t2 = tables.find(t => t.id !== table.id && !t.open_order_id && !t.current_order_id) || tables[1]
|
|
const o2 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t2.id } })
|
|
await a.goto(`${APP}/tables/${t2.id}`)
|
|
r.check('4.3: a waiter takes payment by default (PAY shown)', await shown(a, 'pay-button'))
|
|
await a.getByText('ACTIONS', { exact: true }).first().click()
|
|
await sleep(800)
|
|
const sheet = await a.locator('.modal-sheet--top').innerText().catch(() => '')
|
|
r.check('4.3: the actions follow the keys (transfer yes, discount hidden, cancel "with a manager\'s PIN")',
|
|
sheet.includes('Transfer the table') && !sheet.includes('Apply a discount') && sheet.includes("With a manager's approval"), sheet.replace(/\s+/g, ' ').slice(0, 300))
|
|
await a.getByText('Cancel order', { exact: true }).click()
|
|
await a.getByRole('button', { name: 'Cancel ✕' }).click()
|
|
const dlg = a.getByRole('dialog')
|
|
await dlg.waitFor({ timeout: 10_000 }).catch(() => {})
|
|
r.check('4.3: cancelling from the screen opens the approval dialog', await a.getByTestId('override-key').textContent().catch(() => '') === 'ordering.orders.cancel')
|
|
await dlg.locator('input').nth(0).fill('manager')
|
|
await dlg.locator('input').nth(1).fill('1234')
|
|
await dlg.locator('input').nth(1).press('Enter')
|
|
const cancelled = await waitFor(async () => (await api('GET', `/api/orders/${o2.id}`, { token: boss })).status === 'cancelled', 10_000, 500)
|
|
r.check("4.3: …and the manager's PIN cancels the order", !!cancelled)
|
|
|
|
// the venue takes "take payments" away from the waiter role: the phone hides PAY, the server refuses
|
|
const role = await api('GET', '/api/waiters/roles/waiter/permissions', { token: boss })
|
|
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: role.keys.filter(k => k !== 'ordering.orders.close') } })
|
|
const o3 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t2.id } })
|
|
await a.goto(`${APP}/tables/${t2.id}`)
|
|
await sleep(4000)
|
|
const refused = await api('POST', `/api/orders/${o3.id}/close`, { token: tokenA, raw: true })
|
|
const body3 = await refused.json().catch(() => ({}))
|
|
r.check('4.3: without "take payments" on the role: no PAY on the phone, the server refuses (access.denied)',
|
|
await a.getByTestId('pay-button').count() === 0 && body3?.error?.code === 'access.denied', `${await a.getByTestId('pay-button').count()} ${JSON.stringify(body3).slice(0, 120)}`)
|
|
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: role.default_keys } })
|
|
await api('DELETE', `/api/orders/${o3.id}`, { token: boss }).catch(() => {})
|
|
await a.goto(`${APP}/tables`)
|
|
|
|
// ── 4.4: orders priced by the server ────────────────────────────────────────
|
|
const prods = await api('GET', '/api/products/', { token: boss })
|
|
const simple = p => p.quick_add_enabled && p.is_available && !p.is_service_item && p.lifecycle_status === 'active'
|
|
&& !(p.preference_sets || []).some(ps => ps.default_choice_id == null)
|
|
const free = tables.filter(t => ![table.id, t2.id].includes(t.id) && !t.open_order_id && !t.current_order_id)
|
|
const [t4, t5] = free
|
|
// two products the first category on screen offers with a quick "+"
|
|
await a.goto(`${APP}/tables/${t4.id}/add?new=1`)
|
|
// the picker opens on favourites (none yet): pick the first category that has a quick "+"
|
|
let category = null
|
|
for (const c of (await api('GET', '/api/products/categories', { token: boss })).filter(c => !c.parent_id)) {
|
|
await a.getByRole('button', { name: c.name, exact: true }).first().click({ timeout: 5000 }).catch(() => {})
|
|
if (await a.locator('[data-testid="product-quick-add"]').first().waitFor({ timeout: 3000 }).then(() => true).catch(() => false)) { category = c.name; break }
|
|
}
|
|
await a.locator('[data-testid="product-quick-add"]').first().waitFor({ timeout: 5000 })
|
|
.catch(async e => { await a.screenshot({ path: path.join(OUT, 'waiter-add-items.png') }); throw e })
|
|
const onScreen = await a.locator('[data-testid="product-card"]:has([data-testid="product-quick-add"])').evaluateAll(els => els.map(e => e.dataset.name))
|
|
const [plain, other] = prods.filter(p => simple(p) && onScreen.includes(p.name))
|
|
// 6.3: allergens set in the manager reach the phone (live) and show in the product's details (hold it)
|
|
await api('PUT', `/api/products/${other.id}`, { token: boss, body: { allergens: { milk: 'contains', nuts: 'may_contain' } } })
|
|
await sleep(1500)
|
|
const held = a.locator(`[data-testid="product-card"][data-name="${other.name}"]`).first()
|
|
await held.hover()
|
|
await a.mouse.down()
|
|
await sleep(1600)
|
|
await a.mouse.up()
|
|
const info = a.getByTestId('allergens')
|
|
r.check('6.3: holding a product shows its allergens on the phone', await info.waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
|
|
&& await info.locator('[data-allergen="milk"][data-level="contains"]').count() === 1 && await info.locator('[data-allergen="nuts"][data-level="may_contain"]').count() === 1)
|
|
await a.mouse.click(5, 5)
|
|
await info.waitFor({ state: 'detached', timeout: 3000 }).catch(() => {})
|
|
// a price the phone's menu doesn't know (a price modifier): only the server can say it
|
|
const mod = await api('POST', '/api/pricing/modifiers', { token: boss, body: {
|
|
name: 'e2e 4.4', scope: 'item', item_id: plain.id, action_type: 'set', action_value: 1.2 } })
|
|
const addOn = async (tableId, product, times = 1) => {
|
|
if (!(await pathOf(a)).endsWith('/add')) await a.goto(`${APP}/tables/${tableId}/add?new=1`)
|
|
await a.getByRole('button', { name: category, exact: true }).first().click({ timeout: 5000 }).catch(() => {})
|
|
const card = a.locator(`[data-testid="product-card"][data-name="${product.name}"]`)
|
|
await card.first().waitFor({ timeout: 10_000 })
|
|
for (let i = 0; i < times; i++) await card.getByTestId('product-quick-add').first().click()
|
|
}
|
|
const total = () => a.getByTestId('cart-total')
|
|
await addOn(t4.id, plain, 2)
|
|
await a.getByTestId('cart-open').click()
|
|
const exact = await waitFor(async () => await total().getAttribute('data-estimated') === 'false', 10_000, 300)
|
|
const shownTotal = await total().innerText().catch(() => '')
|
|
r.check('4.4: the cart total is the server\'s price (a price the phone\'s menu doesn\'t know)', !!exact && shownTotal.includes('2.40'), shownTotal.replace(/\s+/g, ' '))
|
|
await a.getByRole('button', { name: /^(SEND|SUMMARY)/ }).last().click()
|
|
if (await shown(a, 'summary-total', 3000)) {
|
|
r.check('4.4: the summary shows the same total', (await a.getByTestId('summary-total').innerText()).includes('2.40'))
|
|
await a.getByRole('button', { name: /SEND/ }).last().click()
|
|
}
|
|
const sent = await waitFor(async () => {
|
|
const st = await api('GET', `/api/tables/${t4.id}/status`, { token: boss })
|
|
if (!st.active_order_id) return null
|
|
const o = await api('GET', `/api/orders/${st.active_order_id}`, { token: boss })
|
|
return o.items.length ? o : null
|
|
}, 10_000, 500)
|
|
r.check('4.4: sent by id, priced by the server: the order costs what the cart said',
|
|
!!sent && sent.items.length === 1 && sent.items[0].quantity === 2 && sent.items[0].unit_price === 1.2, JSON.stringify(sent?.items?.map(i => [i.quantity, i.unit_price])))
|
|
|
|
// offline: the order is queued by id, shown as an estimate, priced when the phone is back;
|
|
// a product taken off the menu meanwhile comes back to the waiter as refused
|
|
await a.goto(`${APP}/tables/${t5.id}/add?new=1`)
|
|
await addOn(t5.id, plain)
|
|
await ctxA.setOffline(true)
|
|
await a.getByTestId('cart-open').click()
|
|
const wentOffline = await waitFor(async () => (await total().innerText().catch(() => '')).includes('offline'), 30_000, 1000)
|
|
const est = await total().getAttribute('data-estimated').catch(() => null)
|
|
r.check('4.4: offline the cart total is an estimate (≈, the menu prices)', !!wentOffline && est === 'true'
|
|
&& (await total().innerText()).includes('≈'), `${wentOffline} ${est} ${await total().innerText().catch(() => '')}`)
|
|
await a.mouse.click(10, 400)
|
|
await sleep(500)
|
|
await addOn(t5.id, other)
|
|
await a.getByTestId('cart-open').click()
|
|
await a.getByRole('button', { name: /^(SEND|SUMMARY)/ }).last().click()
|
|
if (await shown(a, 'summary-total', 3000)) await a.getByRole('button', { name: /SEND/ }).last().click()
|
|
await sleep(2000)
|
|
await api('PUT', `/api/products/${other.id}`, { token: boss, body: { is_available: false } })
|
|
await ctxA.setOffline(false)
|
|
const synced = await waitFor(async () => {
|
|
const st = await api('GET', `/api/tables/${t5.id}/status`, { token: boss })
|
|
if (!st.active_order_id) return null
|
|
const o = await api('GET', `/api/orders/${st.active_order_id}`, { token: boss })
|
|
return o.items.length ? o : null
|
|
}, 40_000, 1000)
|
|
r.check('4.4: back online the queued order is priced by the server (not the phone\'s estimate)',
|
|
!!synced && synced.items.length === 1 && synced.items[0].product_id === plain.id && synced.items[0].unit_price === 1.2,
|
|
JSON.stringify(synced?.items?.map(i => [i.product_id, i.unit_price])))
|
|
const refusedShown = await shown(a, 'refused-lines', 15_000)
|
|
const refusedText = await a.getByTestId('refused-lines').innerText().catch(() => '')
|
|
r.check('4.4: the line the server refused comes back to the waiter with the reason', refusedShown && refusedText.includes(other.name), refusedText.replace(/\s+/g, ' ').slice(0, 200))
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-refused-lines.png') })
|
|
await a.getByTestId('refused-lines-ok').click().catch(() => {})
|
|
await api('PUT', `/api/products/${other.id}`, { token: boss, body: { is_available: true } })
|
|
await api('DELETE', `/api/pricing/modifiers/${mod.id}`, { token: boss }).catch(() => {})
|
|
for (const o of [sent, synced]) if (o) await api('DELETE', `/api/orders/${o.id}`, { token: boss }).catch(() => {})
|
|
await a.goto(`${APP}/tables`)
|
|
|
|
// ── 4.7: a table's earlier orders (the order sent above was cancelled: it is history now) ──
|
|
await a.goto(`${APP}/tables/${t4.id}`)
|
|
await a.getByTestId('history-open').click({ timeout: 10_000 })
|
|
const histShown = await shown(a, 'history-order', 10_000)
|
|
const histText = await a.getByTestId('table-history').innerText().catch(() => '')
|
|
r.check('4.7: a free table shows its earlier orders (the cancelled one, with its total)', histShown && histText.includes(`#${sent?.id}`), histText.replace(/\s+/g, ' ').slice(0, 160))
|
|
await ctxA.setOffline(true)
|
|
await a.getByTestId('history-open').click()
|
|
await a.getByTestId('history-open').click()
|
|
r.check('4.7: offline the saved history shows, marked as saved', await shown(a, 'history-cached', 10_000) && await a.getByTestId('history-order').count() > 0)
|
|
await ctxA.setOffline(false)
|
|
await a.goto(`${APP}/tables`)
|
|
|
|
// ── 4.5: English first; the language switch in the user menu, saved to the person ──
|
|
const navText = () => a.locator('body').innerText()
|
|
await a.goto(`${APP}/tables`)
|
|
await a.locator('.table-card, [data-testid="user-menu"]').first().waitFor({ timeout: 10_000 }).catch(() => {})
|
|
r.check('4.5: the phone runs in English (the venue language; the demo data stays Greek)', (await navText()).includes('Tables') && !(await navText()).includes('Τραπέζια'), (await navText()).replace(/\s+/g, ' ').slice(0, 300))
|
|
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
|
|
await a.getByTestId('menu-language-el').click()
|
|
const greek = await waitFor(async () => (await navText()).includes('Τραπέζια'), 8000, 300)
|
|
// the screen changes first, the profile is saved right after: wait for it
|
|
const me = await waitFor(async () => { const u = await api('GET', '/api/auth/me', { token: tokenA }); return u.language === 'el' && u }, 8000, 300) || {}
|
|
r.check('4.5: menu → Ελληνικά: the screen turns Greek at once and it is saved for the person', !!greek && me.language === 'el', me.language)
|
|
await a.reload()
|
|
r.check('4.5: …still Greek after a reload', !!(await waitFor(async () => (await navText()).includes('Τραπέζια'), 15_000, 500)))
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-greek.png') })
|
|
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
|
|
await a.getByTestId('menu-language-en').click()
|
|
await waitFor(async () => (await navText()).includes('Tables'), 8000, 300)
|
|
|
|
// ── 6F.3: a sent line's price changed by hand, with the reason the venue asks for ──────
|
|
{
|
|
const mariaKeys = (await api('GET', `/api/waiters/${maria.id}/permissions`, { token: boss })).keys
|
|
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss,
|
|
body: { keys: [...new Set([...mariaKeys, 'ordering.prices.modify_sent', 'ordering.prices.view_changes'])] } })
|
|
await setting(boss, 'orders.price_change_reason', 'true')
|
|
const tp = free.find(t => t.id !== t4.id && t.id !== t5.id && t.id !== (free.find(x => x.id !== t4.id && x.id !== t5.id)?.id)) || free[free.length - 1]
|
|
const op = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: tp.id } })
|
|
await api('POST', `/api/orders/${op.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }] } })
|
|
await a.goto(`${APP}/tables/${tp.id}`)
|
|
await a.reload() // the keys were changed after sign-in: the bootstrap comes again
|
|
await a.locator('.order-item').first().waitFor({ timeout: 10_000 })
|
|
await a.locator('.order-item').first().click()
|
|
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
|
await a.getByText('Change the price').first().click({ timeout: 10_000 })
|
|
await a.getByRole('button', { name: '-1 €' }).first().click()
|
|
r.check('6F.3: the venue asks why: the reason picker shows with a changed price', await shown(a, 'price-reason', 5000))
|
|
await a.getByRole('button', { name: 'Apply' }).click()
|
|
await sleep(600)
|
|
const unchanged = (await api('GET', `/api/orders/${op.id}`, { token: boss })).items[0].price_adjustment || 0
|
|
r.check('6F.3: without a reason nothing is saved', unchanged === 0 && await a.getByText('Say why the price changes').isVisible().catch(() => false))
|
|
await a.getByText('Regular customer').first().click()
|
|
await a.getByRole('button', { name: 'Apply' }).click()
|
|
const changed = await waitFor(async () => {
|
|
const ev = (await api('GET', `/api/orders/${op.id}/price-changes`, { token: boss }))
|
|
return ev.length === 1 && ev[0]
|
|
}, 10_000, 500)
|
|
r.check('6F.3: saved with its reason, who and the stage', !!changed && Math.abs(changed.after - (changed.before - 1)) < 0.001
|
|
&& changed.reason === 'Regular customer' && changed.stage === 'sent' && changed.by_id === maria.id, JSON.stringify(changed))
|
|
await a.goto(`${APP}/tables/${tp.id}`)
|
|
await a.locator('.order-item').first().waitFor({ timeout: 10_000 })
|
|
await a.locator('.order-item').first().click()
|
|
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
|
await a.getByText('Price history').first().click({ timeout: 10_000 })
|
|
r.check('6F.3: the price history on the phone (who, from → to, why)', await shown(a, 'price-history-row', 8000)
|
|
&& (await a.getByTestId('price-history-row').first().textContent()).includes('Regular customer'))
|
|
await a.keyboard.press('Escape').catch(() => {})
|
|
await setting(boss, 'orders.price_change_reason', 'false')
|
|
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss, body: { keys: mariaKeys } })
|
|
// 6F.4: the order moved to another table: the phone shows where it came from and the line's moves
|
|
const busyNow = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
|
|
const tq = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busyNow.has(x.id) && x.id !== tp.id)
|
|
await api('POST', `/api/orders/${op.id}/transfer`, { token: boss, body: { target_table_id: tq.id } })
|
|
await a.goto(`${APP}/tables/${tq.id}`)
|
|
r.check('6F.4: a moved order says where it came from', await shown(a, 'order-moved', 10_000)
|
|
&& (await a.getByTestId('order-moved').textContent()).includes('→'))
|
|
r.check('6F.4: …and its lines are marked as moved', await shown(a, 'item-moved', 5000))
|
|
await a.locator('.order-item').first().click()
|
|
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
|
await a.getByText('Move history').first().click({ timeout: 10_000 })
|
|
r.check('6F.4: the line\'s move history on the phone', await shown(a, 'move-row', 8000))
|
|
await a.keyboard.press('Escape').catch(() => {})
|
|
await setting(boss, 'orders.close_with_unpaid', 'true')
|
|
await api('POST', `/api/orders/${op.id}/close`, { token: boss })
|
|
await setting(boss, 'orders.close_with_unpaid', 'false')
|
|
}
|
|
|
|
// ── 6F.5: "+1" on a sent line, and changing a line's quantity ─────────────────────
|
|
{
|
|
await api('PUT', `/api/products/${plain.id}`, { token: boss, body: { one_more_enabled: true } })
|
|
const mariaKeys = (await api('GET', `/api/waiters/${maria.id}/permissions`, { token: boss })).keys
|
|
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss,
|
|
body: { keys: [...new Set([...mariaKeys, 'ordering.items.change_quantity', 'ordering.orders.cancel'])] } })
|
|
await setting(boss, 'orders.quantity_change', 'add_and_remove')
|
|
const busyNow = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
|
|
const tm = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busyNow.has(x.id))
|
|
const om = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: tm.id } })
|
|
await api('POST', `/api/orders/${om.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }] } })
|
|
const count = async () => (await api('GET', `/api/orders/${om.id}`, { token: boss })).items.filter(i => i.status !== 'cancelled').length
|
|
await a.goto(`${APP}/tables/${tm.id}`)
|
|
await a.reload()
|
|
await a.getByTestId('one-more-tap').first().waitFor({ timeout: 10_000 })
|
|
// one stray tap sends nothing: it arms, then goes back after 4 s
|
|
await a.getByTestId('one-more-tap').first().click()
|
|
r.check('6F.5: one tap on +1 only arms it ("Send +1" shows)', await shown(a, 'one-more-send', 3000) && await count() === 1)
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-one-more.png') })
|
|
await sleep(4600)
|
|
r.check('6F.5: …and with no second tap it goes back, nothing sent', !(await a.getByTestId('one-more-send').count()) && await count() === 1)
|
|
// tap, tap, Send → 2 more as a new line, sent like any new line
|
|
await a.getByTestId('one-more-tap').first().click()
|
|
await a.getByTestId('one-more-tap').first().click()
|
|
await a.getByTestId('one-more-send').first().click()
|
|
const again = await waitFor(async () => {
|
|
const o = await api('GET', `/api/orders/${om.id}`, { token: boss })
|
|
const live = o.items.filter(i => i.status === 'active')
|
|
return live.length === 2 && live[1].quantity === 2 && live[1].product_id === plain.id && o
|
|
}, 10_000, 500)
|
|
const newLine = again && again.items.filter(i => i.status === 'active')[1]
|
|
r.check('6F.5: +1, +1, Send: a new line of 2 for the kitchen (pending, like any new line)', !!newLine && newLine.kds_status === 'pending'
|
|
&& newLine.id !== again.items[0].id, JSON.stringify(again?.items?.map(i => [i.id, i.status, i.quantity, i.kds_status, i.printed])))
|
|
// change the first line's quantity: 1 → 3 (nothing printed), then 3 → 2 (one cancelled)
|
|
const first = again.items.filter(i => i.status === 'active')[0]
|
|
const openQty = async () => {
|
|
await a.goto(`${APP}/tables/${tm.id}`)
|
|
await a.locator('.order-item').first().waitFor({ timeout: 10_000 })
|
|
await a.locator('.order-item').first().click()
|
|
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
|
await a.getByText('Change quantity').first().click({ timeout: 10_000 })
|
|
await a.getByTestId('quantity-sheet').waitFor({ timeout: 5000 })
|
|
}
|
|
await openQty()
|
|
await a.getByTestId('quantity-more').click()
|
|
await a.getByTestId('quantity-more').click()
|
|
r.check('6F.5: the dialog shows now 1 → new 3', (await a.getByTestId('quantity-now').textContent()) === '1' && (await a.getByTestId('quantity-new').textContent()) === '3')
|
|
await a.getByTestId('quantity-save').click()
|
|
const up = await waitFor(async () => (await api('GET', `/api/orders/${om.id}`, { token: boss })).items.find(i => i.id === first.id)?.quantity === 3, 10_000, 500)
|
|
r.check('6F.5: the line is now 3 (no new line, nothing sent again)', !!up && await count() === 2)
|
|
await openQty()
|
|
await a.getByTestId('quantity-less').click()
|
|
r.check('6F.5: lowering asks about a cancellation ticket', await a.getByTestId('quantity-ticket').isVisible())
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-quantity.png') })
|
|
await a.getByTestId('quantity-save').click()
|
|
const down = await waitFor(async () => {
|
|
const o = await api('GET', `/api/orders/${om.id}`, { token: boss })
|
|
const part = o.items.find(i => i.status === 'cancelled' && i.split_from_id === first.id)
|
|
return o.items.find(i => i.id === first.id)?.quantity === 2 && part?.quantity === 1 && part
|
|
}, 10_000, 500)
|
|
r.check('6F.5: lowered to 2: one cancelled, kept apart ("quantity lowered")', !!down && down.cancel_reason === 'quantity lowered', JSON.stringify(down))
|
|
await setting(boss, 'orders.quantity_change', 'off')
|
|
await api('PUT', `/api/products/${plain.id}`, { token: boss, body: { one_more_enabled: false } })
|
|
await api('PUT', `/api/waiters/${maria.id}/permissions`, { token: boss, body: { keys: mariaKeys } })
|
|
await setting(boss, 'orders.close_with_unpaid', 'true')
|
|
await api('POST', `/api/orders/${om.id}/close`, { token: boss })
|
|
await setting(boss, 'orders.close_with_unpaid', 'false')
|
|
}
|
|
|
|
// ── 6F.6: split the amount: pre-filled from the customers, undo, pay one part ────────
|
|
{
|
|
await setting(boss, 'payments.split_amount', 'multiple_equal')
|
|
const busyNow = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
|
|
const ts = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busyNow.has(x.id))
|
|
const os = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: ts.id } })
|
|
await api('POST', `/api/orders/${os.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }, { product_id: other.id, quantity: 2 }] } })
|
|
await api('PATCH', `/api/orders/${os.id}/customer-count`, { token: tokenA, body: { customer_count: 3 } })
|
|
const get = () => api('GET', `/api/orders/${os.id}`, { token: boss })
|
|
const before = await get()
|
|
const total = Math.round(before.items.reduce((x, i) => x + (i.unit_price + (i.price_adjustment || 0)) * i.quantity, 0) * 100) / 100
|
|
const openSplit = async () => {
|
|
await a.goto(`${APP}/tables/${ts.id}`)
|
|
await a.reload()
|
|
await a.getByTestId('pay-button').click({ timeout: 10_000 })
|
|
await a.getByTestId('pay-split').click({ timeout: 5000 })
|
|
await a.getByTestId('split-sheet').waitFor({ timeout: 5000 })
|
|
}
|
|
await openSplit()
|
|
r.check('6F.6: "Split the amount" starts at the table\'s 3 customers', (await a.getByTestId('split-parts').textContent()) === '3')
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-split.png') })
|
|
await a.getByTestId('split-confirm').click()
|
|
const split3 = await waitFor(async () => { const o = await get(); return o.split_bills?.length === 1 && o }, 10_000, 500)
|
|
const cents = Math.round(total * 100)
|
|
const b3 = Math.floor(cents / 3)
|
|
r.check('6F.6: the lines are settled, three parts appear (the cent on the last)', !!split3
|
|
&& split3.items.filter(i => i.status === 'split').length === 2
|
|
&& JSON.stringify(split3.split_bills[0].amounts) === JSON.stringify([b3 / 100, b3 / 100, (cents - 2 * b3) / 100]), JSON.stringify(split3?.split_bills))
|
|
await a.getByTestId('split-bill').waitFor({ timeout: 10_000 })
|
|
r.check('6F.6: the table shows the split bill and its parts as lines', (await a.locator('.order-item').allTextContents()).filter(x => x.includes('Split bill')).length === 3)
|
|
// undo while nothing is paid
|
|
await a.getByTestId('split-undo').click()
|
|
const undone = await waitFor(async () => { const o = await get(); return o.split_bills?.length === 0 && o }, 10_000, 500)
|
|
r.check('6F.6: Undo: the lines are unpaid again, the parts cancelled', !!undone
|
|
&& undone.items.filter(i => i.status === 'active').length === 2 && undone.items.filter(i => i.cancel_reason === 'split undone').length === 3)
|
|
// split in two, pay one part
|
|
await openSplit()
|
|
await a.getByTestId('split-fewer').click()
|
|
await a.getByTestId('split-confirm').click()
|
|
const split2 = await waitFor(async () => { const o = await get(); return o.split_bills?.length === 1 && o }, 10_000, 500)
|
|
await a.getByTestId('split-bill').waitFor({ timeout: 10_000 })
|
|
const part1 = split2.items.find(i => i.id === split2.split_bills[0].part_ids[0])
|
|
await a.locator('.order-item', { hasText: part1.product_name }).first().click()
|
|
await a.getByTestId('pay-button').click()
|
|
r.check('6F.6: a part can\'t be split again (no "Split the amount")', await a.getByTestId('pay-split').count() === 0)
|
|
await a.getByRole('button', { name: /Paid/ }).last().click()
|
|
const paidOne = await waitFor(async () => { const o = await get(); return o.items.find(i => i.id === part1.id)?.status === 'paid' && o }, 10_000, 500)
|
|
r.check('6F.6: one part paid like any line; Undo is gone', !!paidOne && paidOne.split_bills[0].can_undo === false
|
|
&& await a.getByTestId('split-undo').count() === 0)
|
|
const refused = await fetch(`${backend.url}/api/orders/${os.id}/split-bills/${split2.split_bills[0].id}/undo`, { method: 'POST', headers: { Authorization: `Bearer ${boss}` } })
|
|
r.check('6F.6: undo refused once a part is paid', refused.status === 409)
|
|
await api('POST', `/api/orders/${os.id}/pay`, { token: boss, body: { item_ids: [split2.split_bills[0].part_ids[1]], payment_method: 'card' } })
|
|
await api('POST', `/api/orders/${os.id}/close`, { token: boss }).catch(() => {})
|
|
await setting(boss, 'payments.split_amount', 'off')
|
|
}
|
|
|
|
// ── 4.8: the owner's choices: combine lines, close with unpaid items, seats ─────────
|
|
const t6 = free.find(t => t.id !== t4.id && t.id !== t5.id)
|
|
const o6 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t6.id } })
|
|
for (let i = 0; i < 3; i++) await api('POST', `/api/orders/${o6.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 2 }] } })
|
|
await a.goto(`${APP}/tables/${t6.id}`)
|
|
await a.locator('.order-item').first().waitFor({ timeout: 10_000 })
|
|
for (let i = 0; i < 3; i++) await a.locator('.order-item').nth(i).click()
|
|
await a.getByRole('button', { name: 'ACTIONS', exact: true }).last().click()
|
|
await a.getByText('Combine into one line').click()
|
|
const combined = await waitFor(async () => {
|
|
const o = await api('GET', `/api/orders/${o6.id}`, { token: boss })
|
|
const live = o.items.filter(i => i.status === 'active')
|
|
return live.length === 1 && live[0].quantity === 6 && o
|
|
}, 10_000, 500)
|
|
r.check('4.8: three lines of the same item (2 + 2 + 2) combined into one line of 6', !!combined)
|
|
// closing with an unpaid item: by default the payment comes first; the venue may allow closing
|
|
await a.goto(`${APP}/tables/${t6.id}`)
|
|
await a.getByRole('button', { name: /CLOSE/ }).last().click()
|
|
r.check('4.8: CLOSE with unpaid items asks for the payment first (default)', await a.getByText('Confirm payment and close').isVisible().catch(() => false))
|
|
await a.keyboard.press('Escape').catch(() => {})
|
|
await setting(boss, 'orders.close_with_unpaid', 'true')
|
|
await a.goto(`${APP}/tables/${t6.id}`)
|
|
await a.getByRole('button', { name: /CLOSE/ }).last().click()
|
|
await a.getByTestId('close-confirm').click({ timeout: 10_000 })
|
|
const closed = await waitFor(async () => (await api('GET', `/api/orders/${o6.id}`, { token: boss })).status === 'closed', 10_000, 500)
|
|
r.check('4.8: with "close with unpaid items" on, CLOSE closes and the item stays unpaid', !!closed)
|
|
await setting(boss, 'orders.close_with_unpaid', 'false')
|
|
// a line the guests sent from the QR menu is marked on the phone (the QR flow itself: qr_table.mjs)
|
|
const o7 = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: t6.id } })
|
|
await api('POST', `/api/orders/${o7.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }, { product_id: other.id, quantity: 1 }] } })
|
|
execFileSync(PYTHON, ['-c', `import sqlite3; c = sqlite3.connect(r"${path.join(backend.dataDir, 'pos.db')}"); c.execute("update order_items set source = 'qr' where order_id = ${o7.id} and product_id = ${other.id}"); c.commit()`])
|
|
await a.goto(`${APP}/tables/${t6.id}`)
|
|
r.check("4.8: the QR menu's lines are marked on the waiter's order", await shown(a, 'item-source', 10_000)
|
|
&& await a.getByTestId('item-source').count() === 1 && await a.getByTestId('item-source').getAttribute('data-source') === 'qr')
|
|
await setting(boss, 'orders.close_with_unpaid', 'true')
|
|
await api('POST', `/api/orders/${o7.id}/close`, { token: boss })
|
|
await setting(boss, 'orders.close_with_unpaid', 'false')
|
|
// seats: a suggestion on the card and in the guests dialog
|
|
await api('PUT', `/api/tables/${t6.id}`, { token: boss, body: { seat_count: 4 } })
|
|
await a.goto(`${APP}/tables`)
|
|
r.check("4.8: the table's seats show on its card", await shown(a, 'table-seats', 10_000))
|
|
await a.goto(`${APP}/tables/${t6.id}/add?new=1`)
|
|
await a.getByTitle('Number of guests').click()
|
|
for (let i = 0; i < 6; i++) await a.locator('.qty-btn').last().click()
|
|
r.check('4.8: more guests than seats is allowed, with a hint (not a limit)', await a.getByTestId('seats-hint').getAttribute('data-over') === 'true')
|
|
await a.goto(`${APP}/tables`)
|
|
|
|
// bookings on the phone: a request made online is confirmed and the guests seated (the counter's flow)
|
|
const sqlite = sql => execFileSync(PYTHON, ['-c', `import sqlite3; c = sqlite3.connect(r"${path.join(backend.dataDir, 'pos.db')}"); r = c.execute(${JSON.stringify(sql)}).fetchall(); c.commit(); print(r)`], { encoding: 'utf8' }).trim()
|
|
sqlite("insert into reservations (guest_name, party_size, phone, reserved_for, status, source, online_ref, created_at, updated_at) values ('E2E Guest', 2, '6900000000', datetime('now', '+2 hours'), 'requested', 'online', 'ORD-E2E', datetime('now'), datetime('now'))")
|
|
const waiterRole = await api('GET', '/api/waiters/roles/waiter/permissions', { token: boss })
|
|
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: [...waiterRole.keys, 'connect_orders.manage'] } })
|
|
await a.goto(`${APP}/tables`)
|
|
await a.reload()
|
|
await a.locator('button').filter({ has: a.locator('svg') }).first().click().catch(() => {})
|
|
const drawerHasBookings = await a.getByRole('button', { name: 'Bookings' }).isVisible({ timeout: 5000 }).catch(() => false)
|
|
await a.goto(`${APP}/bookings`)
|
|
const card = () => a.locator('[data-testid="booking-card"]').filter({ hasText: 'E2E Guest' })
|
|
await card().first().waitFor({ timeout: 10_000 }).catch(() => {})
|
|
r.check('4.8: with the online-orders key the phone lists the booking request (drawer: Bookings)', drawerHasBookings && await card().getAttribute('data-status') === 'requested')
|
|
await card().getByTestId('booking-confirm').click()
|
|
await waitFor(async () => await card().getAttribute('data-status') === 'pending', 10_000, 300)
|
|
await card().getByTestId('booking-table').selectOption({ index: 1 })
|
|
await card().getByTestId('booking-arrive').click()
|
|
const seated = await waitFor(async () => /arrived', \d+/.test(sqlite("select status, table_id from reservations where online_ref = 'ORD-E2E'")) && 1, 10_000, 500)
|
|
r.check('4.8: …confirmed and seated at a table from the phone', !!seated, sqlite("select status, table_id from reservations where online_ref = 'ORD-E2E'"))
|
|
await api('PUT', '/api/waiters/roles/waiter/permissions', { token: boss, body: { keys: waiterRole.default_keys } })
|
|
await a.goto(`${APP}/tables`)
|
|
|
|
// ── 6.8: the floor plan on the phone; the list stays the default (D-31) ──
|
|
const liveNow = (await api('GET', '/api/floor-plans/live', { token: tokenA })).tables
|
|
const [fA, fB] = liveNow.filter(t => t.state === 'free')
|
|
const fp = await api('POST', '/api/floor-plans', { token: boss, body: { name: 'E2E floor', group_id: fA.group_id, width: 800, height: 500 } })
|
|
await api('PUT', `/api/floor-plans/${fp.id}/layout`, { token: boss, body: {
|
|
tables: [fA, fB].map((t, i) => ({ id: t.id, x: 200 + i * 300, y: 250, width: 120, height: 90, shape: 'long', seats: 6 })) } })
|
|
await a.getByTestId('tables-map-toggle').waitFor({ timeout: 10_000 })
|
|
r.check('6.8: the Tables page opens on the list', await a.getByTestId('tables-map-toggle').getAttribute('aria-pressed') === 'false' && await a.getByTestId('waiter-floor').count() === 0)
|
|
await a.getByTestId('tables-map-toggle').click()
|
|
const onMap = id => a.locator(`[data-testid="waiter-floor"] [data-testid="floor-table"][data-table="${id}"]`)
|
|
r.check('6.8: Map shows the floor plan with the tables free', await onMap(fA.id).waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
|
&& await onMap(fA.id).getAttribute('data-state') === 'free')
|
|
const oF = await api('POST', '/api/orders/', { token: tokenA, body: { table_id: fA.id } })
|
|
await api('POST', `/api/orders/${oF.id}/items`, { token: tokenA, body: { lines: [{ product_id: plain.id, quantity: 1 }] } })
|
|
r.check('6.8: the waiter opens a table → it turns "yours" on the map at once', await a.waitForFunction(id =>
|
|
document.querySelector(`[data-testid="waiter-floor"] [data-testid="floor-table"][data-table="${id}"]`)?.dataset.state === 'mine', fA.id, { timeout: 8000 }).then(() => true).catch(() => false))
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-floor.png') })
|
|
await onMap(fA.id).click()
|
|
r.check('6.8: a tap opens the table', await a.waitForURL(new RegExp(`/tables/${fA.id}$`), { timeout: 8000 }).then(() => true).catch(() => false))
|
|
await api('DELETE', `/api/orders/${oF.id}`, { token: boss }).catch(() => {})
|
|
await a.goto(`${APP}/tables`)
|
|
await a.getByTestId('tables-map-toggle').waitFor({ timeout: 10_000 })
|
|
r.check("6.8: back on Tables: the list again (the map isn't remembered)", await a.getByTestId('tables-map-toggle').getAttribute('aria-pressed') === 'false')
|
|
|
|
// ── 4.6: the look on the shared tokens: the venue's colour and light / dark reach the phone ──
|
|
const accentOf = () => a.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--x-accent-rgb').trim())
|
|
r.check('4.6: the venue colour (default amber) is on the phone', await a.evaluate(() => document.documentElement.dataset.venueTheme) === 'amber')
|
|
await api('PUT', '/api/settings/venue.theme', { token: boss, body: { value: 'blue' } })
|
|
await a.reload()
|
|
await waitFor(async () => (await a.evaluate(() => document.documentElement.dataset.venueTheme)) === 'blue', 10_000, 300)
|
|
r.check('4.6: Settings → Venue → Colour: blue reaches the phone (its accent turns blue)',
|
|
await a.evaluate(() => document.documentElement.dataset.venueTheme) === 'blue' && (await accentOf()) === '96 165 250', await accentOf())
|
|
await api('PUT', '/api/settings/venue.theme', { token: boss, body: { value: 'amber' } })
|
|
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
|
|
await a.getByRole('button', { name: /Light theme/ }).click()
|
|
const bg = await a.evaluate(() => getComputedStyle(document.body).backgroundColor)
|
|
r.check('4.6: light theme from the menu: the page turns light (tokens)', await a.evaluate(() => document.documentElement.dataset.theme) === 'light' && bg === 'rgb(248, 250, 252)', bg)
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-light.png') })
|
|
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
|
|
await a.getByRole('button', { name: /Dark theme/ }).click()
|
|
await a.reload()
|
|
|
|
// ── 6F.7: "ask" (the default): the second phone asks; Continue signs the first one out and it
|
|
// says why; an order queued offline on the first phone goes out after it signs in again ──
|
|
{
|
|
await setting(boss, 'auth.single_session_waiter', 'ask')
|
|
const busy7 = new Set((await api('GET', '/api/orders/', { token: boss })).map(o => o.table_id))
|
|
const tq = (await api('GET', '/api/tables/', { token: boss })).find(x => x.is_active !== false && !busy7.has(x.id))
|
|
const status7 = async () => (await api('GET', `/api/tables/${tq.id}/status`, { token: boss })).active_order_id
|
|
await a.goto(`${APP}/tables/${tq.id}/add?new=1`)
|
|
await addOn(tq.id, plain)
|
|
await ctxA.setOffline(true)
|
|
await a.getByTestId('cart-open').click()
|
|
await waitFor(async () => (await total().innerText().catch(() => '')).includes('offline'), 30_000, 1000)
|
|
await a.getByRole('button', { name: /^(SEND|SUMMARY)/ }).last().click()
|
|
if (await shown(a, 'summary-total', 3000)) await a.getByRole('button', { name: /SEND/ }).last().click()
|
|
await sleep(1500)
|
|
// the second phone
|
|
await b.reload()
|
|
await b.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
|
|
await pin(b, '3302')
|
|
const asked = await shown(b, 'login-elsewhere', 5000)
|
|
const askText = await b.getByTestId('login-elsewhere').innerText().catch(() => '')
|
|
r.check('6F.7: a second phone asks (where, since when) instead of refusing', asked && /\d\d:\d\d/.test(askText) && !(await tokenOf(b)), askText.replace(/\s+/g, ' '))
|
|
await b.screenshot({ path: path.join(OUT, 'waiter-signed-in-elsewhere.png') })
|
|
await b.getByTestId('login-elsewhere-continue').click()
|
|
await b.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
|
|
r.check('6F.7: Continue signs this phone in', !!(await tokenOf(b)) && await pathOf(b) !== '/login', await pathOf(b))
|
|
// the first phone comes back: signed out, says why, the order still queued
|
|
await ctxA.setOffline(false)
|
|
const outA = await a.waitForURL(u => u.pathname === '/login', { timeout: 45_000 }).then(() => true).catch(() => false)
|
|
const noteA = await a.getByTestId('signed-out-note').innerText({ timeout: 10_000 }).catch(() => '')
|
|
r.check('6F.7: the first phone, back online, is signed out and says why', outA && /another device|άλλη συσκευή/.test(noteA), noteA)
|
|
await a.screenshot({ path: path.join(OUT, 'waiter-signed-out-replaced.png') })
|
|
r.check('6F.7: its order queued offline was not sent with the ended session', !(await status7()))
|
|
// it signs in again (asks: the second phone now); the second phone leaves at once (live)
|
|
await a.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
|
|
await pin(a, '3302')
|
|
await a.getByTestId('login-elsewhere-continue').click({ timeout: 5000 })
|
|
await a.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
|
|
const outB = await b.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).then(() => true).catch(() => false)
|
|
const noteB = await b.getByTestId('signed-out-note').innerText({ timeout: 5000 }).catch(() => '')
|
|
r.check('6F.7: the other phone is signed out at once (live) and says why', outB && /another device|άλλη συσκευή/.test(noteB), noteB)
|
|
const flushed = await waitFor(status7, 30_000, 1000)
|
|
r.check('6F.7: …and the order queued offline goes out after signing in again', !!flushed)
|
|
if (flushed) await api('DELETE', `/api/orders/${flushed}`, { token: boss }).catch(() => {})
|
|
await a.goto(`${APP}/tables`)
|
|
}
|
|
|
|
// ── Signing out ends the session on the server: the second phone can sign in ─
|
|
await a.getByRole('button', { name: 'demo_maria' }).first().click({ timeout: 10_000 })
|
|
await a.getByRole('button', { name: /Sign out/ }).last().click()
|
|
await a.waitForURL(u => u.pathname === '/login', { timeout: 10_000 }).catch(() => {})
|
|
await sleep(1000)
|
|
const after = await api('GET', '/api/auth/sessions', { token: boss })
|
|
r.check('sign-out ends the session on the server', !after.some(s => s.username === 'demo_maria' && s.client === 'waiter'))
|
|
await b.reload()
|
|
await b.getByTestId('waiter-card').filter({ hasText: 'Κωνσταντίνου' }).click({ timeout: 10_000 })
|
|
await pin(b, '3302')
|
|
await b.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
|
|
r.check('…and then the second phone signs in', !!(await tokenOf(b)) && await pathOf(b) !== '/login', await pathOf(b))
|
|
|
|
// ── Auto-lock and idle sign-out follow the venue's settings ────────────────
|
|
await setting(boss, 'security.auto_lock', 'true')
|
|
await setting(boss, 'security.auto_lock_seconds', '3')
|
|
await setting(boss, 'security.auto_logout', 'true')
|
|
await setting(boss, 'security.auto_logout_seconds', '9')
|
|
await b.reload()
|
|
r.check('idle past auto_lock_seconds: the phone locks by itself', await shown(b, 'lock-screen', 10_000))
|
|
r.check('idle past auto_logout_seconds: signed out', await b.waitForURL(u => u.pathname === '/login', { timeout: 15_000 }).then(() => true).catch(() => false)
|
|
&& !(await tokenOf(b)))
|
|
await setting(boss, 'security.auto_lock', 'false')
|
|
await setting(boss, 'security.auto_logout', 'false')
|
|
await ctxA.close(); await ctxB.close()
|
|
|
|
// ── Username + password mode ───────────────────────────────────────────────
|
|
await setting(boss, 'auth.waiter_login_mode', 'password')
|
|
await setting(boss, 'auth.waiter_require_username', 'true')
|
|
const ctxC = await phone()
|
|
const c = await open(ctxC)
|
|
r.check('password mode with username: a username field and a password field',
|
|
await shown(c, 'login-username') && await shown(c, 'login-password') && await c.getByTestId('waiter-card').count() === 0)
|
|
await c.getByTestId('login-username').fill('manager')
|
|
await c.getByTestId('login-password').fill('wrong-one')
|
|
await c.getByTestId('login-submit').click()
|
|
r.check('wrong password: a message', await shown(c, 'login-error', 5000), await c.getByTestId('login-error').textContent().catch(() => ''))
|
|
await c.getByTestId('login-password').fill('password')
|
|
await c.getByTestId('login-submit').click()
|
|
await c.waitForURL(u => u.pathname !== '/login', { timeout: 10_000 }).catch(() => {})
|
|
r.check('right password: signed in', !!(await tokenOf(c)) && await pathOf(c) !== '/login', await pathOf(c))
|
|
await ctxC.close()
|
|
|
|
// ── Tap mode: phones say so instead of offering a sign-in ──────────────────
|
|
await setting(boss, 'auth.waiter_login_mode', 'tap')
|
|
await setting(boss, 'auth.waiter_require_username', 'false')
|
|
const ctxD = await phone()
|
|
const d = await open(ctxD)
|
|
r.check('tap mode: the phone explains that sign-in is on the paired screens', await shown(d, 'login-tap-only'))
|
|
await d.screenshot({ path: path.join(OUT, 'waiter-tap-only.png') })
|
|
await ctxD.close()
|
|
await setting(boss, 'auth.waiter_login_mode', 'pin')
|
|
|
|
r.check('no page errors', errors.length === 0, errors.join(' | '))
|
|
failures += r.done()
|
|
} catch (e) {
|
|
console.error(e)
|
|
failures += 1 + r.done()
|
|
} finally {
|
|
await browser.close()
|
|
vite.stop()
|
|
await backend.stop()
|
|
}
|
|
process.exit(failures ? 1 : 0)
|