updates on the zone fix

This commit is contained in:
2026-10-06 19:33:02 +05:30
parent 7aca6a6a48
commit 21775fe6f9
3 changed files with 25 additions and 36 deletions

View File

@@ -79,34 +79,35 @@ describe('ZoneContext', () => {
longitude: 77.6408
};
// A client sees their own locations first, then the Doormile hubs. A newly
// onboarded client used to have no locations and therefore no zones at all
// — not even the Coimbatore hub their orders run through.
it('should offer the tenant own locations and then the Doormile hubs', () => {
// A client sees only its own locations, never Doormile's hubs.
it('should offer the tenant only its own locations', () => {
const { result } = setup({ user: { tenantid: '4' }, locations: [LOCATION] });
expect(result.current.isTenantUser).toBe(true);
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones', 'Indiranagar Kitchen', 'Koramangala Hub']);
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones', 'Indiranagar Kitchen']);
expect(result.current.zones[1].hubtype).toBe('kitchen_hub');
expect(result.current.zones[1].isTenantLocation).toBe(true);
expect(result.current.zones[2].isTenantLocation).toBeFalsy();
});
it('should prefix a location zone id so it cannot collide with a hub id', () => {
const { result } = setup({ user: { tenantid: '4' }, locations: [{ ...LOCATION, tenantlocationid: 2 }] });
expect(result.current.zones.map((z) => z.hubid)).toEqual(['all', 'loc:2', '2']);
expect(result.current.zones.map((z) => z.hubid)).toEqual(['all', 'loc:2']);
expect(result.current.zones[1].locationid).toBe('2');
});
it('should offer only the hubs of the client own city when the login carries it', () => {
// The Sai's Kitchen report: a Coimbatore client was offered Hyderabad and
// Bangalore hubs, because a session without a city fell back to every hub.
it('should never offer Doormile hubs to a client, with or without a city', () => {
const CBE = { ...KORAMANGALA, hubid: '7', hubname: 'Coimbatore Neptune Hub', applocationid: 1 };
const BLR = { ...KORAMANGALA, applocationid: 3 };
const { result } = setup({ user: { tenantid: '4', applocationid: 1 }, hubs: [CBE, BLR] });
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones', 'Coimbatore Neptune Hub']);
const HYD = { ...KORAMANGALA, hubid: '8', hubname: 'Hyderabad Mars Hub', applocationid: 2 };
for (const user of [{ tenantid: '4', applocationid: 1 }, { tenantid: '4' }]) {
const { result } = setup({ user, hubs: [CBE, HYD, KORAMANGALA], locations: [LOCATION] });
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones', 'Indiranagar Kitchen']);
}
});
it('should still show the hubs to a client with no locations yet', () => {
it('should show a client with no locations yet only All Zones', () => {
const { result } = setup({ user: { tenantid: '4' }, locations: [] });
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones', 'Koramangala Hub']);
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones']);
});
it('should scope the location query to the operator own tenant', () => {