feat: delivery areas drawn on a map (plan 6R.G)
An area is a list of postcodes, a shape drawn on a map or a circle around a point. The fee engine (both copies, byte-identical) matches a shape only by the customer's pin, then postcodes; point-in-polygon (edges inside) and haversine circles; shared cases in fee_cases.json. - Alembic 0053: delivery_areas.kind / geometry, orders.online_lat / lng - /api/connect/fees: areas with kind + geometry (validated: 3-200 corners, 50 m - 50 km), the venue's place (PUT /venue-point, setting venue.location, sent to the cloud as fees.venue_point), preview by lat / lng - manager: DeliveryMap (Leaflet + OpenStreetMap tiles): draw / move / remove corners, circles, the venue on the map, an overview, test an order by a point - pulled online orders keep the pin; the site re-checks the fee with it; the counter links the pin to a map - tests: backend (shapes, venue point, pinned orders), manager logic, e2e manager.mjs and order_app.mjs 6R.G blocks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -578,6 +578,72 @@ try {
|
||||
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')
|
||||
// ── 6R.G: the venue on the map, an area drawn on it, a circle, "test an order" by a point ──
|
||||
{
|
||||
await page.getByTestId('fees-tab-areas').click()
|
||||
await page.getByTestId('venue-edit').click()
|
||||
const vmap = page.getByTestId('venue-map')
|
||||
await vmap.waitFor({ timeout: 5000 })
|
||||
const vb = await vmap.boundingBox()
|
||||
await vmap.click({ position: { x: vb.width / 2, y: vb.height / 2 } })
|
||||
await page.getByTestId('venue-save').click()
|
||||
let venuePoint = null
|
||||
for (let i = 0; i < 30 && !venuePoint; i++) { venuePoint = (await api('GET', '/api/connect/fees', { token: boss })).venue_point; if (!venuePoint) await sleep(150) }
|
||||
r.check('6R.G: the venue\'s place set by a tap on the map', !!venuePoint && Math.abs(venuePoint.lat) > 1, JSON.stringify(venuePoint))
|
||||
// a shape: four taps, then a tap on the last corner takes it away
|
||||
await page.getByTestId('area-add').click()
|
||||
await page.getByTestId('area-name').fill('Drawn')
|
||||
await page.getByTestId('area-kind-polygon').click()
|
||||
const dmap = page.getByTestId('delivery-map')
|
||||
await dmap.waitFor({ timeout: 5000 })
|
||||
await sleep(500)
|
||||
const db = await dmap.boundingBox()
|
||||
const cx = db.width / 2, cy = db.height / 2
|
||||
for (const [dx, dy] of [[-150, -100], [150, -100], [0, 120], [120, 110]]) {
|
||||
await dmap.click({ position: { x: cx + dx, y: cy + dy } })
|
||||
await sleep(150)
|
||||
}
|
||||
const four = await dmap.getAttribute('data-count')
|
||||
await dmap.click({ position: { x: cx + 120, y: cy + 110 } }) // the 4th corner: removed
|
||||
await sleep(200)
|
||||
r.check('6R.G: corners added by taps on the map, one taken away by a tap on it', four === '4' && await dmap.getAttribute('data-count') === '3',
|
||||
`${four} → ${await dmap.getAttribute('data-count')}`)
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-area-drawn.png') })
|
||||
await page.getByTestId('area-save').click()
|
||||
await page.getByTestId('area').filter({ hasText: 'Drawn' }).waitFor({ timeout: 5000 }).catch(() => {})
|
||||
// a circle around the venue (its centre starts there), 1.5 km
|
||||
await page.getByTestId('area-add').click()
|
||||
await page.getByTestId('area-name').fill('Ring')
|
||||
await page.getByTestId('area-kind-circle').click()
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-area-circle.png') })
|
||||
await page.getByTestId('area-radius').fill('1500')
|
||||
await page.getByTestId('area-save').click()
|
||||
await page.getByTestId('area').filter({ hasText: 'Ring' }).waitFor({ timeout: 5000 }).catch(() => {})
|
||||
const areasNow = (await api('GET', '/api/connect/fees', { token: boss })).areas
|
||||
const drawnA = areasNow.find(a => a.name === 'Drawn'), ring = areasNow.find(a => a.name === 'Ring')
|
||||
r.check('6R.G: saved as a shape with 3 corners and a 1.5 km circle around the venue',
|
||||
drawnA?.kind === 'polygon' && drawnA.geometry.length === 3 && ring?.kind === 'circle' && ring.geometry.radius_m === 1500
|
||||
&& ring.geometry.center[0] === venuePoint.lat && ring.geometry.center[1] === venuePoint.lng, JSON.stringify([drawnA, ring]))
|
||||
r.check('6R.G: the list says what each area is', (await page.getByTestId('area').filter({ hasText: 'Drawn' }).textContent()).includes('3 corners')
|
||||
&& (await page.getByTestId('area').filter({ hasText: 'Ring' }).textContent()).includes('1.5 km') && await page.getByTestId('areas-map').count() === 1)
|
||||
// "test an order" by a point: the middle of the map is inside the drawn shape (the first shape wins)
|
||||
await page.getByTestId('test-subtotal').fill('15')
|
||||
await page.getByRole('combobox', { name: 'Where' }).selectOption('point')
|
||||
const tmap = page.getByTestId('test-map')
|
||||
await tmap.waitFor({ timeout: 5000 })
|
||||
await sleep(500)
|
||||
const tb = await tmap.boundingBox()
|
||||
await tmap.click({ position: { x: tb.width / 2, y: tb.height / 2 } })
|
||||
await page.getByTestId('test-run').click()
|
||||
await page.waitForFunction(() => document.querySelector('[data-testid="test-result"]')?.textContent.includes('Drawn'), null, { timeout: 5000 }).catch(() => {})
|
||||
const tr = page.getByTestId('test-result')
|
||||
r.check('6R.G: "test an order" by a point on the map finds the drawn area and its fee', (await tr.textContent()).includes('Drawn')
|
||||
&& await tr.getAttribute('data-refused') === '' && await tr.getAttribute('data-fee') === '2', await tr.textContent())
|
||||
await page.screenshot({ path: path.join(OUT, 'manager-test-point.png') })
|
||||
for (const a of [drawnA, ring]) if (a) await api('DELETE', `/api/connect/fees/areas/${a.id}`, { token: boss }).catch(() => {})
|
||||
await page.reload()
|
||||
await page.getByTestId('fees-page').waitFor({ timeout: 10_000 })
|
||||
}
|
||||
// S.5: the fee's line on the bill and the receipt (a system product, never in the catalogue)
|
||||
await page.getByTestId('fees-tab-settings').click()
|
||||
await page.getByTestId('fee-product-name').fill('Delivery')
|
||||
|
||||
@@ -208,6 +208,48 @@ try {
|
||||
.then(() => true).catch(() => false) && (await page.getByTestId('track').textContent()).includes('Confirmed'))
|
||||
await page.screenshot({ path: path.join(OUT, 'order-app-booking-track.png'), fullPage: true })
|
||||
|
||||
// ── 6R.G: the venue drew an area on the map: the customer pins the address ──
|
||||
{
|
||||
const shaped = { ...snapshot, fees: { ...snapshot.fees,
|
||||
areas: [...snapshot.fees.areas, { id: 3, name: 'Harbour', kind: 'circle', postcodes: [], is_active: true, geometry: { center: [37.0, 22.0], radius_m: 3000 } }],
|
||||
rules: [...snapshot.fees.rules, { id: 4, name: 'Harbour', area_ids: [3], action: 'add', value: 0.5, sales_points: ['online_delivery'] }],
|
||||
venue_point: { lat: 37.0, lng: 22.0 } } }
|
||||
await call('POST', '/api/menu/sync', { headers: siteH, body: { site_id: numeric, snapshot_json: JSON.stringify(shaped) } })
|
||||
const ctx = await browser.newContext({ viewport: { width: 390, height: 844 }, locale: 'en-GB',
|
||||
geolocation: { latitude: 37.004, longitude: 22.003 }, permissions: ['geolocation'] })
|
||||
const pg = await ctx.newPage()
|
||||
pg.on('pageerror', e => errors.push(e.message))
|
||||
const prod = id => pg.locator(`[data-testid="product"][data-product="${id}"]`).first()
|
||||
await pg.goto(`http://localhost:${APP_PORT}/order/${site.site_id}`)
|
||||
await pg.getByTestId('service-delivery').click()
|
||||
await prod(11).getByTestId('add').click()
|
||||
await pg.getByTestId('extras-add').click()
|
||||
await prod(12).getByTestId('add').click() // €7.00 of products
|
||||
await pg.getByTestId('view-order').click()
|
||||
const map = pg.getByTestId('pin-map')
|
||||
r.check('6R.G: with an area drawn by the venue, the checkout opens on the map', await map.waitFor({ timeout: 8000 }).then(() => true).catch(() => false)
|
||||
&& await pg.getByTestId('where-map').getAttribute('aria-checked') === 'true' && await pg.getByTestId('where-area').count() === 1)
|
||||
await sleep(500)
|
||||
const mb = await map.boundingBox()
|
||||
await map.click({ position: { x: mb.width / 2, y: mb.height / 2 } }) // the middle of the venue's circle
|
||||
await pg.waitForFunction(() => document.querySelector('[data-testid="totals"]')?.dataset.fee === '2.5', null, { timeout: 8000 }).catch(() => {})
|
||||
r.check('6R.G: a tap on the map pins it; the cloud finds the area and its fee (€2.00 + €0.50)', await map.getAttribute('data-pinned') === 'true'
|
||||
&& await pg.getByTestId('totals').getAttribute('data-fee') === '2.5' && (await pg.getByTestId('totals').textContent()).includes('Harbour'),
|
||||
await pg.getByTestId('totals').textContent())
|
||||
await pg.getByTestId('locate').click() // the browser's location (allowed here)
|
||||
await sleep(800)
|
||||
await pg.getByTestId('f-name').fill('Eleni')
|
||||
await pg.getByTestId('f-phone').fill('6922222222')
|
||||
await pg.getByTestId('f-address').fill('Harbour road 12')
|
||||
await pg.screenshot({ path: path.join(OUT, 'order-app-pin.png'), fullPage: true })
|
||||
await pg.getByTestId('place-order').click()
|
||||
await pg.getByTestId('track').waitFor({ timeout: 10_000 }).catch(() => {})
|
||||
const got = (await call('GET', `/api/orders/pending/${numeric}`, { headers: siteH })).find(o => o.customer_name === 'Eleni')
|
||||
r.check('6R.G: placed with the pin from the browser\'s location; the site gets the area, the fee and the pin',
|
||||
got?.delivery_area === 'Harbour' && got.delivery_fee === 2.5 && got.lat === 37.004 && got.lng === 22.003, JSON.stringify(got && { a: got.delivery_area, f: got.delivery_fee, lat: got.lat, lng: got.lng }))
|
||||
await ctx.close()
|
||||
}
|
||||
|
||||
// ── Greek ────────────────────────────────────────────────────────────────
|
||||
await page.goto(`http://localhost:${APP_PORT}/order/${site.site_id}`)
|
||||
await page.getByRole('button', { name: 'EL' }).click()
|
||||
|
||||
Reference in New Issue
Block a user