49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
/**
|
|
* Unit tests for `orderCoords`, the gate that keeps migration-seeded address
|
|
* coordinates out of the admin order APIs.
|
|
*
|
|
* `addresses.vague_backfilled_coords = true` means the latitude/longitude are
|
|
* the region centre written by the 0006 backfill, not a real delivery location.
|
|
* The admin UIs hide "Open in Maps" when coordinates are null, so the backend
|
|
* simply omits them.
|
|
*/
|
|
import { orderCoords } from '@/src/dbService'
|
|
|
|
const base = {
|
|
latitude: 16.7,
|
|
longitude: 78.0,
|
|
adminLatitude: null,
|
|
adminLongitude: null,
|
|
vagueBackfilledCoords: false,
|
|
}
|
|
|
|
describe('orderCoords', () => {
|
|
it('omits the migration-seeded centre when there are no admin coordinates', () => {
|
|
expect(orderCoords({ ...base, vagueBackfilledCoords: true })).toEqual({
|
|
latitude: null,
|
|
longitude: null,
|
|
})
|
|
})
|
|
|
|
it('prefers admin coordinates even when a legacy row still has the seeded flag', () => {
|
|
expect(
|
|
orderCoords({
|
|
...base,
|
|
vagueBackfilledCoords: true,
|
|
adminLatitude: 16.75,
|
|
adminLongitude: 78.02,
|
|
})
|
|
).toEqual({ latitude: 16.75, longitude: 78.02 })
|
|
})
|
|
|
|
it('returns real customer coordinates when the address is not seeded', () => {
|
|
expect(orderCoords(base)).toEqual({ latitude: 16.7, longitude: 78.0 })
|
|
})
|
|
|
|
it('returns nulls when the address has no coordinates at all', () => {
|
|
expect(orderCoords({ ...base, latitude: null, longitude: null })).toEqual({
|
|
latitude: null,
|
|
longitude: null,
|
|
})
|
|
})
|
|
})
|