Compare commits

...

3 Commits

Author SHA1 Message Date
Joshi
fe065d9185 Fixes erroneous result calculation for different data sets. 2020-04-08 17:01:33 -07:00
Joshi
ebc5695720 Removes unecessarily complex check 2020-04-08 15:25:28 -07:00
Joshi
c66f0bc4d1 Enum comparisons use string values. 2020-04-08 15:18:03 -07:00
3 changed files with 91 additions and 20 deletions

View File

@@ -185,11 +185,22 @@ export default class ConditionManager extends EventEmitter {
}
getCurrentCondition(conditionResults) {
let keys = Object.keys(conditionResults);
if (keys.length) {
let timestamp = conditionResults[keys[0]].utc;
for (let i=1; i < keys.length; i++) {
if (timestamp !== conditionResults[keys[i]].utc) {
return;
}
}
}
const conditionCollection = this.conditionSetDomainObject.configuration.conditionCollection;
let currentCondition = conditionCollection[conditionCollection.length-1];
for (let i = 0; i < conditionCollection.length - 1; i++) {
if (conditionResults[conditionCollection[i].id]) {
if (conditionResults[conditionCollection[i].id].result) {
//first condition to be true wins
currentCondition = conditionCollection[i];
break;
@@ -206,26 +217,28 @@ export default class ConditionManager extends EventEmitter {
const id = resultObj.id;
if (this.findConditionById(id)) {
this.conditionResults[id] = resultObj.data.result;
this.conditionResults[id] = resultObj.data;
}
}
handleConditionResult(resultObj) {
this.updateConditionResults(resultObj);
const currentCondition = this.getCurrentCondition(this.conditionResults);
const timestamp = JSON.parse(JSON.stringify(resultObj.data))
delete timestamp.result
const currentCondition = this.getCurrentCondition(Object.assign(this.conditionResults));
if (currentCondition) {
const timestamp = JSON.parse(JSON.stringify(resultObj.data));
delete timestamp.result;
this.emit('conditionSetResultUpdated',
Object.assign(
{
output: currentCondition.configuration.output,
id: this.conditionSetDomainObject.identifier,
conditionId: currentCondition.id
},
timestamp
)
)
this.emit('conditionSetResultUpdated',
Object.assign(
{
output: currentCondition.configuration.output,
id: this.conditionSetDomainObject.identifier,
conditionId: currentCondition.id
},
timestamp
)
);
}
}
requestLADConditionSetOutput() {

View File

@@ -214,7 +214,9 @@ export const OPERATIONS = [
{
name: 'enumValueIs',
operation: function (input) {
return input[0] === input[1];
let stringInputs = [];
input.forEach(inputValue => stringInputs.push(inputValue !== undefined ? inputValue.toString() : ''));
return stringInputs[0] === stringInputs[1];
},
text: 'is',
appliesTo: ['enum'],
@@ -226,7 +228,9 @@ export const OPERATIONS = [
{
name: 'enumValueIsNot',
operation: function (input) {
return input[0] !== input[1];
let stringInputs = [];
input.forEach(inputValue => stringInputs.push(inputValue !== undefined ? inputValue.toString() : ''));
return stringInputs[0] !== stringInputs[1];
},
text: 'is not',
appliesTo: ['enum'],
@@ -238,9 +242,10 @@ export const OPERATIONS = [
{
name: 'valueIs',
operation: function (input) {
const lhsValue = input[0] !== undefined ? input[0].toString() : '';
if (input[1]) {
const values = input[1].split(',');
return values.find((value) => input[0].toString() === _.trim(value.toString()));
return values.find((value) => lhsValue === _.trim(value.toString()));
}
return false;
},
@@ -254,9 +259,10 @@ export const OPERATIONS = [
{
name: 'valueIsNot',
operation: function (input) {
const lhsValue = input[0] !== undefined ? input[0].toString() : '';
if (input[1]) {
const values = input[1].split(',');
const found = values.find((value) => input[0].toString() === _.trim(value.toString()));
const found = values.find((value) => lhsValue === _.trim(value.toString()));
return !found;
}
return false;

View File

@@ -25,8 +25,10 @@ let isOneOfOperation = OPERATIONS.find((operation) => operation.name === 'valueI
let isNotOneOfOperation = OPERATIONS.find((operation) => operation.name === 'valueIsNot');
let isBetween = OPERATIONS.find((operation) => operation.name === 'between');
let isNotBetween = OPERATIONS.find((operation) => operation.name === 'notBetween');
let enumIsOperation = OPERATIONS.find((operation) => operation.name === 'enumValueIs');
let enumIsNotOperation = OPERATIONS.find((operation) => operation.name === 'enumValueIsNot');
describe('Is one of and is not one of operations', function () {
describe('operations', function () {
it('should evaluate isOneOf to true for number inputs', () => {
const inputs = [45, "5,6,45,8"];
@@ -87,4 +89,54 @@ describe('Is one of and is not one of operations', function () {
const inputs = ["45", "30", "50"];
expect(!!isNotBetween.operation(inputs)).toBeFalse();
});
it('should evaluate enumValueIs to true for number inputs', () => {
const inputs = [1, "1"];
expect(!!enumIsOperation.operation(inputs)).toBeTrue();
});
it('should evaluate enumValueIs to true for string inputs', () => {
const inputs = ["45", "45"];
expect(!!enumIsOperation.operation(inputs)).toBeTrue();
});
it('should evaluate enumValueIsNot to true for number inputs', () => {
const inputs = [45, "46"];
expect(!!enumIsNotOperation.operation(inputs)).toBeTrue();
});
it('should evaluate enumValueIsNot to true for string inputs', () => {
const inputs = ["45", "46"];
expect(!!enumIsNotOperation.operation(inputs)).toBeTrue();
});
it('should evaluate enumValueIs to false for number inputs', () => {
const inputs = [1, "2"];
expect(!!enumIsOperation.operation(inputs)).toBeFalse();
});
it('should evaluate enumValueIs to false for string inputs', () => {
const inputs = ["45", "46"];
expect(!!enumIsOperation.operation(inputs)).toBeFalse();
});
it('should evaluate enumValueIsNot to false for number inputs', () => {
const inputs = [45, "45"];
expect(!!enumIsNotOperation.operation(inputs)).toBeFalse();
});
it('should evaluate enumValueIsNot to false for string inputs', () => {
const inputs = ["45", "45"];
expect(!!enumIsNotOperation.operation(inputs)).toBeFalse();
});
it('should evaluate enumValueIs to false for undefined input', () => {
const inputs = [undefined, "45"];
expect(!!enumIsOperation.operation(inputs)).toBeFalse();
});
it('should evaluate enumValueIsNot to true for undefined input', () => {
const inputs = [undefined, "45"];
expect(!!enumIsNotOperation.operation(inputs)).toBeTrue();
});
});