From 90d795cc691111f34c6b7cfacf778169255297ee Mon Sep 17 00:00:00 2001 From: Stephanie Yang Date: Fri, 4 Jun 2021 16:46:52 -0500 Subject: [PATCH] update stringifyRowData tests --- .../App/QueryBuilder/stringifyRowData.test.ts | 482 +++++++++++++++++- 1 file changed, 458 insertions(+), 24 deletions(-) diff --git a/lattice/src/App/QueryBuilder/stringifyRowData.test.ts b/lattice/src/App/QueryBuilder/stringifyRowData.test.ts index 4ace4d7a9..d6cb4b586 100644 --- a/lattice/src/App/QueryBuilder/stringifyRowData.test.ts +++ b/lattice/src/App/QueryBuilder/stringifyRowData.test.ts @@ -1,13 +1,14 @@ import { stringifyRowData } from './stringifyRowData'; -describe('int types', () => { +describe('decimal types', () => { it('stringifies = operator', () => { expect(stringifyRowData([{ row: [{ "field": "fieldName", "rowOperator": "=", "value": "0", - "type": "int" + "type": "decimal", + "keys": undefined }] }])).toEqual({ error: false, query: 'Row(fieldName=0)' }) }); @@ -18,7 +19,8 @@ describe('int types', () => { "field": "fieldName", "rowOperator": "!=", "value": "0", - "type": "int" + "type": "decimal", + "keys": undefined }] }])).toEqual({ error: false, query: 'Not(Row(fieldName=0))' }) }); @@ -29,7 +31,8 @@ describe('int types', () => { "field": "fieldName", "rowOperator": ">", "value": "0", - "type": "int" + "type": "decimal", + "keys": undefined }] }])).toEqual({ error: false, query: 'Row(fieldName>0)' }) }); @@ -40,32 +43,148 @@ describe('int types', () => { "field": "fieldName", "rowOperator": ">=", "value": "0", - "type": "int" + "type": "decimal", + "keys": undefined }] }])).toEqual({ error: false, query: 'Row(fieldName>=0)' }) }); - it('stringifies negated operatorations', () => { + it('stringifies negated operations', () => { expect(stringifyRowData([{ row: [{ "field": "fieldName", "rowOperator": ">=", "value": "0", - "type": "int" + "type": "decimal", + "keys": undefined }], isNot: true }])).toEqual({ error: false, query: 'Not(Row(fieldName>=0))' }) }); -}) +}); -describe('set types', () => { +describe('int types', () => { + it('stringifies = operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "0", + "type": "int", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Row(fieldName=0)' }) + }); + + it('stringifies != operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "0", + "type": "int", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Not(Row(fieldName=0))' }) + }); + + it('stringifies > operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": ">", + "value": "0", + "type": "int", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Row(fieldName>0)' }) + }); + + it('stringifies >= operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": ">=", + "value": "0", + "type": "int", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Row(fieldName>=0)' }) + }); + + it('stringifies negated operations', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": ">=", + "value": "0", + "type": "int", + "keys": undefined + }], + isNot: true + }])).toEqual({ error: false, query: 'Not(Row(fieldName>=0))' }) + }); +}); + +describe('mutex (id) types', () => { + it('stringifies is operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234", + "type": "mutex", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Row(fieldName=1234)' }) + }); + + it('stringifies is operator for multiple values', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234, 5678", + "type": "mutex", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Union(Row(fieldName=1234), Row(fieldName=5678))' }) + }); + + it('stringifies is not operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "1234", + "type": "mutex", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Not(Row(fieldName=1234))' }) + }); + + it('stringifies is not operator for multiple values', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "1234, 5678", + "type": "mutex", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Not(Union(Row(fieldName=1234), Row(fieldName=5678)))' }) + }); +}); + +describe('mutex (keys) types', () => { it('stringifies is operator', () => { expect(stringifyRowData([{ row: [{ "field": "fieldName", "rowOperator": "=", "value": "value", - "type": "set" + "type": "mutex", + "keys": true }] }])).toEqual({ error: false, query: 'Row(fieldName="value")' }) }); @@ -76,7 +195,8 @@ describe('set types', () => { "field": "fieldName", "rowOperator": "=", "value": "one, two", - "type": "set" + "type": "mutex", + "keys": true }] }])).toEqual({ error: false, query: 'Union(Row(fieldName="one"), Row(fieldName="two"))' }) }); @@ -87,7 +207,8 @@ describe('set types', () => { "field": "fieldName", "rowOperator": "!=", "value": "value", - "type": "set" + "type": "mutex", + "keys": true }] }])).toEqual({ error: false, query: 'Not(Row(fieldName="value"))' }) }); @@ -98,7 +219,8 @@ describe('set types', () => { "field": "fieldName", "rowOperator": "!=", "value": "one, two", - "type": "set" + "type": "mutex", + "keys": true }] }])).toEqual({ error: false, query: 'Not(Union(Row(fieldName="one"), Row(fieldName="two")))' }) }); @@ -109,7 +231,8 @@ describe('set types', () => { "field": "fieldName", "rowOperator": "like", "value": "value%", - "type": "set" + "type": "mutex", + "keys": true }] }])).toEqual({ error: false, query: 'UnionRows(Rows(field=fieldName, like="value%"))' }) }); @@ -120,7 +243,8 @@ describe('set types', () => { "field": "fieldName", "rowOperator": "like", "value": "value", - "type": "set" + "type": "mutex", + "keys": true }] }])).toEqual({ error: false, query: 'UnionRows(Rows(field=fieldName, like="%value%"))' }) }); @@ -131,24 +255,328 @@ describe('set types', () => { "field": "fieldName", "rowOperator": "cidr", "value": "10.164.124.33/30", - "type": "set" + "type": "mutex", + "keys": true }] }])).toEqual({ error: false, query: 'Union(Row(fieldName="10.164.124.32"), Row(fieldName="10.164.124.33"), Row(fieldName="10.164.124.34"), Row(fieldName="10.164.124.35"))' }) }); - it('stringifies negated operatorations', () => { + it('stringifies negated operations', () => { expect(stringifyRowData([{ row: [{ "field": "fieldName", "rowOperator": "like", "value": "value", - "type": "set" + "type": "mutex", + "keys": true }], isNot: true }])).toEqual({ error: false, query: 'Not(UnionRows(Rows(field=fieldName, like="%value%")))' }) }); }); +describe('set (id) types', () => { + it('stringifies is operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234", + "type": "set", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Row(fieldName=1234)' }) + }); + + it('stringifies is operator for multiple values', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234, 5678", + "type": "set", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Union(Row(fieldName=1234), Row(fieldName=5678))' }) + }); + + it('stringifies is not operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "1234", + "type": "set", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Not(Row(fieldName=1234))' }) + }); + + it('stringifies is not operator for multiple values', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "1234, 5678", + "type": "set", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Not(Union(Row(fieldName=1234), Row(fieldName=5678)))' }) + }); +}); + +describe('set (keys) types', () => { + it('stringifies is operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "value", + "type": "set", + "keys": true + }] + }])).toEqual({ error: false, query: 'Row(fieldName="value")' }) + }); + + it('stringifies is operator for multiple values', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "one, two", + "type": "set", + "keys": true + }] + }])).toEqual({ error: false, query: 'Union(Row(fieldName="one"), Row(fieldName="two"))' }) + }); + + it('stringifies is not operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "value", + "type": "set", + "keys": true + }] + }])).toEqual({ error: false, query: 'Not(Row(fieldName="value"))' }) + }); + + it('stringifies is not operator for multiple values', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "one, two", + "type": "set", + "keys": true + }] + }])).toEqual({ error: false, query: 'Not(Union(Row(fieldName="one"), Row(fieldName="two")))' }) + }); + + it('stringifies like operator with a wildcard', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "like", + "value": "value%", + "type": "set", + "keys": true + }] + }])).toEqual({ error: false, query: 'UnionRows(Rows(field=fieldName, like="value%"))' }) + }); + + it('stringifies like operator without a wildcard', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "like", + "value": "value", + "type": "set", + "keys": true + }] + }])).toEqual({ error: false, query: 'UnionRows(Rows(field=fieldName, like="%value%"))' }) + }); + + it('stringifies CIDR operator', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "cidr", + "value": "10.164.124.33/30", + "type": "set", + "keys": true + }] + }])).toEqual({ error: false, query: 'Union(Row(fieldName="10.164.124.32"), Row(fieldName="10.164.124.33"), Row(fieldName="10.164.124.34"), Row(fieldName="10.164.124.35"))' }) + }); + + it('stringifies negated operations', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "like", + "value": "value", + "type": "set", + "keys": true + }], + isNot: true + }])).toEqual({ error: false, query: 'Not(UnionRows(Rows(field=fieldName, like="%value%")))' }) + }); +}); + +describe('time (ID) types', () => { + it('stringifies is operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234", + "type": "time", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Row(fieldName=1234)' }) + }); + + it('stringifies is not operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "1234", + "type": "time", + "keys": undefined + }] + }])).toEqual({ error: false, query: 'Not(Row(fieldName=1234))' }) + }); + + it('stringifies negated operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234", + "type": "time", + "keys": undefined + }], + isNot: true + }])).toEqual({ error: false, query: 'Not(Row(fieldName=1234))' }) + }); +}); + +describe('time (keys) types', () => { + it('stringifies is operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234", + "type": "time", + "keys": true + }] + }])).toEqual({ error: false, query: 'Row(fieldName="1234")' }) + }); + + it('stringifies is not operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "!=", + "value": "1234", + "type": "time", + "keys": true + }] + }])).toEqual({ error: false, query: 'Not(Row(fieldName="1234"))' }) + }); + + it('stringifies like operators with a wildcard', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "like", + "value": "%1234", + "type": "time", + "keys": true + }] + }])).toEqual({ error: false, query: 'UnionRows(Rows(field=fieldName, like="%1234"))' }) + }); + + it('stringifies like operators without a wildcard', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "like", + "value": "1234", + "type": "time", + "keys": true + }] + }])).toEqual({ error: false, query: 'UnionRows(Rows(field=fieldName, like="%1234%"))' }) + }); + + it('stringifies negated operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "1234", + "type": "time", + "keys": true + }], + isNot: true + }])).toEqual({ error: false, query: 'Not(Row(fieldName="1234"))' }) + }); +}); + +describe('timestamp types', () => { + it('stringifies is operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "2021-06-04T12:00:00Z", + "type": "timestamp", + "keys": undefined + }], + }])).toEqual({ error: false, query: 'Row(fieldName="2021-06-04T12:00:00Z")' }) + }); + + it('stringifies is before operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "<", + "value": "2021-06-04T12:00:00Z", + "type": "timestamp", + "keys": undefined + }], + }])).toEqual({ error: false, query: 'Row(fieldName<"2021-06-04T12:00:00Z")' }) + }); + + it('stringifies is after operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": ">", + "value": "2021-06-04T12:00:00Z", + "type": "timestamp", + "keys": undefined + }], + }])).toEqual({ error: false, query: 'Row(fieldName>"2021-06-04T12:00:00Z")' }) + }); + + it('stringifies negated operators', () => { + expect(stringifyRowData([{ + row: [{ + "field": "fieldName", + "rowOperator": "=", + "value": "2021-06-04T12:00:00Z", + "type": "timestamp", + "keys": undefined + }], + isNot: true + }])).toEqual({ error: false, query: 'Not(Row(fieldName="2021-06-04T12:00:00Z"))' }) + }); +}); + describe('mixed types', () => { it('stringifies multiple and-ed rows', () => { expect(stringifyRowData([{ @@ -156,12 +584,14 @@ describe('mixed types', () => { "field": "stringType", "rowOperator": "like", "value": "value", - "type": "set" + "type": "set", + "keys": true }, { "field": "intType", "rowOperator": "=", "value": "0", - "type": "int" + "type": "int", + "keys": undefined }], operator: "and" }])).toEqual({ error: false, query: 'Intersect(UnionRows(Rows(field=stringType, like="%value%")), Row(intType=0))' }) @@ -173,12 +603,14 @@ describe('mixed types', () => { "field": "stringType", "rowOperator": "like", "value": "value", - "type": "set" + "type": "set", + "keys": true }, { "field": "intType", "rowOperator": "=", "value": "0", - "type": "int" + "type": "int", + "keys": undefined }], operator: "or" }])).toEqual({ error: false, query: 'Union(UnionRows(Rows(field=stringType, like="%value%")), Row(intType=0))' }) @@ -190,12 +622,14 @@ describe('mixed types', () => { "field": "stringType", "rowOperator": "like", "value": "value", - "type": "set" + "type": "set", + "keys": true }, { "field": "intType", "rowOperator": "=", "value": "0", - "type": "int" + "type": "int", + "keys": undefined }], operator: "or", isNot: true