|
|
|
@ -1,8 +1,8 @@ |
|
|
|
import { DataSourceManager } from '../../../../../src'; |
|
|
|
import { |
|
|
|
DataCondition, |
|
|
|
Expression, |
|
|
|
LogicGroup, |
|
|
|
ExpressionDefinition, |
|
|
|
LogicGroupDefinition, |
|
|
|
} from '../../../../../src/data_sources/model/conditional_variables/DataCondition'; |
|
|
|
import { GenericOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/GenericOperator'; |
|
|
|
import { LogicalOperation } from '../../../../../src/data_sources/model/conditional_variables/operators/LogicalOperator'; |
|
|
|
@ -52,14 +52,14 @@ describe('DataCondition', () => { |
|
|
|
|
|
|
|
describe('Operator Tests', () => { |
|
|
|
test('should evaluate using GenericOperation operators', () => { |
|
|
|
const condition: Expression = { left: 5, operator: GenericOperation.equals, right: 5 }; |
|
|
|
const condition: ExpressionDefinition = { left: 5, operator: GenericOperation.equals, right: 5 }; |
|
|
|
const dataCondition = new DataCondition(condition, 'Equal', 'Not Equal', { em }); |
|
|
|
|
|
|
|
expect(dataCondition.getDataValue()).toBe('Equal'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('equals (false)', () => { |
|
|
|
const condition: Expression = { |
|
|
|
const condition: ExpressionDefinition = { |
|
|
|
left: 'hello', |
|
|
|
operator: GenericOperation.equals, |
|
|
|
right: 'world', |
|
|
|
@ -69,21 +69,21 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should evaluate using StringOperation operators', () => { |
|
|
|
const condition: Expression = { left: 'apple', operator: StringOperation.contains, right: 'app' }; |
|
|
|
const condition: ExpressionDefinition = { left: 'apple', operator: StringOperation.contains, right: 'app' }; |
|
|
|
const dataCondition = new DataCondition(condition, 'Contains', "Doesn't contain", { em }); |
|
|
|
|
|
|
|
expect(dataCondition.getDataValue()).toBe('Contains'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should evaluate using NumberOperation operators', () => { |
|
|
|
const condition: Expression = { left: 10, operator: NumberOperation.lessThan, right: 15 }; |
|
|
|
const condition: ExpressionDefinition = { left: 10, operator: NumberOperation.lessThan, right: 15 }; |
|
|
|
const dataCondition = new DataCondition(condition, 'Valid', 'Invalid', { em }); |
|
|
|
|
|
|
|
expect(dataCondition.getDataValue()).toBe('Valid'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should evaluate using LogicalOperation operators', () => { |
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.and, |
|
|
|
statements: [ |
|
|
|
{ left: true, operator: GenericOperation.equals, right: true }, |
|
|
|
@ -103,7 +103,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should evaluate complex nested conditions', () => { |
|
|
|
const nestedLogicGroup: LogicGroup = { |
|
|
|
const nestedLogicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.or, |
|
|
|
statements: [ |
|
|
|
{ |
|
|
|
@ -124,7 +124,7 @@ describe('DataCondition', () => { |
|
|
|
|
|
|
|
describe('LogicalGroup Tests', () => { |
|
|
|
test('should correctly handle AND logical operator', () => { |
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.and, |
|
|
|
statements: [ |
|
|
|
{ left: true, operator: GenericOperation.equals, right: true }, |
|
|
|
@ -137,7 +137,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should correctly handle OR logical operator', () => { |
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.or, |
|
|
|
statements: [ |
|
|
|
{ left: true, operator: GenericOperation.equals, right: false }, |
|
|
|
@ -150,7 +150,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should correctly handle XOR logical operator', () => { |
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.xor, |
|
|
|
statements: [ |
|
|
|
{ left: true, operator: GenericOperation.equals, right: true }, |
|
|
|
@ -164,7 +164,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should handle nested logical groups', () => { |
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.and, |
|
|
|
statements: [ |
|
|
|
{ left: true, operator: GenericOperation.equals, right: true }, |
|
|
|
@ -183,7 +183,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should handle groups with false conditions', () => { |
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.and, |
|
|
|
statements: [ |
|
|
|
{ left: true, operator: GenericOperation.equals, right: true }, |
|
|
|
@ -199,7 +199,7 @@ describe('DataCondition', () => { |
|
|
|
|
|
|
|
describe('Conditions with dataVariables', () => { |
|
|
|
test('should return "Yes" when dataVariable matches expected value', () => { |
|
|
|
const condition: Expression = { |
|
|
|
const condition: ExpressionDefinition = { |
|
|
|
left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.USER_1.status' }, |
|
|
|
operator: GenericOperation.equals, |
|
|
|
right: 'active', |
|
|
|
@ -210,7 +210,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should return "No" when dataVariable does not match expected value', () => { |
|
|
|
const condition: Expression = { |
|
|
|
const condition: ExpressionDefinition = { |
|
|
|
left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.USER_1.status' }, |
|
|
|
operator: GenericOperation.equals, |
|
|
|
right: 'inactive', |
|
|
|
@ -222,7 +222,7 @@ describe('DataCondition', () => { |
|
|
|
|
|
|
|
// TODO: unskip after adding UndefinedOperator
|
|
|
|
test.skip('should handle missing data variable gracefully', () => { |
|
|
|
const condition: Expression = { |
|
|
|
const condition: ExpressionDefinition = { |
|
|
|
left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.not_a_user.status' }, |
|
|
|
operator: GenericOperation.isDefined, |
|
|
|
right: undefined, |
|
|
|
@ -233,7 +233,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should correctly compare numeric values from dataVariables', () => { |
|
|
|
const condition: Expression = { |
|
|
|
const condition: ExpressionDefinition = { |
|
|
|
left: { type: DataVariableType, path: 'USER_STATUS_SOURCE.USER_1.age' }, |
|
|
|
operator: NumberOperation.greaterThan, |
|
|
|
right: 24, |
|
|
|
@ -249,7 +249,7 @@ describe('DataCondition', () => { |
|
|
|
}; |
|
|
|
dsm.add(dataSource2); |
|
|
|
|
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.and, |
|
|
|
statements: [ |
|
|
|
{ |
|
|
|
@ -270,7 +270,7 @@ describe('DataCondition', () => { |
|
|
|
}); |
|
|
|
|
|
|
|
test('should handle nested logical conditions with data variables', () => { |
|
|
|
const logicGroup: LogicGroup = { |
|
|
|
const logicGroup: LogicGroupDefinition = { |
|
|
|
logicalOperator: LogicalOperation.or, |
|
|
|
statements: [ |
|
|
|
{ |
|
|
|
|