From 5f4611d65e40eae3ca6191a15f68d69ea5a1c4cb Mon Sep 17 00:00:00 2001 From: Kirill Rogovoy Date: Tue, 20 Jul 2021 21:24:52 +0300 Subject: WIP --- app_expo/services/api/api-problem.test.ts | 100 ++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 app_expo/services/api/api-problem.test.ts (limited to 'app_expo/services/api/api-problem.test.ts') diff --git a/app_expo/services/api/api-problem.test.ts b/app_expo/services/api/api-problem.test.ts new file mode 100644 index 0000000..f8b4041 --- /dev/null +++ b/app_expo/services/api/api-problem.test.ts @@ -0,0 +1,100 @@ +import { getGeneralApiProblem } from './api-problem' +import { ApiErrorResponse } from 'apisauce' + +test('handles connection errors', () => { + expect( + getGeneralApiProblem({ + problem: 'CONNECTION_ERROR', + } as ApiErrorResponse), + ).toEqual({ + kind: 'cannot-connect', + temporary: true, + }) +}) + +test('handles network errors', () => { + expect( + getGeneralApiProblem({ + problem: 'NETWORK_ERROR', + } as ApiErrorResponse), + ).toEqual({ + kind: 'cannot-connect', + temporary: true, + }) +}) + +test('handles timeouts', () => { + expect( + getGeneralApiProblem({ + problem: 'TIMEOUT_ERROR', + } as ApiErrorResponse), + ).toEqual({ + kind: 'timeout', + temporary: true, + }) +}) + +test('handles server errors', () => { + expect(getGeneralApiProblem({ problem: 'SERVER_ERROR' } as ApiErrorResponse)).toEqual({ + kind: 'server', + }) +}) + +test('handles unknown errors', () => { + expect( + getGeneralApiProblem({ + problem: 'UNKNOWN_ERROR', + } as ApiErrorResponse), + ).toEqual({ + kind: 'unknown', + temporary: true, + }) +}) + +test('handles unauthorized errors', () => { + expect( + getGeneralApiProblem({ + problem: 'CLIENT_ERROR', + status: 401, + } as ApiErrorResponse), + ).toEqual({ + kind: 'unauthorized', + }) +}) + +test('handles forbidden errors', () => { + expect( + getGeneralApiProblem({ + problem: 'CLIENT_ERROR', + status: 403, + } as ApiErrorResponse), + ).toEqual({ + kind: 'forbidden', + }) +}) + +test('handles not-found errors', () => { + expect( + getGeneralApiProblem({ + problem: 'CLIENT_ERROR', + status: 404, + } as ApiErrorResponse), + ).toEqual({ + kind: 'not-found', + }) +}) + +test('handles other client errors', () => { + expect( + getGeneralApiProblem({ + problem: 'CLIENT_ERROR', + status: 418, + } as ApiErrorResponse), + ).toEqual({ + kind: 'rejected', + }) +}) + +test('handles cancellation errors', () => { + expect(getGeneralApiProblem({ problem: 'CANCEL_ERROR' } as ApiErrorResponse)).toBeNull() +}) -- cgit v1.2.3