Browse Source

refactor/Added lookup filter unit test for table row api

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
e1d0a2666c
  1. 2
      packages/nocodb/src/__tests__/unit/rest/tests/helpers/column.ts
  2. 40
      packages/nocodb/src/__tests__/unit/rest/tests/tableRow.test.ts

2
packages/nocodb/src/__tests__/unit/rest/tests/helpers/column.ts

@ -212,6 +212,7 @@ const createRollupColumn = async (
column_name: title,
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const rollupColumn = (await table.getColumns()).find(
(column) => column.title === title
)!;
@ -265,6 +266,7 @@ const createLookupColumn = async (
column_name: title,
});
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const lookupColumn = (await table.getColumns()).find(
(column) => column.title === title
)!;

40
packages/nocodb/src/__tests__/unit/rest/tests/tableRow.test.ts

@ -5,6 +5,7 @@ import init from '../init';
import request from 'supertest';
import { ColumnType } from 'nocodb-sdk';
import { createLookupColumn, createRollupColumn } from './helpers/column';
import Filter from '../../../../lib/models/Filter';
const isColumnsCorrectInResponse = (response, columns: ColumnType[]) => {
const responseColumnsListStr = Object.keys(response.body.list[0])
@ -256,6 +257,45 @@ function tableTest() {
if (descResponse.body.list[0][lookupColumn.title] !== 'ZACHARY')
throw new Error('Wrong sort');
});
it('Get sorted filtered table data list with a lookup column', async function () {
const rentalTable = await Model.getByIdOrName({
project_id: project.id,
base_id: project.bases[0].id,
table_name: 'rental',
});
const lookupColumn = await createLookupColumn(context, {
project,
title: 'Lookup',
table: rentalTable,
relatedTableName: customerTable.table_name,
relatedTableColumnTitle: 'FirstName',
});
const filter = {
fk_column_id: lookupColumn?.id,
status: 'create',
logical_op: 'and',
comparison_op: 'eq',
value: 'AARON',
};
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${project.id}/${rentalTable.id}`)
.set('xc-auth', context.token)
.query({
filterArrJson: JSON.stringify([filter]),
})
.expect(200);
if (response.body.pageInfo.totalRows !== 24)
throw new Error('Wrong number of rows');
response.body.list.forEach((row) => {
if (row[lookupColumn.title] !== 'AARON') throw new Error('Wrong filter');
});
});
}
export default function () {

Loading…
Cancel
Save