updates on the customer app and map stuck issue
This commit is contained in:
@@ -34,7 +34,8 @@ import doormileAxios, {
|
||||
clearStoredSession,
|
||||
readStoredUser,
|
||||
readStoredToken,
|
||||
errorMessage
|
||||
errorMessage,
|
||||
friendlyErrorMessage
|
||||
} from '@/api/doormile/client';
|
||||
|
||||
const handlers = axios.__handlers;
|
||||
@@ -314,6 +315,46 @@ describe('doormile API client', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('friendlyErrorMessage', () => {
|
||||
const withStatus = (body, status) => Object.defineProperty(body, 'httpStatus', { value: status });
|
||||
|
||||
it('should explain an unreachable server instead of showing "Network Error"', () => {
|
||||
const msg = friendlyErrorMessage({ message: 'Network Error' }, 'create this order');
|
||||
expect(msg).toMatch(/^We couldn't create this order because the Doormile server couldn't be reached/);
|
||||
expect(msg).not.toMatch(/Network Error/);
|
||||
});
|
||||
|
||||
it('should explain a timeout', () => {
|
||||
expect(friendlyErrorMessage({ code: 'ECONNABORTED', message: 'timeout of 0ms exceeded' }, 'create this order'))
|
||||
.toMatch(/took too long to respond/);
|
||||
});
|
||||
|
||||
it('should keep the server reason for a validation failure, since the user can fix it', () => {
|
||||
expect(friendlyErrorMessage(withStatus({ message: 'Pickup pincode 110001 is outside our service cities' }, 400), 'create this order'))
|
||||
.toBe("We couldn't create this order: Pickup pincode 110001 is outside our service cities");
|
||||
});
|
||||
|
||||
it('should hide server internals behind a plain message on a 5xx', () => {
|
||||
const msg = friendlyErrorMessage(withStatus({ message: 'relation "bookings" does not exist' }, 500), 'create this order');
|
||||
expect(msg).toMatch(/problem on our server/);
|
||||
expect(msg).not.toMatch(/relation/);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[401, /session has expired/],
|
||||
[403, /don't have permission to create this order/],
|
||||
[404, /no longer exists/],
|
||||
[429, /Too many requests/]
|
||||
])('should explain HTTP %i', (status, pattern) => {
|
||||
expect(friendlyErrorMessage(withStatus({}, status), 'create this order')).toMatch(pattern);
|
||||
});
|
||||
|
||||
it('should fall back to a check-your-details message on a 4xx with no reason', () => {
|
||||
expect(friendlyErrorMessage(withStatus({}, 422), 'create this order'))
|
||||
.toBe("We couldn't create this order. Please check the details you entered and try again.");
|
||||
});
|
||||
});
|
||||
|
||||
describe('module surface', () => {
|
||||
it('should export the configured axios instance as the default', () => {
|
||||
expect(doormileAxios).toBe(axios.__instance);
|
||||
|
||||
Reference in New Issue
Block a user