Skip to content

Commit 21e9283

Browse files
authored
Merge pull request #13 from shelfio/feature/DECTREEAPI-235-fix-joiners
DECTREEAPI-235 Joiners `AND`, `OR` replaced w/ `and`, `or`
2 parents 7e62efd + 427a309 commit 21e9283

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/evaluation.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type {Expression} from './types';
22
import {expressionToRPN} from './evaluation';
33

44
const baseExpression: Expression = {
5-
joiner: 'AND',
5+
joiner: 'and',
66
rules: [
77
{
8-
joiner: 'OR',
8+
joiner: 'or',
99
rules: [
1010
{
1111
variableId: 'variable-id-c',
@@ -28,10 +28,10 @@ const baseExpression: Expression = {
2828
};
2929

3030
const notBinaryExpression: Expression = {
31-
joiner: 'AND',
31+
joiner: 'and',
3232
rules: [
3333
{
34-
joiner: 'OR',
34+
joiner: 'or',
3535
rules: [
3636
{
3737
variableId: 'variable-id-c',
@@ -203,12 +203,12 @@ describe('expressionToRPN', () => {
203203

204204
it('should return `[true]` for complex expression', () => {
205205
const complexExpression: Expression = {
206-
joiner: 'AND',
206+
joiner: 'and',
207207
rules: [
208208
baseExpression,
209209
singleRuleExpression,
210210
{
211-
joiner: 'OR',
211+
joiner: 'or',
212212
rules: [
213213
notBinaryExpression,
214214
{
@@ -230,12 +230,12 @@ describe('expressionToRPN', () => {
230230

231231
it('should return `[false]` for complex expression', () => {
232232
const complexExpression: Expression = {
233-
joiner: 'AND',
233+
joiner: 'and',
234234
rules: [
235235
baseExpression,
236236
singleRuleExpression,
237237
{
238-
joiner: 'AND',
238+
joiner: 'and',
239239
rules: [
240240
notBinaryExpression,
241241
{

src/evaluation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type {JoinerParameters, RuleParameters} from './types';
33
import {validateJoinerInvoke, validateRuleInvoke} from './validations';
44

55
export const joinerHandlers = {
6-
OR: ({left, right}: JoinerParameters) => Boolean(left || right),
7-
AND: ({left, right}: JoinerParameters) => Boolean(left && right),
8-
SINGLE: ({left}: JoinerParameters) => Boolean(left),
6+
or: ({left, right}: JoinerParameters) => Boolean(left || right),
7+
and: ({left, right}: JoinerParameters) => Boolean(left && right),
8+
single: ({left}: JoinerParameters) => Boolean(left),
99
};
1010

1111
export const ruleHandlers = {
@@ -31,7 +31,7 @@ export const expressionToRPN = (
3131

3232
validateJoinerInvoke({joiner, left, right});
3333

34-
rpn.push(joinerHandlers[joiner ?? 'SINGLE']({left, right}));
34+
rpn.push(joinerHandlers[joiner ?? 'single']({left, right}));
3535

3636
return rpn;
3737
}

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export type Rule = {
44
value: string;
55
};
66
export type Expression = {
7-
joiner?: 'OR' | 'AND';
7+
joiner?: 'or' | 'and';
88
rules: (Expression | Rule)[];
99
};
1010
export type VariableWithValue = {id: string; value: string};
1111
export type JoinerParameters = {left: StackElement; right: StackElement};
12-
export type StackElement = boolean | 'OR' | 'AND';
12+
export type StackElement = boolean | Expression['joiner'];
1313
export type RuleParameters = {passedValue?: string; comparedValue: string};

src/validations.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ describe('validateJoinerInvoke', () => {
44
it('should throw error if joiner is not SINGLE and left is undefined', () => {
55
expect(() =>
66
validateJoinerInvoke({
7-
joiner: 'AND',
7+
joiner: 'and',
88
left: true,
99
right: undefined as any,
1010
})
11-
).toThrow('Invalid Joiner expression "true AND undefined"');
11+
).toThrow('Invalid Joiner expression "true and undefined"');
1212
});
1313

1414
it('should throw error if joiner is not SINGLE and right is undefined', () => {
1515
expect(() =>
1616
validateJoinerInvoke({
17-
joiner: 'AND',
17+
joiner: 'and',
1818
left: undefined as any,
1919
right: true,
2020
})
21-
).toThrow('Invalid Joiner expression "undefined AND true"');
21+
).toThrow('Invalid Joiner expression "undefined and true"');
2222
});
2323
});
2424

0 commit comments

Comments
 (0)