From eb22997f8e0b8b2506d33112ee31b2d6f1b76a88 Mon Sep 17 00:00:00 2001 From: bonamin Date: Sat, 14 Nov 2026 10:04:43 +0200 Subject: [PATCH] test(e2e): owner flow end to end (platform-v2 2.6g) manager.mjs: sign in -> KDS on from its Apps card -> pair a screen on the Devices page (device side via the API) -> the chef is refused, then gets kds.access + kds.bump in the permission editor -> signs in on that screen with their PIN and reads /api/kds/orders -> listed under "Signed in now". 87 checks. Co-Authored-By: Claude Opus 5.5 --- tests/e2e/README.md | 2 +- tests/e2e/manager.mjs | 65 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/e2e/README.md b/tests/e2e/README.md index 5b650a6..ac61f08 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -41,7 +41,7 @@ Or run one suite at a time: | `node install.mjs` | `install.sh`: VPN-safe `HOST_IP` detection (simulated WireGuard/WiFi hosts); fresh install, upgrade, re-run; proxy config identical to `nginx-proxy/nginx.conf` | Docker | ~1 min | | `python license_e2e.py` | Offline licensing with a real cloud + site process: 400 days offline, tampered file, clock set back, expiry deferred to workday close, renewal, remote lock | Python deps of both backends | ~2 min | | `node ui.mjs` | `@xenia/ui` components on the dev-only gallery (`/ui-gallery`, manager Vite :5185): dialog focus/Escape/backdrop, sheet, toasts, field wiring, switch, InfoTip, PinPad, themes; `@xenia/i18n` on `/i18n-sample` with the browser in New York: venue time, live language switch, el/en money and numbers, price input, translated component labels | Edge | ~40 s | -| `node manager.mjs` | Manager on `@xenia/api`/`@xenia/access` (backend :8057 on a demo DB, manager Vite :5186): bootstrap before/after login, wrong password and wrong lock PIN stay on screen, sidebar from keys, KDS module off → "turned off" screen, session ended elsewhere → /login, a waiter's cancel approved by a manager PIN (wrong PIN first) and audited; Apps, Integrations, License, Devices (pairing played through the API); the approvals log, "Signed in now" + end session, the staff permission editor (give, reset to role, a staff manager can't give what they lack); the notification bell (live, read, read all), sign-in/venue/print settings, log download | Edge | ~1 min | +| `node manager.mjs` | Manager on `@xenia/api`/`@xenia/access` (backend :8057 on a demo DB, manager Vite :5186): bootstrap before/after login, wrong password and wrong lock PIN stay on screen, sidebar from keys, KDS module off → "turned off" screen, session ended elsewhere → /login, a waiter's cancel approved by a manager PIN (wrong PIN first) and audited; Apps, Integrations, License, Devices (pairing played through the API); the approvals log, "Signed in now" + end session, the staff permission editor (give, reset to role, a staff manager can't give what they lack); the notification bell (live, read, read all), sign-in/venue/print settings, log download; the **owner flow** (sign in → turn on KDS → pair a screen → give a chef the kitchen permissions → the chef signs in on that screen) | Edge | ~1 min | | `node browser.mjs` | Waiter web modes (same-origin, plain HTTP by LAN IP, venue mode), install dialog + drawer entry (Android / iPhone / desktop / no APK) | Docker, Edge | ~2 min | | `node android.mjs basics` | Pairing, wrong address / other venue's QR, login + live WS, back button, restart, two venues, camera permission | Android emulator | ~5 min | | `node android.mjs rediscovery` | Server IP change (logged in / out), server down + manual search, cold start while offline | Android emulator | ~4 min | diff --git a/tests/e2e/manager.mjs b/tests/e2e/manager.mjs index 8ce0386..3e6684f 100644 --- a/tests/e2e/manager.mjs +++ b/tests/e2e/manager.mjs @@ -516,6 +516,71 @@ try { await s2.getByText('Printer history').or(s2.getByText('Ιστορικό Εκτυπωτή')).first().waitFor({ timeout: 10_000 }).catch(() => {}) r.check('logs: a staff manager has no "Log files" tab (owner-level)', await s2.getByText('Log files', { exact: true }).count() === 0) + // ── 2.6g: the owner flow (plan step 2.6 "done when") ─────────────────────── + // log in → enable KDS → pair a device → give a chef kds.access → the chef logs in on it. + // The device's side is played through the API until the terminal app exists (phase 3). + const ownerFlow = 'owner flow:' + await api('PUT', '/api/platform/modules/kds', { token: boss, body: { enabled: false } }) // start with KDS off + const chef = await api('POST', '/api/waiters/', { token: boss, body: { username: 'e2e_chef', full_name: 'Kostas Chef', pin: '4747', role: 'custom', is_active: true } }) + const o = await (await browser.newContext({ viewport: { width: 1400, height: 900 } })).newPage() + o.on('pageerror', e => errors.push(e.message)) + // 1. log in + await uiLogin(o, 'password') + await o.waitForURL(u => u.pathname === '/dashboard', { timeout: 15_000 }).catch(() => {}) + r.check(`${ownerFlow} 1. the owner signs in`, new URL(o.url()).pathname === '/dashboard', o.url()) + // 2. enable KDS on the Apps page + await o.goto(`${APP}/apps`) + const kdsCard = o.getByTestId('module-kds') + await kdsCard.waitFor({ timeout: 10_000 }) + const offBefore = await kdsCard.getAttribute('data-state') + await kdsCard.getByRole('switch').click() + await o.waitForFunction(() => document.querySelector('[data-testid="module-kds"]')?.getAttribute('data-state') === 'on', null, { timeout: 8000 }).catch(() => {}) + r.check(`${ownerFlow} 2. KDS turned on from its card`, offBefore === 'off' && await kdsCard.getAttribute('data-state') === 'on') + // 3. the screen shows a code; the owner pairs it on the Devices page + const kitchenReq = await deviceRequestsPairing() + await o.goto(`${APP}/devices`) + await o.getByTestId('device-usage').waitFor({ timeout: 10_000 }) + await o.getByRole('button', { name: 'Pair a device' }).first().click() + const odlg = o.getByRole('dialog') + await odlg.getByLabel('Code shown on the device').fill(kitchenReq.code) + await odlg.getByLabel('App to run').selectOption('kds') + await odlg.getByLabel('Name').fill('Kitchen pass') + await odlg.getByLabel('How staff sign in').selectOption('pin') + await odlg.getByRole('button', { name: 'Pair a device' }).click() + await odlg.waitFor({ state: 'detached', timeout: 8000 }).catch(() => {}) + const kitchenToken = await devicePicksUpToken(kitchenReq) + const kitchenMe = await asDevice(kitchenToken, '/api/devices/me').then(x => x.json()) + r.check(`${ownerFlow} 3. the screen is paired as "Kitchen pass", a kitchen display with PIN sign-in`, + kitchenMe.app_key === 'kds' && kitchenMe.name === 'Kitchen pass' && kitchenMe.login_mode === 'pin', JSON.stringify(kitchenMe)) + const chefOnDevice = () => fetch(`${backend.url}/api/auth/login`, { + method: 'POST', headers: { 'content-type': 'application/json', 'X-Xenia-Device': kitchenToken }, + body: JSON.stringify({ client: 'terminal', user_id: chef.id, pin: '4747' }), + }) + const refused = await chefOnDevice() + r.check(`${ownerFlow} …before the permission, the chef is refused on that screen`, + refused.status === 403 && (await refused.json()).error.code === 'auth.client_not_allowed') + // 4. give the chef the kitchen permissions in the editor + await o.goto(`${APP}/management/staff`) + await o.getByTestId(`staff-perms-${chef.id}`).getByRole('button').click() + await o.getByTestId('perm-editor').waitFor({ timeout: 10_000 }) + await o.getByTestId('perm-kds.access').getByRole('switch').click() + await o.getByTestId('perm-kds.bump').getByRole('switch').click() + await o.getByRole('button', { name: 'Save 2 changes' }).click() + await o.getByTestId('perm-editor').waitFor({ state: 'detached', timeout: 8000 }).catch(() => {}) + const chefKeys = (await api('GET', `/api/waiters/${chef.id}/permissions`, { token: boss })).keys + r.check(`${ownerFlow} 4. the chef now has kds.access and kds.bump`, chefKeys.includes('kds.access') && chefKeys.includes('kds.bump'), JSON.stringify(chefKeys)) + // 5. the chef signs in on the kitchen screen with their PIN + const chefLogin = await chefOnDevice() + const chefSession = chefLogin.status === 200 ? (await chefLogin.json()).access_token : null + const kdsOrders = chefSession && await fetch(`${backend.url}/api/kds/orders`, { headers: { authorization: `Bearer ${chefSession}`, 'X-Xenia-Device': kitchenToken } }) + r.check(`${ownerFlow} 5. the chef signs in on that screen and sees the kitchen orders`, !!chefSession && kdsOrders.status === 200, String(chefLogin.status)) + await o.goto(`${APP}/management/sessions`) + const chefRow = o.locator(`[data-user="${chef.id}"][data-client="terminal"]`) + await chefRow.waitFor({ timeout: 10_000 }).catch(() => {}) + r.check(`${ownerFlow} …and the owner sees them under "Signed in now" on "Kitchen pass · Kitchen display"`, + (await chefRow.textContent().catch(() => '')).includes('Kitchen pass · Kitchen display')) + await o.screenshot({ path: path.join(OUT, 'manager-owner-flow.png'), fullPage: true }) + r.check('no page errors', errors.length === 0, errors.slice(0, 3).join(' | ')) } finally { await browser.close()