updates on bugs on the dispatch and ai button integrations
This commit is contained in:
@@ -71,11 +71,77 @@ const withNoJoins = () => {
|
||||
endpoints.getMilers.mockResolvedValue([]);
|
||||
endpoints.getAdminTenants.mockResolvedValue([]);
|
||||
endpoints.getConsignments.mockResolvedValue([]);
|
||||
// The hub list backs the city filter. Empty here on purpose: `key()` passes
|
||||
// applocationid 1, and with no hubs to resolve it against the filter has to
|
||||
// fail open, leaving every assertion below about status/date/joins alone.
|
||||
endpoints.getHubs.mockResolvedValue([]);
|
||||
};
|
||||
|
||||
describe('deliveries data layer', () => {
|
||||
beforeEach(withNoJoins);
|
||||
|
||||
/**
|
||||
* The hub picker on Control X.
|
||||
*
|
||||
* `applocationid` is slot 1 of the query key, and it was destructured out and
|
||||
* then never read — the same silent no-op this folder's CLAUDE.md records for
|
||||
* startdate/enddate, which it survived. Picking a hub rebuilt the key,
|
||||
* refetched, and returned the identical nationwide row set, so the header
|
||||
* chip read "Coimbatore Neptune Hub" while the map drew a Bangalore rider on
|
||||
* Mysore Road.
|
||||
*
|
||||
* These assert the KEY POSITION is consumed, not just that the helper works —
|
||||
* locationScope.test.js covers the matching rules. A filter nothing calls is
|
||||
* exactly what went wrong here twice.
|
||||
*/
|
||||
describe('fetchDeliveries — the city in the query key', () => {
|
||||
const HUBS = [
|
||||
{ hubid: 1, hubname: 'Coimbatore Jupiter Hub', applocationid: 1, latitude: 11.0168, longitude: 76.9558 },
|
||||
{ hubid: 5, hubname: 'Bangalore Earth Hub', applocationid: 3, latitude: 12.9352, longitude: 77.6244 },
|
||||
];
|
||||
const cityKey = (appId) => ['dispatchDeliveries', appId, null, 'all', undefined, undefined, 100];
|
||||
|
||||
const coimbatore = booking({ bookingid: 1, bookingno: 'DM-CBE',
|
||||
pickuplatitude: 11.0168, pickuplongitude: 76.9558,
|
||||
deliverylatitude: 11.0183, deliverylongitude: 76.9680 });
|
||||
const bangalore = booking({ bookingid: 2, bookingno: 'DM-BLR',
|
||||
pickuplatitude: 12.9352, pickuplongitude: 77.6244,
|
||||
deliverylatitude: 12.9439, deliverylongitude: 77.5092 });
|
||||
|
||||
beforeEach(() => {
|
||||
endpoints.getHubs.mockResolvedValue(HUBS);
|
||||
endpoints.getBookings.mockResolvedValue([coimbatore, bangalore]);
|
||||
});
|
||||
|
||||
it('Coimbatore returns the Coimbatore run and not the Bangalore one', async () => {
|
||||
const { rows } = await fetchDeliveries({ pageParam: 1, queryKey: cityKey(1) });
|
||||
expect(rows.map((r) => r.bookingno)).toEqual(['DM-CBE']);
|
||||
});
|
||||
|
||||
it('Bangalore returns the Bangalore run and not the Coimbatore one', async () => {
|
||||
const { rows } = await fetchDeliveries({ pageParam: 1, queryKey: cityKey(3) });
|
||||
expect(rows.map((r) => r.bookingno)).toEqual(['DM-BLR']);
|
||||
});
|
||||
|
||||
it('All locations returns both', async () => {
|
||||
const { rows } = await fetchDeliveries({ pageParam: 1, queryKey: cityKey(0) });
|
||||
expect(rows.map((r) => r.bookingno).sort()).toEqual(['DM-BLR', 'DM-CBE']);
|
||||
});
|
||||
|
||||
it('a failed hub list shows everything rather than an empty board', async () => {
|
||||
// A blank dispatch board reads as "no work today" and is acted on. It
|
||||
// must never be what a failed side-call produces.
|
||||
endpoints.getHubs.mockRejectedValue(new Error('hubs down'));
|
||||
const { rows } = await fetchDeliveries({ pageParam: 1, queryKey: cityKey(1) });
|
||||
expect(rows).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('an unknown city shows everything rather than an empty board', async () => {
|
||||
const { rows } = await fetchDeliveries({ pageParam: 1, queryKey: cityKey(999) });
|
||||
expect(rows).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchDeliveries — dispatched filtering', () => {
|
||||
it('should surface a booking that already has a rider assigned', async () => {
|
||||
endpoints.getBookings.mockResolvedValue([booking()]);
|
||||
@@ -623,3 +689,29 @@ describe('deliveries data layer', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchDeliveries — the hub list is only fetched when it is needed', () => {
|
||||
// Dispatch polls every 8 seconds and auto-pages through the whole day, so an
|
||||
// unconditional call here is a request per page per tick on a list that four
|
||||
// pages read and three never scope.
|
||||
beforeEach(() => {
|
||||
endpoints.getBookings.mockResolvedValue([]);
|
||||
endpoints.getHubs.mockResolvedValue([]);
|
||||
});
|
||||
|
||||
it('is not fetched for All locations', async () => {
|
||||
await fetchDeliveries({ pageParam: 1, queryKey: ['d', 0, null, 'all', undefined, undefined, 100] });
|
||||
expect(endpoints.getHubs).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('is not fetched by a caller that passes no city at all', async () => {
|
||||
// reports/OperationalReportCards passes '' in this slot.
|
||||
await fetchDeliveries({ pageParam: 1, queryKey: ['d', '', '', '', '2026-09-01', '2026-09-30', 500] });
|
||||
expect(endpoints.getHubs).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('is fetched once a city is selected', async () => {
|
||||
await fetchDeliveries({ pageParam: 1, queryKey: ['d', 3, null, 'all', undefined, undefined, 100] });
|
||||
expect(endpoints.getHubs).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user