|
|
|
@ -14,6 +14,7 @@ import {
|
|
|
|
|
} from '../../factory/row'; |
|
|
|
|
import Model from '../../../../src/lib/models/Model'; |
|
|
|
|
import { expect } from 'chai'; |
|
|
|
|
import request from 'supertest'; |
|
|
|
|
|
|
|
|
|
// Test case list
|
|
|
|
|
|
|
|
|
@ -21,6 +22,7 @@ function filterTests() {
|
|
|
|
|
let context; |
|
|
|
|
let project: Project; |
|
|
|
|
let table: Model; |
|
|
|
|
let columns: any[]; |
|
|
|
|
let unfilteredRecords: any[] = []; |
|
|
|
|
|
|
|
|
|
// prepare data for test cases
|
|
|
|
@ -64,7 +66,7 @@ function filterTests() {
|
|
|
|
|
], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const columns = await table.getColumns(); |
|
|
|
|
columns = await table.getColumns(); |
|
|
|
|
|
|
|
|
|
let rowAttributes = []; |
|
|
|
|
for (let i = 0; i < 400; i++) { |
|
|
|
@ -89,7 +91,100 @@ function filterTests() {
|
|
|
|
|
expect(unfilteredRecords.length).to.equal(400); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Type: Single Line Text', async () => {}); |
|
|
|
|
async function retrieveRecordsAndValidate( |
|
|
|
|
filter: { |
|
|
|
|
comparison_op: string; |
|
|
|
|
value: string; |
|
|
|
|
fk_column_id: any; |
|
|
|
|
status: string; |
|
|
|
|
logical_op: string; |
|
|
|
|
}, |
|
|
|
|
expectedRecords: any[] |
|
|
|
|
) { |
|
|
|
|
// 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
|
|
|
|
|
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 () => { |
|
|
|
|
// filter types to be verified
|
|
|
|
|
// eq, neq, null, notnull, empty, notempty, like, nlike
|
|
|
|
|
|
|
|
|
|
const filter = { |
|
|
|
|
fk_column_id: columns[1].id, |
|
|
|
|
status: 'create', |
|
|
|
|
logical_op: 'and', |
|
|
|
|
comparison_op: 'eq', |
|
|
|
|
value: 'Afghanistan', |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let expectedRecords = unfilteredRecords.filter( |
|
|
|
|
(record) => record.SingleLineText === 'Afghanistan' |
|
|
|
|
); |
|
|
|
|
await retrieveRecordsAndValidate(filter, expectedRecords); |
|
|
|
|
|
|
|
|
|
// filter: neq
|
|
|
|
|
filter.comparison_op = 'neq'; |
|
|
|
|
expectedRecords = unfilteredRecords.filter( |
|
|
|
|
(record) => record.SingleLineText !== 'Afghanistan' |
|
|
|
|
); |
|
|
|
|
await retrieveRecordsAndValidate(filter, expectedRecords); |
|
|
|
|
|
|
|
|
|
// filter: null
|
|
|
|
|
filter.comparison_op = 'null'; |
|
|
|
|
expectedRecords = unfilteredRecords.filter( |
|
|
|
|
(record) => record.SingleLineText === null |
|
|
|
|
); |
|
|
|
|
await retrieveRecordsAndValidate(filter, expectedRecords); |
|
|
|
|
|
|
|
|
|
// filter: notnull
|
|
|
|
|
filter.comparison_op = 'notnull'; |
|
|
|
|
expectedRecords = unfilteredRecords.filter( |
|
|
|
|
(record) => record.SingleLineText !== null |
|
|
|
|
); |
|
|
|
|
await retrieveRecordsAndValidate(filter, expectedRecords); |
|
|
|
|
|
|
|
|
|
// filter: empty
|
|
|
|
|
filter.comparison_op = 'empty'; |
|
|
|
|
expectedRecords = unfilteredRecords.filter( |
|
|
|
|
(record) => record.SingleLineText === '' |
|
|
|
|
); |
|
|
|
|
await retrieveRecordsAndValidate(filter, expectedRecords); |
|
|
|
|
|
|
|
|
|
// filter: notempty
|
|
|
|
|
filter.comparison_op = 'notempty'; |
|
|
|
|
expectedRecords = unfilteredRecords.filter( |
|
|
|
|
(record) => record.SingleLineText !== '' |
|
|
|
|
); |
|
|
|
|
//TBD await retrieveRecordsAndValidate(filter, expectedRecords);
|
|
|
|
|
|
|
|
|
|
// filter: like
|
|
|
|
|
filter.comparison_op = 'like'; |
|
|
|
|
filter.value = 'Au'; |
|
|
|
|
expectedRecords = unfilteredRecords.filter((record) => |
|
|
|
|
record.SingleLineText?.includes('Au') |
|
|
|
|
); |
|
|
|
|
await retrieveRecordsAndValidate(filter, expectedRecords); |
|
|
|
|
|
|
|
|
|
// filter: nlike
|
|
|
|
|
filter.comparison_op = 'nlike'; |
|
|
|
|
filter.value = 'Au'; |
|
|
|
|
expectedRecords = unfilteredRecords.filter( |
|
|
|
|
(record) => !record.SingleLineText?.includes('Au') |
|
|
|
|
); |
|
|
|
|
await retrieveRecordsAndValidate(filter, expectedRecords); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default function () { |
|
|
|
|