|
| 1 | +import {isResponseError, isResponseErrorWithIssues} from '../response'; |
| 2 | + |
| 3 | +describe('isResponseError', () => { |
| 4 | + test('should return false on incorrect data', () => { |
| 5 | + const incorrectValues = [{}, [], 'hello', 123, null, undefined]; |
| 6 | + |
| 7 | + incorrectValues.forEach((value) => { |
| 8 | + expect(isResponseError(value)).toBe(false); |
| 9 | + }); |
| 10 | + }); |
| 11 | + test('should return true if it is object with status or status text', () => { |
| 12 | + expect(isResponseError({status: 403})).toBe(true); |
| 13 | + expect(isResponseError({statusText: 'Gateway timeout'})).toBe(true); |
| 14 | + }); |
| 15 | + test('should return true if it is cancelled', () => { |
| 16 | + expect(isResponseError({isCancelled: true})).toBe(true); |
| 17 | + }); |
| 18 | + test('should return true if it has data', () => { |
| 19 | + expect(isResponseError({data: 'Everything is broken'})).toBe(true); |
| 20 | + }); |
| 21 | +}); |
| 22 | + |
| 23 | +describe('isResponseErrorWithIssues', () => { |
| 24 | + test('should return false on incorrect data', () => { |
| 25 | + const incorrectValues = [{}, [], 'hello', 123, null, undefined]; |
| 26 | + |
| 27 | + incorrectValues.forEach((value) => { |
| 28 | + expect(isResponseErrorWithIssues({data: value})).toBe(false); |
| 29 | + }); |
| 30 | + }); |
| 31 | + test('should return false on empty issues', () => { |
| 32 | + expect( |
| 33 | + isResponseErrorWithIssues({ |
| 34 | + data: {issues: []}, |
| 35 | + }), |
| 36 | + ).toBe(false); |
| 37 | + }); |
| 38 | + test('should return false on incorrect issues value', () => { |
| 39 | + const incorrectValues = [{}, [], 'hello', 123, null, undefined]; |
| 40 | + |
| 41 | + incorrectValues.forEach((value) => { |
| 42 | + expect(isResponseErrorWithIssues({data: {issues: value}})).toBe(false); |
| 43 | + }); |
| 44 | + }); |
| 45 | + test('should return false on incorrect issue inside issues', () => { |
| 46 | + const incorrectValues = [{}, [], 'hello', 123, null, undefined]; |
| 47 | + |
| 48 | + incorrectValues.forEach((value) => { |
| 49 | + expect(isResponseErrorWithIssues({data: {issues: [value]}})).toBe(false); |
| 50 | + }); |
| 51 | + }); |
| 52 | + test('should return true if it is an array of issues', () => { |
| 53 | + expect( |
| 54 | + isResponseErrorWithIssues({ |
| 55 | + data: {issues: [{message: 'Some error'}]}, |
| 56 | + }), |
| 57 | + ).toBe(true); |
| 58 | + }); |
| 59 | +}); |
0 commit comments