|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import isServerError from 'brn/utils/is-server-error'; |
| 3 | + |
| 4 | +module('Unit | Utils | is-server-error', function () { |
| 5 | + test('returns false for null/undefined', function (assert) { |
| 6 | + assert.false(isServerError(null)); |
| 7 | + assert.false(isServerError(undefined)); |
| 8 | + }); |
| 9 | + |
| 10 | + test('returns false for non-object values', function (assert) { |
| 11 | + assert.false(isServerError('some string error')); |
| 12 | + assert.false(isServerError(42)); |
| 13 | + assert.false(isServerError(true)); |
| 14 | + }); |
| 15 | + |
| 16 | + test('returns true for WarpDrive FetchError with status 500', function (assert) { |
| 17 | + const error = { isRequestError: true, status: 500, code: 500 }; |
| 18 | + assert.true(isServerError(error)); |
| 19 | + }); |
| 20 | + |
| 21 | + test('returns true for WarpDrive FetchError with status 503', function (assert) { |
| 22 | + const error = { isRequestError: true, status: 503, code: 503 }; |
| 23 | + assert.true(isServerError(error)); |
| 24 | + }); |
| 25 | + |
| 26 | + test('returns true for WarpDrive FetchError with status 0 (network error)', function (assert) { |
| 27 | + const error = { isRequestError: true, status: 0, code: 0 }; |
| 28 | + assert.true(isServerError(error)); |
| 29 | + }); |
| 30 | + |
| 31 | + test('returns false for WarpDrive FetchError with status 401', function (assert) { |
| 32 | + const error = { isRequestError: true, status: 401, code: 401 }; |
| 33 | + assert.false(isServerError(error)); |
| 34 | + }); |
| 35 | + |
| 36 | + test('returns false for WarpDrive FetchError with status 404', function (assert) { |
| 37 | + const error = { isRequestError: true, status: 404, code: 404 }; |
| 38 | + assert.false(isServerError(error)); |
| 39 | + }); |
| 40 | + |
| 41 | + test('returns true for error with status 500 in errors array', function (assert) { |
| 42 | + const error = { errors: [{ status: 500 }] }; |
| 43 | + assert.true(isServerError(error)); |
| 44 | + }); |
| 45 | + |
| 46 | + test('returns true for error with string status "502" in errors array', function (assert) { |
| 47 | + const error = { errors: [{ status: '502' }] }; |
| 48 | + assert.true(isServerError(error)); |
| 49 | + }); |
| 50 | + |
| 51 | + test('returns false for error with status 400 in errors array', function (assert) { |
| 52 | + const error = { errors: [{ status: 400 }] }; |
| 53 | + assert.false(isServerError(error)); |
| 54 | + }); |
| 55 | + |
| 56 | + test('returns true for TypeError with fetch message', function (assert) { |
| 57 | + const error = new TypeError('Failed to fetch'); |
| 58 | + assert.true(isServerError(error)); |
| 59 | + }); |
| 60 | + |
| 61 | + test('returns false for TypeError without fetch message', function (assert) { |
| 62 | + const error = new TypeError('Cannot read property of undefined'); |
| 63 | + assert.false(isServerError(error)); |
| 64 | + }); |
| 65 | + |
| 66 | + test('returns false for AbortError (user-initiated navigation)', function (assert) { |
| 67 | + const error = { name: 'AbortError', message: 'The operation was aborted' }; |
| 68 | + assert.false(isServerError(error)); |
| 69 | + }); |
| 70 | + |
| 71 | + test('returns false for generic Error', function (assert) { |
| 72 | + const error = new Error('Something went wrong'); |
| 73 | + assert.false(isServerError(error)); |
| 74 | + }); |
| 75 | + |
| 76 | + test('returns true for direct status 500 on error object', function (assert) { |
| 77 | + const error = { status: 500 }; |
| 78 | + assert.true(isServerError(error)); |
| 79 | + }); |
| 80 | + |
| 81 | + test('returns false for direct status 422 on error object', function (assert) { |
| 82 | + const error = { status: 422 }; |
| 83 | + assert.false(isServerError(error)); |
| 84 | + }); |
| 85 | +}); |
0 commit comments