2018-02-22 15:59:56 -08:00
|
|
|
import { throwIfApiError, ApiError } from 'wherehows-web/utils/api/errors/errors';
|
2018-02-21 14:41:05 -08:00
|
|
|
import { module, test } from 'qunit';
|
2018-02-22 16:17:55 -08:00
|
|
|
import { ApiResponseStatus } from 'wherehows-web/utils/api/shared';
|
2018-02-21 14:41:05 -08:00
|
|
|
|
|
|
|
module('Unit | Utility | api/errors/errors');
|
|
|
|
|
|
|
|
test('throwIfApiError exists', function(assert) {
|
|
|
|
assert.ok(typeof throwIfApiError === 'function', 'throwIfApiError exists as a function');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('throwIfApiError returns a Promise / thennable', function(assert) {
|
|
|
|
assert.ok(
|
|
|
|
typeof throwIfApiError({ status: 200, ok: true, json: () => Promise.resolve() }).then === 'function',
|
|
|
|
'invocation returns a Promise object / thennable'
|
|
|
|
);
|
|
|
|
});
|
2018-02-22 15:59:56 -08:00
|
|
|
|
|
|
|
test('ApiError subclasses built-in Error and has attributes', function(assert) {
|
|
|
|
const status = ApiResponseStatus.NotFound;
|
|
|
|
const apiError = new ApiError(status);
|
|
|
|
|
|
|
|
assert.ok(apiError instanceof Error, 'is an instanceof Error');
|
|
|
|
assert.ok(apiError.timestamp instanceof Date, 'has a valid timestamp');
|
|
|
|
assert.ok(apiError.status === status, 'has a status attribute');
|
|
|
|
});
|