Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
443 changes: 308 additions & 135 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
],
"devDependencies": {
"@babel/eslint-parser": "^7.28.4",
"@typescript-eslint/eslint-plugin": "^8.46.0",
"@typescript-eslint/parser": "^8.46.0",
"@typescript-eslint/eslint-plugin": "^8.46.1",
"@typescript-eslint/parser": "^8.46.1",
"c8": "^10.1.3",
"chai": "^6.2.0",
"env-cmd": "^11.0.0",
"eslint": "^9.37.0",
"eslint": "^9.38.0",
"mocha": "^11.7.4",
"mocha-sonarqube-reporter": "^1.0.2",
"sinon": "^21.0.0"
Expand Down
7 changes: 4 additions & 3 deletions tests/helper/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export async function assertUntilResolve(assert, actual, expected) {

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

if (!actual()) {
console.warn('Async test could not resolve in time');
const resolved = actual();
if (resolved) {
assert.equal(resolved, expected);
} else {
assert.equal(actual(), expected);
console.warn('Async test could not resolve in time');
}
}

Expand Down
44 changes: 22 additions & 22 deletions tests/strategy-operations/date.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,69 @@ describe('Processing strategy: DATE', () => {
activated: true,
});

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

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

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

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

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

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

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

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

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

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

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

Expand Down
34 changes: 17 additions & 17 deletions tests/strategy-operations/network.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,57 @@ describe('Processing strategy: NETWORK', () => {
activated: true,
});

it('should agree when input range EXIST', async () => {
it('should agree when input range EXIST', () => {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
const result = await processOperation(strategyConfig, '10.0.0.3');
const result = processOperation(strategyConfig, '10.0.0.3');
assert.isTrue(result);
});

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

it('should NOT agree when input range DOES NOT EXIST', async () => {
it('should NOT agree when input range DOES NOT EXIST', () => {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
const result = await processOperation(strategyConfig, '10.0.0.4');
const result = processOperation(strategyConfig, '10.0.0.4');
assert.isFalse(result);
});

it('should agree when input DOES NOT EXIST', async () => {
it('should agree when input DOES NOT EXIST', () => {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values1);
const result = await processOperation(strategyConfig, '10.0.0.4');
const result = processOperation(strategyConfig, '10.0.0.4');
assert.isTrue(result);
});

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

it('should agree when input IP EXIST', async () => {
it('should agree when input IP EXIST', () => {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values3);
const result = await processOperation(strategyConfig, '192.168.56.58');
const result = processOperation(strategyConfig, '192.168.56.58');
assert.isTrue(result);
});

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

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

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

Expand Down
60 changes: 30 additions & 30 deletions tests/strategy-operations/numeric.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,100 +22,100 @@ describe('Processing strategy: NUMERIC', () => {
activated: true,
});

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

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

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

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

it('should agree when input is EQUAL to value', async () => {
it('should agree when input is EQUAL to value', () => {
const strategyConfig = givenStrategyConfig(OperationsType.EQUAL, mock_values1);
const result = await processOperation(strategyConfig, '1');
const result = processOperation(strategyConfig, '1');
assert.isTrue(result);
});

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

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

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

// test decimal
result = await processOperation(strategyConfig, '1.01');
result = processOperation(strategyConfig, '1.01');
assert.isTrue(result);

strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
result = await processOperation(strategyConfig, '1.55');
result = processOperation(strategyConfig, '1.55');
assert.isTrue(result);
});

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

// test decimal
result = await processOperation(strategyConfig, '0.99');
result = processOperation(strategyConfig, '0.99');
assert.isFalse(result);

strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
result = await processOperation(strategyConfig, '1.49');
result = processOperation(strategyConfig, '1.49');
assert.isFalse(result);
});

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

// test decimal
result = await processOperation(strategyConfig, '0.99');
result = processOperation(strategyConfig, '0.99');
assert.isTrue(result);

strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values3);
result = await processOperation(strategyConfig, '1.49');
result = processOperation(strategyConfig, '1.49');
assert.isTrue(result);
});

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

// test decimal
result = await processOperation(strategyConfig, '2.99');
result = processOperation(strategyConfig, '2.99');
assert.isTrue(result);

result = await processOperation(strategyConfig, '1.001');
result = processOperation(strategyConfig, '1.001');
assert.isTrue(result);
});
});
Loading