Browse Source

test: filter for numeric types

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5029/head
Raju Udava 2 years ago
parent
commit
3d476125e5
  1. 25
      packages/nocodb/tests/unit/factory/row.ts
  2. 874
      packages/nocodb/tests/unit/rest/tests/filter.test.ts

25
packages/nocodb/tests/unit/factory/row.ts

@ -61,7 +61,22 @@ const rowMixedValue = (column: ColumnType, index: number) => {
]; ];
// Array of random integers, not more than 10000 // Array of random integers, not more than 10000
const numbers = [33, 456, 54, 267, 34, 8754, 3234, 44, 33, null]; const numbers = [33, null, 456, 333, 267, 34, 8754, 3234, 44, 33, null];
const decimals = [
33.3,
456.34,
333.3,
null,
267.5674,
34.0,
8754.0,
3234.547,
44.2647,
33.98,
null,
];
const duration = [10, 20, 30, 40, 50, 60, null, 70, 80, 90, null];
const rating = [0, 1, 2, 3, null, 0, 4, 5, 0, 1, null];
// Array of random sample email strings (not more than 100 characters) // Array of random sample email strings (not more than 100 characters)
const emails = [ const emails = [
@ -115,7 +130,15 @@ const rowMixedValue = (column: ColumnType, index: number) => {
switch (column.uidt) { switch (column.uidt) {
case UITypes.Number: case UITypes.Number:
case UITypes.Percent:
return numbers[index % numbers.length]; return numbers[index % numbers.length];
case UITypes.Decimal:
case UITypes.Currency:
return decimals[index % decimals.length];
case UITypes.Duration:
return duration[index % duration.length];
case UITypes.Rating:
return rating[index % rating.length];
case UITypes.SingleLineText: case UITypes.SingleLineText:
return countries[index % countries.length]; return countries[index % countries.length];
case UITypes.Email: case UITypes.Email:

874
packages/nocodb/tests/unit/rest/tests/filter.test.ts

@ -16,15 +16,67 @@ import Model from '../../../../src/lib/models/Model';
import { expect } from 'chai'; import { expect } from 'chai';
import request from 'supertest'; import request from 'supertest';
const debugMode = true;
// Test case list // Test case list
function filterTests() { async function retrieveRecordsAndValidate(
filter: {
comparison_op: string;
value: string;
fk_column_id: any;
status: string;
logical_op: string;
},
expectedRecords: any[],
title: string
) {
// retrieve filtered records
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${project.id}/${table.id}`)
.set('xc-auth', context.token)
.query({
filterArrJson: JSON.stringify([filter]),
})
.expect(200);
// validate
if (debugMode) {
if (response.body.pageInfo.totalRows !== expectedRecords.length) {
console.log(`Failed for filter: ${JSON.stringify(filter)}`);
console.log(`Expected: ${expectedRecords.length}`);
console.log(`Actual: ${response.body.pageInfo.totalRows}`);
throw new Error('fix me!');
}
response.body.list.forEach((row, index) => {
if (row[title] !== expectedRecords[index][title]) {
console.log(`Failed for filter: ${JSON.stringify(filter)}`);
console.log(`Expected: ${expectedRecords[index][title]}`);
console.log(`Actual: ${row[title]}`);
throw new Error('fix me!');
}
});
} else {
expect(response.body.pageInfo.totalRows).to.equal(expectedRecords.length);
response.body.list.forEach((row, index) => {
expect(row[title] !== expectedRecords[index][title]);
});
}
}
let context; let context;
let project: Project; let project: Project;
let table: Model; let table: Model;
let columns: any[]; let columns: any[];
let unfilteredRecords: any[] = []; let unfilteredRecords: any[] = [];
function filterTextBased() {
// let context;
// let project: Project;
// let table: Model;
// let columns: any[];
// let unfilteredRecords: any[] = [];
// prepare data for test cases // prepare data for test cases
beforeEach(async function () { beforeEach(async function () {
context = await init(); context = await init();
@ -91,36 +143,55 @@ function filterTests() {
expect(unfilteredRecords.length).to.equal(400); expect(unfilteredRecords.length).to.equal(400);
}); });
async function retrieveRecordsAndValidate( // async function retrieveRecordsAndValidate(
filter: { // filter: {
comparison_op: string; // comparison_op: string;
value: string; // value: string;
fk_column_id: any; // fk_column_id: any;
status: string; // status: string;
logical_op: string; // logical_op: string;
}, // },
expectedRecords: any[] // expectedRecords: any[]
) { // ) {
// retrieve filtered records // // retrieve filtered records
const response = await request(context.app) // const response = await request(context.app)
.get(`/api/v1/db/data/noco/${project.id}/${table.id}`) // .get(`/api/v1/db/data/noco/${project.id}/${table.id}`)
.set('xc-auth', context.token) // .set('xc-auth', context.token)
.query({ // .query({
filterArrJson: JSON.stringify([filter]), // filterArrJson: JSON.stringify([filter]),
}) // })
.expect(200); // .expect(200);
//
// validate // // validate
expect(response.body.pageInfo.totalRows).to.equal(expectedRecords.length); // if (debugMode) {
response.body.list.forEach((row, index) => { // if (response.body.pageInfo.totalRows !== expectedRecords.length) {
expect(row[columns[1].title] !== expectedRecords[index].SingleLineText); // console.log(`Failed for filter: ${JSON.stringify(filter)}`);
}); // console.log(`Expected: ${expectedRecords.length}`);
} // console.log(`Actual: ${response.body.pageInfo.totalRows}`);
// throw new Error('fix me!');
// }
// response.body.list.forEach((row, index) => {
// if (row[columns[1].title] !== expectedRecords[index].SingleLineText) {
// console.log(`Failed for filter: ${JSON.stringify(filter)}`);
// console.log(`Expected: ${expectedRecords[index].SingleLineText}`);
// console.log(`Actual: ${row[columns[1].title]}`);
// throw new Error('fix me!');
// }
// });
// } else {
// expect(response.body.pageInfo.totalRows).to.equal(expectedRecords.length);
// response.body.list.forEach((row, index) => {
// expect(row[columns[1].title] !== expectedRecords[index].SingleLineText);
// });
// }
// }
it('Type: Single Line Text', async () => { it('Type: Single Line Text', async () => {
// filter types to be verified // filter types to be verified
// eq, neq, null, notnull, empty, notempty, like, nlike // eq, neq, null, notnull, empty, notempty, like, nlike
const dataType = 'SingleLineText';
const filter = { const filter = {
fk_column_id: columns[1].id, fk_column_id: columns[1].id,
status: 'create', status: 'create',
@ -130,63 +201,780 @@ function filterTests() {
}; };
let expectedRecords = unfilteredRecords.filter( let expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText === 'Afghanistan' (record) => record[dataType] === 'Afghanistan'
); );
await retrieveRecordsAndValidate(filter, expectedRecords); await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq // filter: neq
filter.comparison_op = 'neq'; filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter( expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText !== 'Afghanistan' (record) => record[dataType] !== 'Afghanistan'
); );
await retrieveRecordsAndValidate(filter, expectedRecords); await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null // filter: null
filter.comparison_op = 'null'; filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter( expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText === null (record) => record[dataType] === null
); );
await retrieveRecordsAndValidate(filter, expectedRecords); await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull // filter: notnull
filter.comparison_op = 'notnull'; filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter( expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText !== null (record) => record[dataType] !== null
); );
await retrieveRecordsAndValidate(filter, expectedRecords); await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: empty // filter: empty
filter.comparison_op = 'empty'; filter.comparison_op = 'empty';
expectedRecords = unfilteredRecords.filter( expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText === '' (record) => record[dataType] === ''
); );
await retrieveRecordsAndValidate(filter, expectedRecords); await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notempty // filter: notempty
filter.comparison_op = 'notempty'; filter.comparison_op = 'notempty';
expectedRecords = unfilteredRecords.filter( expectedRecords = unfilteredRecords.filter(
(record) => record.SingleLineText !== '' (record) => record[dataType] !== ''
); );
//TBD await retrieveRecordsAndValidate(filter, expectedRecords); //TBD await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: like // filter: like
filter.comparison_op = 'like'; filter.comparison_op = 'like';
filter.value = 'Au'; filter.value = 'Au';
expectedRecords = unfilteredRecords.filter((record) => expectedRecords = unfilteredRecords.filter((record) =>
record.SingleLineText?.includes('Au') record[dataType]?.includes('Au')
); );
await retrieveRecordsAndValidate(filter, expectedRecords); await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: nlike // filter: nlike
filter.comparison_op = 'nlike'; filter.comparison_op = 'nlike';
filter.value = 'Au'; filter.value = 'Au';
expectedRecords = unfilteredRecords.filter( expectedRecords = unfilteredRecords.filter(
(record) => !record.SingleLineText?.includes('Au') (record) => !record[dataType]?.includes('Au')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: LongText', async () => {
// filter types to be verified
// eq, neq, null, notnull, empty, notempty, like, nlike
const dataType = 'MultiLineText';
const filter = {
fk_column_id: columns[2].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: 'Aberdeen, United Kingdom',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === 'Aberdeen, United Kingdom'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== 'Aberdeen, United Kingdom'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: empty
filter.comparison_op = 'empty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === ''
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notempty
filter.comparison_op = 'notempty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== ''
);
//TBD await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: like
filter.comparison_op = 'like';
filter.value = 'abad';
expectedRecords = unfilteredRecords.filter((record) =>
record[dataType]?.includes('abad')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: nlike
filter.comparison_op = 'nlike';
filter.value = 'abad';
expectedRecords = unfilteredRecords.filter(
(record) => !record[dataType]?.includes('abad')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: Email', async () => {
// filter types to be verified
// eq, neq, null, notnull, empty, notempty, like, nlike
const dataType = 'Email';
const filter = {
fk_column_id: columns[3].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: 'leota@hotmail.com',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === 'leota@hotmail.com'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== 'leota@hotmail.com'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: empty
filter.comparison_op = 'empty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === ''
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notempty
filter.comparison_op = 'notempty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== ''
);
//TBD await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: like
filter.comparison_op = 'like';
filter.value = 'cox.net';
expectedRecords = unfilteredRecords.filter((record) =>
record[dataType]?.includes('cox.net')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: nlike
filter.comparison_op = 'nlike';
filter.value = 'cox.net';
expectedRecords = unfilteredRecords.filter(
(record) => !record[dataType]?.includes('cox.net')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: Phone', async () => {
// filter types to be verified
// eq, neq, null, notnull, empty, notempty, like, nlike
const dataType = 'Phone';
const filter = {
fk_column_id: columns[4].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: '504-621-8927',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === '504-621-8927'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== '504-621-8927'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: empty
filter.comparison_op = 'empty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === ''
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notempty
filter.comparison_op = 'notempty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== ''
);
//TBD await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: like
filter.comparison_op = 'like';
filter.value = '504';
expectedRecords = unfilteredRecords.filter((record) =>
record[dataType]?.includes('504')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: nlike
filter.comparison_op = 'nlike';
filter.value = '504';
expectedRecords = unfilteredRecords.filter(
(record) => !record[dataType]?.includes('504')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: URL', async () => {
// filter types to be verified
// eq, neq, null, notnull, empty, notempty, like, nlike
const dataType = 'Url';
const filter = {
fk_column_id: columns[5].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: 'https://www.youtube.com',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === 'https://www.youtube.com'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== 'https://www.youtube.com'
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: empty
filter.comparison_op = 'empty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === ''
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notempty
filter.comparison_op = 'notempty';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== ''
);
//TBD await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: like
filter.comparison_op = 'like';
filter.value = 'e.com';
expectedRecords = unfilteredRecords.filter((record) =>
record[dataType]?.includes('e.com')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: nlike
filter.comparison_op = 'nlike';
filter.value = 'e.com';
expectedRecords = unfilteredRecords.filter(
(record) => !record[dataType]?.includes('e.com')
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
}
function filterNumberBased() {
// prepare data for test cases
beforeEach(async function () {
context = await init();
project = await createProject(context);
table = await createTable(context, project, {
table_name: 'numberBased',
title: 'numberBased',
columns: [
{
column_name: 'Id',
title: 'Id',
uidt: UITypes.ID,
},
{
column_name: 'Number',
title: 'Number',
uidt: UITypes.Number,
},
{
column_name: 'Decimal',
title: 'Decimal',
uidt: UITypes.Decimal,
},
{
column_name: 'Currency',
title: 'Currency',
uidt: UITypes.Currency,
},
{
column_name: 'Percent',
title: 'Percent',
uidt: UITypes.Percent,
},
{
column_name: 'Duration',
title: 'Duration',
uidt: UITypes.Duration,
},
{
column_name: 'Rating',
title: 'Rating',
uidt: UITypes.Rating,
},
],
});
columns = await table.getColumns();
let rowAttributes = [];
for (let i = 0; i < 400; i++) {
let row = {
Number: rowMixedValue(columns[1], i),
Decimal: rowMixedValue(columns[2], i),
Currency: rowMixedValue(columns[3], i),
Percent: rowMixedValue(columns[4], i),
Duration: rowMixedValue(columns[5], i),
Rating: rowMixedValue(columns[6], i),
};
rowAttributes.push(row);
}
await createBulkRows(context, {
project,
table,
values: rowAttributes,
});
unfilteredRecords = await listRow({ project, table });
// verify length of unfiltered records to be 400
expect(unfilteredRecords.length).to.equal(400);
});
it('Type: Number', async () => {
// filter types to be verified
// eq, neq, null, notnull, like, nlike, >, >=, <, <=
const dataType = 'Number';
const filter = {
fk_column_id: columns[1].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: '33',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === 33
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== 33
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >
filter.comparison_op = 'gt';
filter.value = '44';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] > 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >=
filter.comparison_op = 'gte';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] >= 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <
filter.comparison_op = 'lt';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] < 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <=
filter.comparison_op = 'lte';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] <= 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: Decimal', async () => {
// filter types to be verified
// eq, neq, null, notnull, like, nlike, >, >=, <, <=
const dataType = 'Decimal';
const filter = {
fk_column_id: columns[2].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: '33.3',
};
let expectedRecords = unfilteredRecords.filter(
(record) => parseFloat(record[dataType]) === 33.3
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => parseFloat(record[dataType]) !== 33.3
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >
filter.comparison_op = 'gt';
filter.value = '44.26';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) > 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >=
filter.comparison_op = 'gte';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) >= 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <
filter.comparison_op = 'lt';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) < 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <=
filter.comparison_op = 'lte';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) <= 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: Currency', async () => {
// filter types to be verified
// eq, neq, null, notnull, like, nlike, >, >=, <, <=
const dataType = 'Currency';
const filter = {
fk_column_id: columns[3].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: '33.3',
};
let expectedRecords = unfilteredRecords.filter(
(record) => parseFloat(record[dataType]) === 33.3
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => parseFloat(record[dataType]) !== 33.3
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >
filter.comparison_op = 'gt';
filter.value = '44.26';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) > 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >=
filter.comparison_op = 'gte';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) >= 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <
filter.comparison_op = 'lt';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) < 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <=
filter.comparison_op = 'lte';
expectedRecords = unfilteredRecords.filter(
(record) =>
parseFloat(record[dataType]) <= 44.26 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: Percent', async () => {
// filter types to be verified
// eq, neq, null, notnull, like, nlike, >, >=, <, <=
const dataType = 'Percent';
const filter = {
fk_column_id: columns[4].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: '33',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === 33
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== 33
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >
filter.comparison_op = 'gt';
filter.value = '44';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] > 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >=
filter.comparison_op = 'gte';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] >= 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <
filter.comparison_op = 'lt';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] < 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <=
filter.comparison_op = 'lte';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] <= 44 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
});
it('Type: Rating', async () => {
// filter types to be verified
// eq, neq, null, notnull, like, nlike, >, >=, <, <=
const dataType = 'Rating';
const filter = {
fk_column_id: columns[6].id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: '3',
};
let expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === 3
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: neq
filter.comparison_op = 'neq';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== 3
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: null
filter.comparison_op = 'null';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] === null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: notnull
filter.comparison_op = 'notnull';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >
filter.comparison_op = 'gt';
filter.value = '2';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] > 2 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: >=
filter.comparison_op = 'gte';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] >= 2 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <
filter.comparison_op = 'lt';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] < 2 && record[dataType] !== null
);
await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
// filter: <=
filter.comparison_op = 'lte';
expectedRecords = unfilteredRecords.filter(
(record) => record[dataType] <= 2 && record[dataType] !== null
); );
await retrieveRecordsAndValidate(filter, expectedRecords); await retrieveRecordsAndValidate(filter, expectedRecords, dataType);
}); });
} }
export default function () { export default function () {
describe('Filters', filterTests); describe('Filter: Text based', filterTextBased);
describe('Filter: Numerical', filterNumberBased);
} }

Loading…
Cancel
Save