feat: delivery areas and fee rules with "test an order" (platform-v2 3S, S.3)

- models/fees.py + Alembic 0018: delivery_areas, fee_rules; key connect_orders.fees
  (owner, store manager; existing ones get it).
- services/fees.py: the pure engine (set / add / % / free / minimum, conditions: sales
  points, areas, products total, item count, days, time incl. past midnight, stop), the
  same file as the cloud's; tests/fixtures/fee_cases.json shared, plus a test that the
  cloud copy is identical.
- routers/fees.py at /api/connect/fees: areas and rules CRUD (validated), order, preview.
- Snapshot carries fees + the venue's time zone; a change to products, pricing or fees
  pushes the menu within ~5 s (middleware -> cloud_sync.request_menu_push).
- Manager: Online -> Delivery fees page (@xenia/ui): rules in order with words for each,
  areas with postcodes, "Test an order"; en/el texts; feesLogic.js unit-tested.
- Tests: test_fees.py (39), manager unit +5, manager.mjs +7 on the real page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 12:28:29 +02:00
co-authored by Claude Opus 5.5
parent ffeb2b45cb
commit 9bfe54554d
24 changed files with 1723 additions and 9 deletions
+51
View File
@@ -513,6 +513,57 @@ try {
r.check('online orders: loads its lists and never asks for the old /api/stream',
ooUrls.some(u => u.startsWith('/api/connect/orders')) && !ooUrls.some(u => u.startsWith('/api/stream')), [...new Set(ooUrls)].filter(u => u.startsWith('/api/')).join(' '))
// ── phase 3S S.3: delivery areas and fees, set up and tested on the real page ──
await page.goto(`${APP}/online/fees`)
r.check('fees: the page opens from the nav entry, no rules yet', await page.getByTestId('fees-page').waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
&& await page.locator('a[href="/online/fees"]').count() >= 1 && await page.getByTestId('rule').count() === 0)
await page.getByTestId('area-add').click()
await page.getByTestId('area-name').fill('Centre')
await page.getByTestId('area-postcodes').fill('24100, 241 31')
await page.getByTestId('area-save').click()
r.check('fees: an area with postcodes', await page.getByTestId('area').filter({ hasText: 'Centre' }).waitFor({ timeout: 5000 }).then(() => true).catch(() => false)
&& (await page.getByTestId('area').first().textContent()).includes('241 31'))
const addRule = async (name, fill) => {
await page.getByTestId('rule-add').click()
await page.getByTestId('rule-name').fill(name)
await fill()
await page.getByTestId('rule-save').click()
await page.getByTestId('rule').filter({ hasText: name }).waitFor({ timeout: 5000 }).catch(() => {})
}
await addRule('Base', () => page.getByTestId('rule-value').fill('2'))
await addRule('Free over 25', async () => {
await page.getByTestId('rule-action').selectOption('free')
await page.getByTestId('rule-subtotal-min').fill('25')
await page.getByRole('switch', { name: 'Stop here' }).click()
})
await page.getByTestId('rule').filter({ hasText: 'Free over 25' }).getByRole('button', { name: 'Move up' }).click()
await page.waitForFunction(() => document.querySelector('[data-testid="rule"]')?.textContent.includes('Free over 25'), null, { timeout: 5000 }).catch(() => {})
r.check('fees: rules added and put in order (free over 25 first, it stops)', (await page.getByTestId('rule').first().textContent()).includes('Free over 25')
&& (await page.getByTestId('rule').first().textContent()).includes('stop here'))
const testFee = async (subtotal) => {
await page.getByTestId('test-subtotal').fill(String(subtotal))
await page.getByTestId('test-run').click()
await page.waitForFunction(st => document.querySelector('[data-testid="test-result"]') && document.querySelector('[data-testid="test-subtotal"]').value === st,
String(subtotal), { timeout: 5000 }).catch(() => {})
await sleep(300)
return page.getByTestId('test-result')
}
let res = await testFee(15)
r.check('fees: "test an order" for €15 in Centre → €2.00', await res.getAttribute('data-fee') === '2' && await res.getAttribute('data-refused') === ''
&& (await res.textContent()).includes('Base') && (await res.textContent()).includes('Centre'),
await res.textContent())
res = await testFee(30)
r.check('fees: …for €30 → free, the first rule stopped the rest', await res.getAttribute('data-fee') === '0' && await res.getAttribute('data-refused') === ''
&& (await res.textContent()).includes('Free over 25') && !(await res.textContent()).includes('Base'),
await res.textContent())
await page.getByTestId('test-subtotal').fill('8')
await page.getByRole('combobox', { name: 'Where' }).selectOption('postcode')
await page.getByTestId('test-postcode').fill('10431')
await page.getByTestId('test-run').click()
await page.waitForFunction(() => document.querySelector('[data-testid="test-result"]')?.dataset.refused, null, { timeout: 5000 }).catch(() => {})
r.check('fees: …a postcode outside the areas is refused', await page.getByTestId('test-result').getAttribute('data-refused') === 'area_not_served')
await page.screenshot({ path: path.join(OUT, 'manager-fees.png'), fullPage: true })
await page.goto(`${APP}/settings`)
await page.getByText('Sign-in & security', { exact: true }).click()
const waiterMode = page.getByTestId('setting-auth.waiter_login_mode')