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:
@@ -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