feat: pricing on v2 (platform-v2 step 6.7)
- manager src/pages/pricing: price rules, price groups, deals, discounts on the tokens, English and Greek; the rules as data in pricingLogic.js (tests/pricing.test.mjs) - routers/pricing: set-up needs pricing.manage, broadcasts pricing.changed; incomplete conditions refused (pricing.bad_condition); venue discount settings saved again (the date-as-text bug) with empty = no limit (pricing.bad_limit), old "None" tolerated - nav: Offers & pricing needs pricing.manage - tests: test_pricing_setup.py (a happy-hour rule prices a counter quote), manager.mjs e2e Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -903,6 +903,56 @@ try {
|
||||
JSON.stringify(orderB2))
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-products.png') })
|
||||
|
||||
// ── 6.7: pricing — a happy-hour rule made on the page prices a counter sale ──
|
||||
const pg = 'pricing:'
|
||||
const plain = (await api('GET', '/api/products/?all=true', { token: boss }))
|
||||
.find(p => p.lifecycle_status === 'active' && !p.is_service_item && !(p.preference_sets?.length) && p.base_price >= 2)
|
||||
const quote = async () => (await api('POST', '/api/pos/quote', { token: boss, body: { order_type: 'here', lines: [{ product_id: plain.id, quantity: 1 }] } })).lines[0].unit_price
|
||||
const basePrice = await quote()
|
||||
await page.goto(`${APP}/management/pricing`)
|
||||
await page.getByTestId('pricing-rules').waitFor({ timeout: 15_000 })
|
||||
await page.getByTestId('pricing-rule-new').click()
|
||||
await page.getByTestId('pricing-name').fill('E2E happy hour')
|
||||
await page.getByTestId('pricing-target').first().locator('select').selectOption('item')
|
||||
await page.getByTestId('pricing-target-products').getByRole('textbox').fill(plain.name).catch(() => {})
|
||||
await page.locator(`[data-testid="pricing-target-products"] [role="checkbox"][data-name="${plain.name}"]`).first().click()
|
||||
await page.getByTestId('pricing-rule-page-when').click()
|
||||
await page.getByTestId('pricing-condition-add').click()
|
||||
await page.getByTestId('pricing-cond-from').fill('00:00')
|
||||
await page.getByTestId('pricing-cond-to').fill('23:59')
|
||||
await page.getByTestId('pricing-rule-page-price').click()
|
||||
await page.getByTestId('pricing-rule-value').fill('-20')
|
||||
const example = await page.getByTestId('pricing-rule-example').textContent().catch(() => '')
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-pricing-rule.png') })
|
||||
await page.getByTestId('pricing-save').click()
|
||||
const ruleRow = page.locator('[data-testid="pricing-rule"][data-name="E2E happy hour"]')
|
||||
r.check(`${pg} a new price rule (one product, all day, −20%) shows in the list`, await ruleRow.waitFor({ timeout: 10_000 }).then(() => true).catch(() => false)
|
||||
&& (await ruleRow.getByTestId('pricing-rule-action').textContent()).includes('20%'), example)
|
||||
const expected = Math.round(Math.round(basePrice * 0.8 / 0.1) * 0.1 * 100) / 100
|
||||
const discounted = await quote()
|
||||
r.check(`${pg} the done-when: the counter prices the product with it (${basePrice} → ${expected})`, discounted === expected, String(discounted))
|
||||
await ruleRow.getByTestId('pricing-toggle').click()
|
||||
await page.locator('[data-testid="pricing-rule"][data-name="E2E happy hour"][data-active="false"]').waitFor({ timeout: 8000 }).catch(() => {})
|
||||
r.check(`${pg} turned off: back to the menu price`, await quote() === basePrice)
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-pricing.png') })
|
||||
// a price group with a schedule; the venue's discount limit
|
||||
await page.getByTestId('pricing-tab-groups').click()
|
||||
await page.getByTestId('pricing-group-new').click()
|
||||
await page.getByTestId('pricing-name').fill('E2E summer')
|
||||
await page.getByTestId('pricing-save').click()
|
||||
r.check(`${pg} a price group is made`, await page.locator('[data-testid="pricing-group"][data-name="E2E summer"]').waitFor({ timeout: 8000 }).then(() => true).catch(() => false))
|
||||
await page.getByTestId('pricing-tab-discounts').click()
|
||||
await page.getByTestId('limit-max_total_value_workday').first().fill('50,5')
|
||||
await page.getByTestId('pricing-venue-save').click()
|
||||
let limits = null
|
||||
for (let i = 0; i < 20 && limits?.max_total_value_workday !== 50.5; i++) { await sleep(250); limits = await api('GET', '/api/pricing/discount-settings/global', { token: boss }) }
|
||||
r.check(`${pg} the venue's discount limit "50,5" is saved as 50.5`, limits?.max_total_value_workday === 50.5, JSON.stringify(limits))
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-pricing-discounts.png') })
|
||||
await page.getByTestId('limit-max_total_value_workday').first().fill('')
|
||||
await page.getByTestId('pricing-venue-save').click()
|
||||
for (let i = 0; i < 20 && limits?.max_total_value_workday !== null; i++) { await sleep(250); limits = await api('GET', '/api/pricing/discount-settings/global', { token: boss }) }
|
||||
r.check(`${pg} emptied: no limit`, limits?.max_total_value_workday === null, JSON.stringify(limits))
|
||||
|
||||
await api('PUT', '/api/platform/modules/connect_orders', { token: boss, body: { enabled: true } })
|
||||
await page.goto(`${APP}/online-orders`)
|
||||
await page.getByTestId('online-orders').waitFor({ timeout: 10_000 }).catch(() => {})
|
||||
|
||||
Reference in New Issue
Block a user