Browse Source

refactor/Added unit test for exists table row api and improved table dropping while starting tests

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
9fa075ea69
  1. 10
      packages/nocodb/src/__tests__/unit/rest/init/cleanupMeta.ts
  2. 14
      packages/nocodb/src/__tests__/unit/rest/tests/factory/row.ts
  3. 33
      packages/nocodb/src/__tests__/unit/rest/tests/tableRow.test.ts

10
packages/nocodb/src/__tests__/unit/rest/init/cleanupMeta.ts

@ -24,11 +24,11 @@ const dropTablesAllNonExternalProjects = async (knexClient) => {
})
);
await Promise.all(
userCreatedTableNames.map(async (tableName) => {
await knexClient.raw(`DROP TABLE ${tableName}`);
})
);
await knexClient.raw('SET FOREIGN_KEY_CHECKS = 0');
for (const tableName of userCreatedTableNames) {
await knexClient.raw(`DROP TABLE ${tableName}`);
}
await knexClient.raw('SET FOREIGN_KEY_CHECKS = 1');
};
const cleanupMetaTables = async (knexClient) => {

14
packages/nocodb/src/__tests__/unit/rest/tests/factory/row.ts

@ -1,4 +1,3 @@
import console from 'console';
import { ColumnType, UITypes } from 'nocodb-sdk';
import request from 'supertest';
import Column from '../../../../../lib/models/Column';
@ -32,6 +31,17 @@ const getRow = async (context, project, table, id) => {
return response.body;
};
const getOneRow = async (
context,
{ project, table }: { project: Project; table: Model }
) => {
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${project.id}/${table.id}/find-one`)
.set('xc-auth', context.token);
return response.body;
};
const createRow = async (
context,
{
@ -102,4 +112,4 @@ const createRelation = async (
.set('xc-auth', context.token);
};
export { createRow, getRow, createRelation };
export { createRow, getRow, createRelation, getOneRow };

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

@ -11,7 +11,7 @@ import {
createRollupColumn,
} from './factory/column';
import { createTable } from './factory/table';
import { createRelation, createRow, getRow } from './factory/row';
import { createRelation, createRow, getOneRow, getRow } from './factory/row';
const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => {
const responseColumnsListStr = Object.keys(row).sort().join(',');
@ -1232,6 +1232,37 @@ function tableTest() {
throw new Error('Should give ltar foreign key error');
}
});
it('Exist should be true table row when it exists', async function () {
const row = await getOneRow(context, {
project: sakilaProject,
table: customerTable,
});
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${row['CustomerId']}/exist`
)
.set('xc-auth', context.token)
.expect(200);
if (!response.body) {
throw new Error('Should exist');
}
});
it('Exist should be false table row when it does not exists', async function () {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/invalid-id/exist`
)
.set('xc-auth', context.token)
.expect(200);
if (response.body) {
throw new Error('Should not exist');
}
});
}
export default function () {

Loading…
Cancel
Save