Skip to content

Commit 20adc7c

Browse files
committed
feat: Removed validation 'should throw error if passedValue is undefined'
1 parent df02054 commit 20adc7c

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

src/evaluation.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ describe('expressionToRPN', () => {
127127
expect(expressionToRPN(expression, variablesValueMap)).toEqual([false]);
128128
});
129129

130+
it('should return `[false]` when variables value not passed', () => {
131+
const variablesValueMap = new Map();
132+
133+
const expression: Expression = {
134+
rules: [
135+
{
136+
variableId: 'variable-id-a',
137+
operator: 'eq',
138+
value: 'a',
139+
},
140+
],
141+
};
142+
143+
expect(expressionToRPN(expression, variablesValueMap)).toEqual([false]);
144+
});
145+
130146
const variableValueSomething = new Map([['variable-id-a', 'something']]);
131147

132148
it('should return `[true]` for expression and `contains` rule', () => {

src/evaluation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const expressionToRPN = (
3838
const {variableId, operator, value: comparedValue} = expression;
3939
const passedValue = variableIdToValuesMap.get(variableId);
4040

41-
validateRuleInvoke({operator, comparedValue, passedValue, variableId});
41+
validateRuleInvoke({operator, comparedValue});
4242

4343
return [
4444
ruleHandlers[operator]({

src/validations.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ describe('validateRuleInvoke', () => {
2828
validateRuleInvoke({
2929
comparedValue: undefined as any,
3030
operator: 'eq',
31-
passedValue: 'a',
32-
variableId: 'variable-id-a',
3331
})
3432
).toThrow('Invalid Rule compared value not exist');
3533
});
@@ -39,20 +37,7 @@ describe('validateRuleInvoke', () => {
3937
validateRuleInvoke({
4038
comparedValue: 'a',
4139
operator: undefined as any,
42-
passedValue: 'a',
43-
variableId: 'variable-id-a',
4440
})
4541
).toThrow('Invalid Rule operator not exist');
4642
});
47-
48-
it('should throw error if passedValue is undefined', () => {
49-
expect(() =>
50-
validateRuleInvoke({
51-
comparedValue: 'a',
52-
operator: 'eq',
53-
passedValue: undefined as any,
54-
variableId: 'variable-id-a',
55-
})
56-
).toThrow('Invalid passed variable value with id: variable-id-a');
57-
});
5843
});

src/validations.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ export const validateJoinerInvoke = ({
1313
};
1414

1515
export const validateRuleInvoke = ({
16-
passedValue,
17-
variableId,
1816
operator,
1917
comparedValue,
2018
}: {
2119
comparedValue: string;
2220
operator?: Rule['operator'];
23-
passedValue?: string;
24-
variableId: string;
2521
}) => {
2622
if (comparedValue === undefined) {
2723
throw new Error(`Invalid Rule compared value not exist`, {
@@ -34,10 +30,4 @@ export const validateRuleInvoke = ({
3430
cause: 'invalid-expression',
3531
});
3632
}
37-
38-
if (passedValue === undefined) {
39-
throw new Error(`Invalid passed variable value with id: ${variableId}`, {
40-
cause: 'invalid-expression',
41-
});
42-
}
4333
};

0 commit comments

Comments
 (0)