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 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 10:04:43 +02:00
co-authored by Claude Opus 5.5
parent 2426ffddad
commit eb22997f8e
2 changed files with 66 additions and 1 deletions
+65
View File
@@ -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()