Completed
Push — master ( a32486...3adefc )
by Roman
02:05
created

tests/TErrorGroup.test.js   A

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 76
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 44
mnd 0
bc 0
fnc 9
dl 0
loc 76
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import { TError } from '../libs';
2
import { TErrorGroup } from '../libs';
3
4
5
it('TErrorGroup generate error correctly with params', () => {
6
  const errorsList = {
7
    PAGE_NOT_FOUND: {
8
      message: 'Page not found :(', //Message for user
9
      status: 'REQUEST_ERROR', //Status for logging
10
      code: 404 //HTTP code
11
    }
12
  };
13
14
  const params = {
15
    type: 'SERVER_ERROR'
16
  };
17
18
  const error = new TErrorGroup(params, errorsList);
19
20
  expect(error.create).toThrow()
21
});
22
23
it('TErrorGroup generate error with true params', () => {
24
  const errorsList = {
25
    PAGE_NOT_FOUND: {
26
      message: 'Page not found :(', //Message for user
27
      name: 'REQUEST_ERROR', //Status for logging
28
      code: 404 //HTTP code
29
    }
30
  };
31
32
  const params = {
33
    type: 'SERVER_ERROR'
34
  };
35
36
  const error = new TErrorGroup(params, errorsList);
37
  const result = error.create('PAGE_NOT_FOUND');
38
39
  expect(result.message).toBe(errorsList.PAGE_NOT_FOUND.message);
40
  expect(result.name).toBe(errorsList.PAGE_NOT_FOUND.name);
41
  expect(result.code).toBe(errorsList.PAGE_NOT_FOUND.code);
42
});
43
44
it('TErrorGroup generate error correctly without params', () => {
45
  const error = new TErrorGroup();
46
47
  expect(error.create).toThrow()
48
});
49
50
51
it('TErrorGroup error with undefined name', () => {
52
  const error = new TErrorGroup();
53
  const errorType = 'ABCD';
54
55
  const create = function() {
56
    error.create(errorType);
57
  };
58
59
  expect(create).toThrow(new Error(`Error ${errorType} is missing in errors list.`))
60
});
61
62
it('TErrorGroup must set logger', () => {
63
  const error = new TErrorGroup();
64
  const fn = () => {};
65
  error.setLogger(fn);
66
67
  expect(error.logger).toEqual(fn)
68
});
69
70
it('TErrorGroup must set handler', () => {
71
  const error = new TErrorGroup();
72
  const fn = () => {};
73
  error.setHandler(fn);
74
75
  expect(error.handler).toEqual(fn)
76
});
77