1 | const { CircularOperationValidator } = require('../src/CircularOperationValidator');
|
2 | const { Operation } = require('../src/Operation');
|
3 |
|
4 | describe('CircularOperationValidator', function () {
|
5 | test('should be defined', () => {
|
6 | expect(CircularOperationValidator).toBeDefined();
|
7 | });
|
8 |
|
9 | test('should throw error when two operations depend on each other', (done) => {
|
10 | const operation1 = new Operation();
|
11 | const operation2 = new Operation();
|
12 |
|
13 | operation1.dependencies = [operation2];
|
14 | operation2.dependencies = [operation1];
|
15 |
|
16 | try {
|
17 | new CircularOperationValidator([operation1]);
|
18 | fail('should have failed here');
|
19 | } catch (e) {
|
20 | expect(e.constructor.name === 'CircularOperationValidatorError').toBe(true);
|
21 | done();
|
22 | }
|
23 | });
|
24 |
|
25 | test('should throw error when two deeply nested operations depend on each other', (done) => {
|
26 | const operation1 = new Operation();
|
27 | const operation2 = new Operation();
|
28 | const operation3 = new Operation();
|
29 | const operation4 = new Operation();
|
30 | const operation5 = new Operation();
|
31 | const operation6 = new Operation();
|
32 | const operation7 = new Operation();
|
33 |
|
34 | operation1.dependencies = [operation2];
|
35 | operation2.dependencies = [operation3];
|
36 | operation3.dependencies = [operation4];
|
37 | operation4.dependencies = [operation5];
|
38 | operation5.dependencies = [operation6];
|
39 | operation6.dependencies = [operation7];
|
40 | operation7.dependencies = [operation1];
|
41 |
|
42 | try {
|
43 | new CircularOperationValidator([operation1]);
|
44 | fail('should have failed here');
|
45 | } catch (e) {
|
46 | expect(e.constructor.name === 'CircularOperationValidatorError').toBe(true);
|
47 | done();
|
48 | }
|
49 | });
|
50 |
|
51 | test('error should be of type ', (done) => {
|
52 | const operation1 = new Operation();
|
53 | const operation2 = new Operation();
|
54 |
|
55 | operation1.dependencies = [operation2];
|
56 | operation2.dependencies = [operation1];
|
57 |
|
58 | try {
|
59 | new CircularOperationValidator([operation1]);
|
60 | fail('should have failed here');
|
61 | } catch (e) {
|
62 | expect(e.constructor.name === 'CircularOperationValidatorError').toBe(true);
|
63 | done();
|
64 | }
|
65 | });
|
66 |
|
67 | test('should not throw error when two operations dont depend on each other', (done) => {
|
68 | const operation1 = new Operation();
|
69 | const operation2 = new Operation();
|
70 |
|
71 | operation1.dependencies = [operation2];
|
72 | operation2.dependencies = [];
|
73 |
|
74 | try {
|
75 | new CircularOperationValidator([operation1]);
|
76 | done();
|
77 | } catch (e) {
|
78 | fail('should have failed here');
|
79 | }
|
80 | });
|
81 |
|
82 | test('should throw error when two deeply nested operations depend on each other', (done) => {
|
83 | const operation1 = new Operation();
|
84 | const operation2 = new Operation();
|
85 | const operation3 = new Operation();
|
86 | const operation4 = new Operation();
|
87 | const operation5 = new Operation();
|
88 | const operation6 = new Operation();
|
89 | const operation7 = new Operation();
|
90 |
|
91 | operation1.dependencies = [operation2];
|
92 | operation2.dependencies = [operation3];
|
93 | operation3.dependencies = [operation4];
|
94 | operation4.dependencies = [operation5];
|
95 | operation5.dependencies = [operation6];
|
96 | operation6.dependencies = [operation7];
|
97 | operation7.dependencies = [];
|
98 |
|
99 | try {
|
100 | new CircularOperationValidator([operation1]);
|
101 | done();
|
102 | } catch (e) {
|
103 | fail('should have failed here');
|
104 | }
|
105 | });
|
106 | }); |
\ | No newline at end of file |