updates on the admin and zone things and minor changes
This commit is contained in:
@@ -65,7 +65,7 @@ describe('ZoneContext', () => {
|
||||
|
||||
it('should not load tenant locations for a staff login', () => {
|
||||
setup({ user: { tenantid: '0' } });
|
||||
expect(useHubs).toHaveBeenCalledWith({ enabled: true });
|
||||
expect(useHubs).toHaveBeenCalled();
|
||||
expect(useTenantLocations).toHaveBeenCalledWith(null, { enabled: false });
|
||||
});
|
||||
});
|
||||
@@ -79,17 +79,40 @@ describe('ZoneContext', () => {
|
||||
longitude: 77.6408
|
||||
};
|
||||
|
||||
it('should offer the tenant kitchen hubs instead of global hubs', () => {
|
||||
// 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', () => {
|
||||
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']);
|
||||
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones', 'Indiranagar Kitchen', 'Koramangala Hub']);
|
||||
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[1].locationid).toBe('2');
|
||||
});
|
||||
|
||||
it('should offer only the hubs of the client own city when the login carries it', () => {
|
||||
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']);
|
||||
});
|
||||
|
||||
it('should still show the hubs to a client with no locations yet', () => {
|
||||
const { result } = setup({ user: { tenantid: '4' }, locations: [] });
|
||||
expect(result.current.zones.map((z) => z.hubname)).toEqual(['All Zones', 'Koramangala Hub']);
|
||||
});
|
||||
|
||||
it('should scope the location query to the operator own tenant', () => {
|
||||
setup({ user: { tenantid: '4' }, locations: [LOCATION] });
|
||||
expect(useTenantLocations).toHaveBeenCalledWith('4', { enabled: true });
|
||||
expect(useHubs).toHaveBeenCalledWith({ enabled: false });
|
||||
expect(useHubs).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should treat tenantid "0" as staff, not as a tenant', () => {
|
||||
@@ -425,7 +448,7 @@ describe('ZoneContext', () => {
|
||||
expect(result.current.isHubsLoading).toBe(true);
|
||||
});
|
||||
|
||||
it('should refetch the source the current login actually reads', () => {
|
||||
it('should refetch both sources a client login reads', () => {
|
||||
const refetchHubs = jest.fn();
|
||||
const refetchLocations = jest.fn();
|
||||
useAuth.mockReturnValue({ user: { tenantid: '4' } });
|
||||
@@ -436,7 +459,7 @@ describe('ZoneContext', () => {
|
||||
act(() => result.current.refetchHubs());
|
||||
|
||||
expect(refetchLocations).toHaveBeenCalledTimes(1);
|
||||
expect(refetchHubs).not.toHaveBeenCalled();
|
||||
expect(refetchHubs).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user