Passed
Push — master ( 2c89c8...4bbdb1 )
by Dmytro
02:27
created

tests/package/error.test.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 23
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 13
mnd 0
bc 0
fnc 4
dl 0
loc 23
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10
1
import { assert } from 'chai';
2
import Test from '../Test';
3
import { checkError, load } from '../utils';
4
5
const factory = new Test();
6
const api = factory.createAPI();
7
const API_ERROR = load('Error').default;
8
9
suite('Api Errors');
10
11
before(function () {
12
    factory.mockAPI();
13
});
14
15
test('Negative: unknownError', async function () {
16
    await checkError(api.put('/request_4/unknownError'), 'Error', 'unknownError occured');
17
});
18
19
test('Negative: apiError with empty data', async function () {
20
    await checkError(api.put('/request_4/emptyError'), 'API_ERROR', 'Error: Request failed with status code 401');
21
});
22
23
test('Negative: Error idempotency', async function () {
24
    const err = await api.put('/request_4/emptyError').catch(error => error);
25
26
    assert.isTrue(err instanceof API_ERROR);
27
    assert.include(err.message, 'Error: Request failed with status code 401', err.toString());
28
29
    const idempotent = new API_ERROR(err);
30
31
    assert.equal(idempotent, err);
32
});
33
34
after(function () {
35
    factory.unMockAPI();
36
});
37