import { ErrorMessages } from '../../constants'; import { NetworkResponse } from '../../types'; import responseHandler from '../responseHandler'; describe('responseHandler', () => { const mockResponse = { status: 'healthy' }; it('should resolve successfully if status is ok', () => { const expected: NetworkResponse = { ok: true, status: 200, response: mockResponse, }; return responseHandler(200, mockResponse).then((response) => { expect(response).toEqual(expected); }); }); it('resolve with error_response if status is bad and response present', () => { const expected: NetworkResponse = { ok: false, status: 422, error: mockResponse, }; return responseHandler(422, mockResponse).then((response) => { expect(response).toEqual(expected); }); }); it('resolve with error_response if status is bad and response is not present', () => { const expected: NetworkResponse = { ok: false, status: 500, error: { messages: [ErrorMessages.NETWORK_ERROR], }, }; return responseHandler(500).then((response) => { expect(response).toEqual(expected); }); }); });