Browse Source

refactor/Added unit test to get find one table row

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
ecf93b1a90
  1. 92
      packages/nocodb/src/__tests__/unit/rest/tests/tableRow.test.ts
  2. 1
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

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

@ -867,6 +867,98 @@ function tableTest() {
throw new Error('Wrong sort');
}
});
it('Find one sorted filtered table with nested fields data list with a rollup column in customer table', async function () {
const rollupColumn = await createRollupColumn(context, {
project: sakilaProject,
title: 'Number of rentals',
rollupFunction: 'count',
table: customerTable,
relatedTableName: 'rental',
relatedTableColumnTitle: 'RentalDate',
});
const paymentListColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Payment List'
);
const activeColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Active'
);
const nestedFields = {
'Rental List': ['RentalDate', 'ReturnDate'],
};
const nestedFilter = [
{
fk_column_id: rollupColumn?.id,
status: 'create',
logical_op: 'and',
comparison_op: 'gte',
value: '25',
},
{
is_group: true,
status: 'create',
logical_op: 'or',
children: [
{
fk_column_id: rollupColumn?.id,
status: 'create',
logical_op: 'and',
comparison_op: 'lte',
value: '30',
},
{
fk_column_id: paymentListColumn?.id,
status: 'create',
logical_op: 'and',
comparison_op: 'notempty',
},
{
is_group: true,
status: 'create',
logical_op: 'and',
children: [
{
logical_op: 'and',
fk_column_id: activeColumn?.id,
status: 'create',
comparison_op: 'notempty',
},
],
},
],
},
];
const ascResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/find-one`
)
.set('xc-auth', context.token)
.query({
nested: nestedFields,
filterArrJson: JSON.stringify([nestedFilter]),
sort: `${rollupColumn.title}`,
})
.expect(200);
if (ascResponse.body[rollupColumn.title] !== 12) {
console.log(ascResponse.body);
throw new Error('Wrong filter');
}
const nestedRentalResponse = Object.keys(ascResponse.body['Rental List']);
if (
nestedRentalResponse.includes('RentalId') &&
nestedRentalResponse.includes('RentalDate') &&
nestedRentalResponse.length === 2
) {
throw new Error('Wrong nested fields');
}
});
}
export default function () {

1
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -116,6 +116,7 @@ class BaseModelSqlv2 {
return !!(await qb.where(_wherePk(pks, id)).first());
}
// todo: add support for sortArrJson
public async findOne(
args: {
where?: string;

Loading…
Cancel
Save