Browse Source

fix(nocodb): Improved unit tests and now completly support sqlite

pull/3721/head
Muhammed Mustafa 2 years ago
parent
commit
379de73099
  1. 6
      packages/nocodb/tests/mysql-sakila-db/03-test-sakila-schema.sql
  2. 5
      packages/nocodb/tests/unit/factory/view.ts
  3. 4
      packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts
  4. 122
      packages/nocodb/tests/unit/rest/tests/tableRow.test.ts
  5. 58
      packages/nocodb/tests/unit/rest/tests/viewRow.test.ts

6
packages/nocodb/tests/mysql-sakila-db/03-test-sakila-schema.sql

@ -532,7 +532,7 @@ proc: BEGIN
DROP TABLE tmpCustomer;
END;
CREATE FUNCTION IF NOT EXISTS get_customer_balance(p_customer_id INT, p_effective_date DATETIME) RETURNS DECIMAL(5,2)
CREATE FUNCTION get_customer_balance(p_customer_id INT, p_effective_date DATETIME) RETURNS DECIMAL(5,2)
DETERMINISTIC
READS SQL DATA
BEGIN
@ -608,7 +608,7 @@ BEGIN
END;
CREATE FUNCTION IF NOT EXISTS inventory_held_by_customer(p_inventory_id INT) RETURNS INT
CREATE FUNCTION inventory_held_by_customer(p_inventory_id INT) RETURNS INT
READS SQL DATA
BEGIN
DECLARE v_customer_id INT;
@ -622,7 +622,7 @@ BEGIN
RETURN v_customer_id;
END;
CREATE FUNCTION IF NOT EXISTS inventory_in_stock(p_inventory_id INT) RETURNS BOOLEAN
CREATE FUNCTION inventory_in_stock(p_inventory_id INT) RETURNS BOOLEAN
READS SQL DATA
BEGIN
DECLARE v_rentals INT;

5
packages/nocodb/tests/unit/factory/view.ts

@ -19,13 +19,16 @@ const createView = async (context, {title, table, type}: {title: string, table:
}
};
await request(context.app)
const response = await request(context.app)
.post(`/api/v1/db/meta/tables/${table.id}/${viewTypeStr(type)}`)
.set('xc-auth', context.token)
.send({
title,
type,
});
if(response.status !== 200) {
throw new Error('createView',response.body.message);
}
const view = await View.getByTitleOrId({fk_model_id: table.id, titleOrId:title}) as View;

4
packages/nocodb/tests/unit/model/tests/baseModelSql.test.ts

@ -14,6 +14,7 @@ import { expect } from 'chai';
import Filter from '../../../../src/lib/models/Filter';
import { createLtarColumn } from '../../factory/column';
import LinkToAnotherRecordColumn from '../../../../src/lib/models/LinkToAnotherRecordColumn';
import { isSqlite } from '../../init/db';
function baseModelSqlTests() {
let context;
@ -126,6 +127,9 @@ function baseModelSqlTests() {
});
it('Bulk update record', async () => {
// Since sqlite doesn't support multiple sql connections, we can't test bulk update in sqlite
if(isSqlite(context)) return
const columns = await table.getColumns();
const request = {
clientIp: '::ffff:192.0.0.1',

122
packages/nocodb/tests/unit/rest/tests/tableRow.test.ts

@ -22,6 +22,7 @@ import {
import { isMysql, isSqlite } from '../../init/db';
import Model from '../../../../src/lib/models/Model';
import Project from '../../../../src/lib/models/Project';
import { expect } from 'chai';
const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => {
const responseColumnsListStr = Object.keys(row).sort().join(',');
@ -353,6 +354,90 @@ function tableTest() {
(c) => c.title === 'Payment List'
);
const nestedFilter = {
is_group: true,
status: 'create',
logical_op: 'and',
children: [
{
fk_column_id: lookupColumn?.id,
status: 'create',
logical_op: 'and',
comparison_op: 'like',
value: '%a%',
},
{
fk_column_id: paymentListColumn?.id,
status: 'create',
logical_op: 'and',
comparison_op: 'notempty',
},
],
};
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}`)
.set('xc-auth', context.token)
.query({
filterArrJson: JSON.stringify([nestedFilter]),
})
.expect(200);
expect(response.body.pageInfo.totalRows).equal(9558)
const ascResponse = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}`)
.set('xc-auth', context.token)
.query({
filterArrJson: JSON.stringify([nestedFilter]),
sortArrJson: JSON.stringify([
{
fk_column_id: lookupColumn?.id,
direction: 'asc',
},
]),
})
.expect(200);
expect(ascResponse.body.pageInfo.totalRows).equal(9558)
expect(ascResponse.body.list[0][lookupColumn.title]).equal('AARON')
const descResponse = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}`)
.set('xc-auth', context.token)
.query({
filterArrJson: JSON.stringify([nestedFilter]),
sortArrJson: JSON.stringify([
{
fk_column_id: lookupColumn?.id,
direction: 'desc',
},
]),
})
.expect(200);
expect(descResponse.body.pageInfo.totalRows).equal(9558)
expect(descResponse.body.list[0][lookupColumn.title]).equal('ZACHARY')
});
it('Get nested sorted filtered table data list with a lookup column with date comparison', async function () {
// Since sqlite doesn't support date comparison
if(isSqlite(context)) return;
const rentalTable = await getTable({project: sakilaProject, name: 'rental'});
const lookupColumn = await createLookupColumn(context, {
project: sakilaProject,
title: 'Lookup',
table: rentalTable,
relatedTableName: customerTable.table_name,
relatedTableColumnTitle: 'FirstName',
});
const paymentListColumn = (await rentalTable.getColumns()).find(
(c) => c.title === 'Payment List'
);
const returnDateColumn = (await rentalTable.getColumns()).find(
(c) => c.title === 'ReturnDate'
);
@ -483,7 +568,7 @@ function tableTest() {
status: 'create',
logical_op: 'and',
comparison_op: 'gte',
value: '25',
value: 25,
},
{
is_group: true,
@ -495,7 +580,7 @@ function tableTest() {
status: 'create',
logical_op: 'and',
comparison_op: 'lte',
value: '30',
value: 30,
},
{
fk_column_id: paymentListColumn?.id,
@ -512,7 +597,8 @@ function tableTest() {
logical_op: 'and',
fk_column_id: activeColumn?.id,
status: 'create',
comparison_op: 'notempty',
comparison_op: 'eq',
value: 1
},
],
},
@ -639,7 +725,7 @@ function tableTest() {
status: 'create',
logical_op: 'and',
comparison_op: 'gte',
value: '25',
value: 25,
},
{
is_group: true,
@ -651,7 +737,7 @@ function tableTest() {
status: 'create',
logical_op: 'and',
comparison_op: 'lte',
value: '30',
value: 30,
},
{
fk_column_id: paymentListColumn?.id,
@ -668,7 +754,8 @@ function tableTest() {
logical_op: 'and',
fk_column_id: activeColumn?.id,
status: 'create',
comparison_op: 'notempty',
comparison_op: 'eq',
value: 1
},
],
},
@ -946,7 +1033,7 @@ function tableTest() {
status: 'create',
logical_op: 'and',
comparison_op: 'gte',
value: '25',
value: 25,
},
{
is_group: true,
@ -958,7 +1045,7 @@ function tableTest() {
status: 'create',
logical_op: 'and',
comparison_op: 'lte',
value: '30',
value: 30,
},
{
fk_column_id: paymentListColumn?.id,
@ -975,7 +1062,8 @@ function tableTest() {
logical_op: 'and',
fk_column_id: activeColumn?.id,
status: 'create',
comparison_op: 'notempty',
comparison_op: 'eq',
value: 1
},
],
},
@ -1343,7 +1431,7 @@ function tableTest() {
});
it('Bulk update', async function () {
// todo: Find why bulk update in sqlite is hanging
// todo: Since sqlite doesn't support multiple sql connections, we can't test bulk update in sqlite
if(isSqlite(context)) {
return
}
@ -1375,10 +1463,6 @@ function tableTest() {
});
it('Bulk delete', async function () {
// todo: Find why bulk delete in sqlite is hanging
if(isSqlite(context)) {
return
}
const table = await createTable(context, project);
const columns = await table.getColumns();
@ -1766,6 +1850,9 @@ function tableTest() {
})
it('Create list mm', async () => {
// todo: Foreign key has non nullable clause in sqlite sakila
if(isSqlite(context)) return
const rowId = 1;
const actorTable = await getTable({project: sakilaProject, name: 'actor'});
const filmListColumn = (await actorTable.getColumns()).find(
@ -1848,6 +1935,9 @@ function tableTest() {
})
it('Delete list hm with existing ref row id with non nullable clause', async () => {
// todo: Foreign key has non nullable clause in sqlite sakila
if(isSqlite(context)) return
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List'
@ -1900,10 +1990,6 @@ function tableTest() {
})
it('Exclude list hm', async () => {
// todo: Find why sqlite not working with this
if(isSqlite(context)) {
return
}
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List'

58
packages/nocodb/tests/unit/rest/tests/viewRow.test.ts

@ -10,6 +10,7 @@ import { ColumnType, UITypes, ViewTypes } from 'nocodb-sdk';
import { createView } from '../../factory/view';
import { createColumn, createLookupColumn, createLtarColumn, createRollupColumn, updateViewColumn } from '../../factory/column';
import { createChildRow, createRow, getOneRow, getRow } from '../../factory/row';
import { expect } from 'chai';
const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => {
const responseColumnsListStr = Object.keys(row).sort().join(',');
@ -262,10 +263,6 @@ function viewRowTests() {
(c) => c.title === 'Payment List'
);
const returnDateColumn = (await rentalTable.getColumns()).find(
(c) => c.title === 'ReturnDate'
);
const nestedFilter = {
is_group: true,
status: 'create',
@ -284,20 +281,6 @@ function viewRowTests() {
logical_op: 'and',
comparison_op: 'notempty',
},
{
is_group: true,
status: 'create',
logical_op: 'and',
children: [
{
logical_op: 'and',
fk_column_id: returnDateColumn?.id,
status: 'create',
comparison_op: 'gte',
value: '2005-06-02 04:33',
},
],
},
],
};
@ -308,11 +291,7 @@ function viewRowTests() {
filterArrJson: JSON.stringify([nestedFilter]),
});
if (response.body.pageInfo.totalRows !== 9133)
throw new Error('Wrong number of rows');
if (response.body.list[0][lookupColumn.title] !== 'ANDREW')
throw new Error('Wrong filter');
expect(response.body.pageInfo.totalRows).equal(9558)
const ascResponse = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`)
@ -328,13 +307,8 @@ function viewRowTests() {
})
.expect(200);
if (ascResponse.body.pageInfo.totalRows !== 9133)
throw new Error('Wrong number of rows asc');
if (ascResponse.body.list[0][lookupColumn.title] !== 'AARON') {
console.log(ascResponse.body.list[0][lookupColumn.title]);
throw new Error('Wrong filter asc');
}
expect(ascResponse.body.pageInfo.totalRows).equal(9558)
expect(ascResponse.body.list[0][lookupColumn.title]).equal('AARON')
const descResponse = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`)
@ -350,11 +324,8 @@ function viewRowTests() {
})
.expect(200);
if (descResponse.body.pageInfo.totalRows !== 9133)
throw new Error('Wrong number of rows desc');
if (descResponse.body.list[0][lookupColumn.title] !== 'ZACHARY')
throw new Error('Wrong filter desc');
expect(descResponse.body.pageInfo.totalRows).equal(9558)
expect(descResponse.body.list[0][lookupColumn.title]).equal('ZACHARY')
}
it('Get nested sorted filtered table data list with a lookup column gallery', async function () {
@ -399,7 +370,7 @@ function viewRowTests() {
status: 'create',
logical_op: 'and',
comparison_op: 'gte',
value: '25',
value: 25,
},
{
is_group: true,
@ -411,7 +382,7 @@ function viewRowTests() {
status: 'create',
logical_op: 'and',
comparison_op: 'lte',
value: '30',
value: 30,
},
{
fk_column_id: paymentListColumn?.id,
@ -428,7 +399,8 @@ function viewRowTests() {
logical_op: 'and',
fk_column_id: activeColumn?.id,
status: 'create',
comparison_op: 'notempty',
comparison_op: 'eq',
value: 1
},
],
},
@ -451,8 +423,7 @@ function viewRowTests() {
})
.expect(200);
if (ascResponse.body.pageInfo.totalRows !== 594)
throw new Error('Wrong number of rows');
expect(ascResponse.body.pageInfo.totalRows).equal(594);
if (ascResponse.body.list[0][rollupColumn.title] !== 12) {
throw new Error('Wrong filter');
@ -648,7 +619,7 @@ function viewRowTests() {
status: 'create',
logical_op: 'and',
comparison_op: 'gte',
value: '25',
value: 25,
},
{
is_group: true,
@ -660,7 +631,7 @@ function viewRowTests() {
status: 'create',
logical_op: 'and',
comparison_op: 'lte',
value: '30',
value: 30,
},
{
fk_column_id: paymentListColumn?.id,
@ -677,7 +648,8 @@ function viewRowTests() {
logical_op: 'and',
fk_column_id: activeColumn?.id,
status: 'create',
comparison_op: 'notempty',
comparison_op: 'eq',
value: 1
},
],
},

Loading…
Cancel
Save