Skip to content

Commit 5e492e4

Browse files
authored
chore-docs: improved documentation and fixed test smells (#213)
* chore-docs: improved documentation and fixed test smells * test: reverted structuredClone (not available for Node 16 LTS)
1 parent def41ff commit 5e492e4

File tree

13 files changed

+435
-261
lines changed

13 files changed

+435
-261
lines changed

README.md

Lines changed: 308 additions & 135 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
],
3333
"devDependencies": {
3434
"@babel/eslint-parser": "^7.28.4",
35-
"@typescript-eslint/eslint-plugin": "^8.46.0",
36-
"@typescript-eslint/parser": "^8.46.0",
35+
"@typescript-eslint/eslint-plugin": "^8.46.1",
36+
"@typescript-eslint/parser": "^8.46.1",
3737
"c8": "^10.1.3",
3838
"chai": "^6.2.0",
3939
"env-cmd": "^11.0.0",
40-
"eslint": "^9.37.0",
40+
"eslint": "^9.38.0",
4141
"mocha": "^11.7.4",
4242
"mocha-sonarqube-reporter": "^1.0.2",
4343
"sinon": "^21.0.0"

tests/helper/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ export async function assertUntilResolve(assert, actual, expected) {
4343

4444
await Promise.race([promise, sleep(2000)]);
4545

46-
if (!actual()) {
47-
console.warn('Async test could not resolve in time');
46+
const resolved = actual();
47+
if (resolved) {
48+
assert.equal(resolved, expected);
4849
} else {
49-
assert.equal(actual(), expected);
50+
console.warn('Async test could not resolve in time');
5051
}
5152
}
5253

tests/strategy-operations/date.test.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,69 @@ describe('Processing strategy: DATE', () => {
2222
activated: true,
2323
});
2424

25-
it('should agree when input is LOWER', async () => {
25+
it('should agree when input is LOWER', () => {
2626
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
27-
const result = await processOperation(strategyConfig, '2019-11-26');
27+
const result = processOperation(strategyConfig, '2019-11-26');
2828
assert.isTrue(result);
2929
});
3030

31-
it('should agree when input is LOWER or SAME', async () => {
31+
it('should agree when input is LOWER or SAME', () => {
3232
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
33-
const result = await processOperation(strategyConfig, '2019-12-01');
33+
const result = processOperation(strategyConfig, '2019-12-01');
3434
assert.isTrue(result);
3535
});
3636

37-
it('should NOT agree when input is NOT LOWER', async () => {
37+
it('should NOT agree when input is NOT LOWER', () => {
3838
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
39-
const result = await processOperation(strategyConfig, '2019-12-02');
39+
const result = processOperation(strategyConfig, '2019-12-02');
4040
assert.isFalse(result);
4141
});
4242

43-
it('should agree when input is GREATER', async () => {
43+
it('should agree when input is GREATER', () => {
4444
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
45-
const result = await processOperation(strategyConfig, '2019-12-02');
45+
const result = processOperation(strategyConfig, '2019-12-02');
4646
assert.isTrue(result);
4747
});
4848

49-
it('should agree when input is GREATER or SAME', async () => {
49+
it('should agree when input is GREATER or SAME', () => {
5050
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
51-
const result = await processOperation(strategyConfig, '2019-12-01');
51+
const result = processOperation(strategyConfig, '2019-12-01');
5252
assert.isTrue(result);
5353
});
5454

55-
it('should NOT agree when input is NOT GREATER', async () => {
55+
it('should NOT agree when input is NOT GREATER', () => {
5656
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
57-
const result = await processOperation(strategyConfig, '2019-11-10');
57+
const result = processOperation(strategyConfig, '2019-11-10');
5858
assert.isFalse(result);
5959
});
6060

61-
it('should agree when input is in BETWEEN', async () => {
61+
it('should agree when input is in BETWEEN', () => {
6262
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
63-
const result = await processOperation(strategyConfig, '2019-12-03');
63+
const result = processOperation(strategyConfig, '2019-12-03');
6464
assert.isTrue(result);
6565
});
6666

67-
it('should NOT agree when input is NOT in BETWEEN', async () => {
67+
it('should NOT agree when input is NOT in BETWEEN', () => {
6868
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
69-
const result = await processOperation(strategyConfig, '2019-12-12');
69+
const result = processOperation(strategyConfig, '2019-12-12');
7070
assert.isFalse(result);
7171
});
7272

73-
it('should agree when input is LOWER including time', async () => {
73+
it('should agree when input is LOWER including time', () => {
7474
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values3);
75-
const result = await processOperation(strategyConfig, '2019-12-01T07:00');
75+
const result = processOperation(strategyConfig, '2019-12-01T07:00');
7676
assert.isTrue(result);
7777
});
7878

79-
it('should NOT agree when input is NOT LOWER including time', async () => {
79+
it('should NOT agree when input is NOT LOWER including time', () => {
8080
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
81-
const result = await processOperation(strategyConfig, '2019-12-01T07:00');
81+
const result = processOperation(strategyConfig, '2019-12-01T07:00');
8282
assert.isFalse(result);
8383
});
8484

85-
it('should agree when input is GREATER including time', async () => {
85+
it('should agree when input is GREATER including time', () => {
8686
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
87-
const result = await processOperation(strategyConfig, '2019-12-01T08:40');
87+
const result = processOperation(strategyConfig, '2019-12-01T08:40');
8888
assert.isTrue(result);
8989
});
9090

tests/strategy-operations/network.test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,57 +25,57 @@ describe('Processing strategy: NETWORK', () => {
2525
activated: true,
2626
});
2727

28-
it('should agree when input range EXIST', async () => {
28+
it('should agree when input range EXIST', () => {
2929
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
30-
const result = await processOperation(strategyConfig, '10.0.0.3');
30+
const result = processOperation(strategyConfig, '10.0.0.3');
3131
assert.isTrue(result);
3232
});
3333

3434
it('should agree when input range EXIST - Irregular CIDR', async function () {
3535
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, ['10.0.0.3/24']);
36-
const result = await processOperation(strategyConfig, '10.0.0.3');
36+
const result = processOperation(strategyConfig, '10.0.0.3');
3737
assert.isTrue(result);
3838
});
3939

40-
it('should NOT agree when input range DOES NOT EXIST', async () => {
40+
it('should NOT agree when input range DOES NOT EXIST', () => {
4141
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
42-
const result = await processOperation(strategyConfig, '10.0.0.4');
42+
const result = processOperation(strategyConfig, '10.0.0.4');
4343
assert.isFalse(result);
4444
});
4545

46-
it('should agree when input DOES NOT EXIST', async () => {
46+
it('should agree when input DOES NOT EXIST', () => {
4747
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values1);
48-
const result = await processOperation(strategyConfig, '10.0.0.4');
48+
const result = processOperation(strategyConfig, '10.0.0.4');
4949
assert.isTrue(result);
5050
});
5151

52-
it('should NOT agree when input EXIST but assumed that it DOES NOT EXIST', async () => {
52+
it('should NOT agree when input EXIST but assumed that it DOES NOT EXIST', () => {
5353
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values1);
54-
const result = await processOperation(strategyConfig, '10.0.0.3');
54+
const result = processOperation(strategyConfig, '10.0.0.3');
5555
assert.isFalse(result);
5656
});
5757

58-
it('should agree when input IP EXIST', async () => {
58+
it('should agree when input IP EXIST', () => {
5959
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values3);
60-
const result = await processOperation(strategyConfig, '192.168.56.58');
60+
const result = processOperation(strategyConfig, '192.168.56.58');
6161
assert.isTrue(result);
6262
});
6363

64-
it('should agree when input IP DOES NOT EXIST', async () => {
64+
it('should agree when input IP DOES NOT EXIST', () => {
6565
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values3);
66-
const result = await processOperation(strategyConfig, '192.168.56.50');
66+
const result = processOperation(strategyConfig, '192.168.56.50');
6767
assert.isTrue(result);
6868
});
6969

70-
it('should agree when input range EXIST for multiple ranges', async () => {
70+
it('should agree when input range EXIST for multiple ranges', () => {
7171
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values2);
72-
const result = await processOperation(strategyConfig, '192.168.0.3');
72+
const result = processOperation(strategyConfig, '192.168.0.3');
7373
assert.isTrue(result);
7474
});
7575

76-
it('should NOT agree when input range DOES NOT EXIST for multiple ranges', async () => {
76+
it('should NOT agree when input range DOES NOT EXIST for multiple ranges', () => {
7777
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values2);
78-
const result = await processOperation(strategyConfig, '127.0.0.0');
78+
const result = processOperation(strategyConfig, '127.0.0.0');
7979
assert.isTrue(result);
8080
});
8181

tests/strategy-operations/numeric.test.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,100 +22,100 @@ describe('Processing strategy: NUMERIC', () => {
2222
activated: true,
2323
});
2424

25-
it('should agree when input EXIST in values - String type', async () => {
25+
it('should agree when input EXIST in values - String type', () => {
2626
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values2);
27-
const result = await processOperation(strategyConfig, '3');
27+
const result = processOperation(strategyConfig, '3');
2828
assert.isTrue(result);
2929
});
3030

31-
it('should agree when input EXIST in values - Number type', async () => {
31+
it('should agree when input EXIST in values - Number type', () => {
3232
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values2);
33-
const result = await processOperation(strategyConfig, 3);
33+
const result = processOperation(strategyConfig, 3);
3434
assert.isTrue(result);
3535
});
3636

37-
it('should NOT agree when input exist but test as DOES NOT EXIST ', async () => {
37+
it('should NOT agree when input exist but test as DOES NOT EXIST ', () => {
3838
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values2);
39-
const result = await processOperation(strategyConfig, '1');
39+
const result = processOperation(strategyConfig, '1');
4040
assert.isFalse(result);
4141
});
4242

43-
it('should agree when input DOES NOT EXIST in values', async () => {
43+
it('should agree when input DOES NOT EXIST in values', () => {
4444
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values2);
45-
const result = await processOperation(strategyConfig, '2');
45+
const result = processOperation(strategyConfig, '2');
4646
assert.isTrue(result);
4747
});
4848

49-
it('should agree when input is EQUAL to value', async () => {
49+
it('should agree when input is EQUAL to value', () => {
5050
const strategyConfig = givenStrategyConfig(OperationsType.EQUAL, mock_values1);
51-
const result = await processOperation(strategyConfig, '1');
51+
const result = processOperation(strategyConfig, '1');
5252
assert.isTrue(result);
5353
});
5454

55-
it('should NOT agree when input is not equal but test as EQUAL', async () => {
55+
it('should NOT agree when input is not equal but test as EQUAL', () => {
5656
const strategyConfig = givenStrategyConfig(OperationsType.EQUAL, mock_values1);
57-
const result = await processOperation(strategyConfig, '2');
57+
const result = processOperation(strategyConfig, '2');
5858
assert.isFalse(result);
5959
});
6060

61-
it('should agree when input is NOT EQUAL to value', async () => {
61+
it('should agree when input is NOT EQUAL to value', () => {
6262
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EQUAL, mock_values1);
63-
const result = await processOperation(strategyConfig, '2');
63+
const result = processOperation(strategyConfig, '2');
6464
assert.isTrue(result);
6565
});
6666

67-
it('should agree when input is GREATER than value', async () => {
67+
it('should agree when input is GREATER than value', () => {
6868
let strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
69-
let result = await processOperation(strategyConfig, '2');
69+
let result = processOperation(strategyConfig, '2');
7070
assert.isTrue(result);
7171

7272
// test decimal
73-
result = await processOperation(strategyConfig, '1.01');
73+
result = processOperation(strategyConfig, '1.01');
7474
assert.isTrue(result);
7575

7676
strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
77-
result = await processOperation(strategyConfig, '1.55');
77+
result = processOperation(strategyConfig, '1.55');
7878
assert.isTrue(result);
7979
});
8080

81-
it('should NOT agree when input is lower but tested as GREATER than value', async () => {
81+
it('should NOT agree when input is lower but tested as GREATER than value', () => {
8282
let strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
83-
let result = await processOperation(strategyConfig, '0');
83+
let result = processOperation(strategyConfig, '0');
8484
assert.isFalse(result);
8585

8686
// test decimal
87-
result = await processOperation(strategyConfig, '0.99');
87+
result = processOperation(strategyConfig, '0.99');
8888
assert.isFalse(result);
8989

9090
strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
91-
result = await processOperation(strategyConfig, '1.49');
91+
result = processOperation(strategyConfig, '1.49');
9292
assert.isFalse(result);
9393
});
9494

95-
it('should agree when input is LOWER than value', async () => {
95+
it('should agree when input is LOWER than value', () => {
9696
let strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
97-
let result = await processOperation(strategyConfig, '0');
97+
let result = processOperation(strategyConfig, '0');
9898
assert.isTrue(result);
9999

100100
// test decimal
101-
result = await processOperation(strategyConfig, '0.99');
101+
result = processOperation(strategyConfig, '0.99');
102102
assert.isTrue(result);
103103

104104
strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values3);
105-
result = await processOperation(strategyConfig, '1.49');
105+
result = processOperation(strategyConfig, '1.49');
106106
assert.isTrue(result);
107107
});
108108

109-
it('should agree when input is BETWEEN values', async () => {
109+
it('should agree when input is BETWEEN values', () => {
110110
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
111-
let result = await processOperation(strategyConfig, '1');
111+
let result = processOperation(strategyConfig, '1');
112112
assert.isTrue(result);
113113

114114
// test decimal
115-
result = await processOperation(strategyConfig, '2.99');
115+
result = processOperation(strategyConfig, '2.99');
116116
assert.isTrue(result);
117117

118-
result = await processOperation(strategyConfig, '1.001');
118+
result = processOperation(strategyConfig, '1.001');
119119
assert.isTrue(result);
120120
});
121121
});

0 commit comments

Comments
 (0)