Browse Source

test: UT fix as per new behaviour

pull/5816/head
Raju Udava 1 year ago
parent
commit
30a2adc2a0
  1. 15
      packages/nocodb/tests/unit/rest/tests/tableRow.test.ts
  2. 148
      packages/nocodb/tests/unit/rest/tests/viewRow.test.ts

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

@ -1422,22 +1422,15 @@ function tableTest() {
rowId: row['Id'],
});
const response = await request(context.app)
await request(context.app)
.delete(`/api/v1/db/data/noco/${project.id}/${table.id}/${row['Id']}`)
.set('xc-auth', context.token)
.expect(200);
const deleteRow = await getRow(context, { project, table, id: row['Id'] });
if (!deleteRow) {
throw new Error('Should not delete');
}
if (
!(response.body.message[0] as string).includes(
'is a LinkToAnotherRecord of',
)
) {
throw new Error('Should give ltar foreign key error');
if (deleteRow && Object.keys(deleteRow).length > 0) {
console.log(deleteRow);
throw new Error('Wrong delete');
}
});

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

@ -1,12 +1,11 @@
import 'mocha';
import { isString } from 'util';
import request from 'supertest';
import { UITypes, ViewTypes } from 'nocodb-sdk';
import { expect } from 'chai';
import init from '../../init';
import { createProject, createSakilaProject } from '../../factory/project';
import request from 'supertest';
import Project from '../../../../src/models/Project';
import Model from '../../../../src/models/Model';
import { createTable, getTable } from '../../factory/table';
import View from '../../../../src/models/View';
import { ColumnType, UITypes, ViewTypes } from 'nocodb-sdk';
import { createView } from '../../factory/view';
import {
createColumn,
@ -21,9 +20,11 @@ import {
getOneRow,
getRow,
} from '../../factory/row';
import { expect } from 'chai';
import { isPg } from '../../init/db';
import { isString } from 'util';
import type { ColumnType } from 'nocodb-sdk';
import type View from '../../../../src/models/View';
import type Model from '../../../../src/models/Model';
import type Project from '../../../../src/models/Project';
// Test case list
// 1. Get view row list g
@ -160,7 +161,7 @@ function viewRowTests() {
const testGetViewRowList = async (view: View) => {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.expect(200);
@ -179,7 +180,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`,
)
.set('xc-auth', context.token)
.expect(200);
@ -225,7 +226,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -244,7 +245,7 @@ function viewRowTests() {
requiredColumns.map((c: ColumnType) => ({
title: c.title,
uidt: c.uidt,
}))
})),
);
throw new Error('Wrong columns');
}
@ -271,7 +272,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`,
)
.set('xc-auth', context.token)
.query({
@ -287,7 +288,7 @@ function viewRowTests() {
expect(
Object.keys(response.body.find((e) => e.key === 'NC-17').value.list[0])
.sort()
.join(',')
.join(','),
).to.equal('FilmId,Title');
};
@ -297,14 +298,14 @@ function viewRowTests() {
const testDescSortedViewDataList = async (view: View) => {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName'
(col) => col.title === 'FirstName',
);
const visibleColumns = [firstNameColumn];
const sortInfo = [{ fk_column_id: firstNameColumn.id, direction: 'desc' }];
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -332,7 +333,7 @@ function viewRowTests() {
Math.trunc(pageInfo.totalRows / pageInfo.pageSize) * pageInfo.pageSize;
const lastPageResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -375,7 +376,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`,
)
.set('xc-auth', context.token)
.query({
@ -390,7 +391,7 @@ function viewRowTests() {
expect(response.body).to.be.have.length(6);
expect(
response.body.find((e) => e.key === 'PG').value.list[0].Title
response.body.find((e) => e.key === 'PG').value.list[0].Title,
).to.equal('WORST BANGER');
};
@ -400,14 +401,14 @@ function viewRowTests() {
const testAscSortedViewDataList = async (view: View) => {
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName'
(col) => col.title === 'FirstName',
);
const visibleColumns = [firstNameColumn];
const sortInfo = [{ fk_column_id: firstNameColumn.id, direction: 'asc' }];
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -435,7 +436,7 @@ function viewRowTests() {
Math.trunc(pageInfo.totalRows / pageInfo.pageSize) * pageInfo.pageSize;
const lastPageResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -478,7 +479,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${view.id}/group/${ratingColumn.id}`,
)
.set('xc-auth', context.token)
.query({
@ -493,7 +494,7 @@ function viewRowTests() {
expect(response.body).to.be.have.length(6);
expect(
response.body.find((e) => e.key === 'PG').value.list[0].Title
response.body.find((e) => e.key === 'PG').value.list[0].Title,
).to.equal('ACADEMY DINOSAUR');
};
@ -502,7 +503,7 @@ function viewRowTests() {
});
const testGetViewDataListWithRequiredColumnsAndFilter = async (
viewType: ViewTypes
viewType: ViewTypes,
) => {
const rentalTable = await getTable({
project: sakilaProject,
@ -523,7 +524,7 @@ function viewRowTests() {
});
const paymentListColumn = (await rentalTable.getColumns()).find(
(c) => c.title === 'Payment List'
(c) => c.title === 'Payment List',
);
const nestedFilter = {
@ -549,7 +550,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -560,7 +561,7 @@ function viewRowTests() {
const ascResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -579,7 +580,7 @@ function viewRowTests() {
const descResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${rentalTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -606,7 +607,7 @@ function viewRowTests() {
});
const testGetNestedSortedFilteredTableDataListWithLookupColumn = async (
viewType: ViewTypes
viewType: ViewTypes,
) => {
const view = await createView(context, {
title: 'View',
@ -624,11 +625,11 @@ function viewRowTests() {
});
const paymentListColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Payment List'
(c) => c.title === 'Payment List',
);
const activeColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Active'
(c) => c.title === 'Active',
);
const nestedFields = {
@ -681,7 +682,7 @@ function viewRowTests() {
const ascResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.query({
@ -703,7 +704,7 @@ function viewRowTests() {
}
const nestedRentalResponse = Object.keys(
ascResponse.body.list[0]['Rental List'][0]
ascResponse.body.list[0]['Rental List'][0],
);
if (
@ -719,7 +720,7 @@ function viewRowTests() {
it('Get nested sorted filtered table with nested fields data list with a rollup column in customer table view grid', async () => {
await testGetNestedSortedFilteredTableDataListWithLookupColumn(
ViewTypes.GRID
ViewTypes.GRID,
);
});
@ -774,7 +775,7 @@ function viewRowTests() {
await request(context.app)
.post(
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${nonRelatedView.id}`
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${nonRelatedView.id}`,
)
.set('xc-auth', context.token)
.send({
@ -802,7 +803,7 @@ function viewRowTests() {
// todo: Test that all the columns needed to be shown in the view are returned
const testFindOneSortedDataWithRequiredColumns = async (
viewType: ViewTypes
viewType: ViewTypes,
) => {
const view = await createView(context, {
title: 'View',
@ -810,13 +811,13 @@ function viewRowTests() {
type: viewType,
});
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName'
(col) => col.title === 'FirstName',
);
const visibleColumns = [firstNameColumn];
let response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/find-one`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/find-one`,
)
.set('xc-auth', context.token)
.query({
@ -837,7 +838,7 @@ function viewRowTests() {
response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/find-one`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/find-one`,
)
.set('xc-auth', context.token)
.query({
@ -870,7 +871,7 @@ function viewRowTests() {
});
const testFindOneSortedFilteredNestedFieldsDataWithRollup = async (
viewType: ViewTypes
viewType: ViewTypes,
) => {
const rollupColumn = await createRollupColumn(context, {
project: sakilaProject,
@ -893,11 +894,11 @@ function viewRowTests() {
});
const paymentListColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Payment List'
(c) => c.title === 'Payment List',
);
const activeColumn = (await customerTable.getColumns()).find(
(c) => c.title === 'Active'
(c) => c.title === 'Active',
);
const nestedFields = {
@ -950,7 +951,7 @@ function viewRowTests() {
const ascResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/find-one`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/find-one`,
)
.set('xc-auth', context.token)
.query({
@ -995,7 +996,7 @@ function viewRowTests() {
type: viewType,
});
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName'
(col) => col.title === 'FirstName',
);
const rollupColumn = await createRollupColumn(context, {
@ -1012,7 +1013,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/groupby`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/groupby`,
)
.set('xc-auth', context.token)
.query({
@ -1049,7 +1050,7 @@ function viewRowTests() {
});
const firstNameColumn = customerColumns.find(
(col) => col.title === 'FirstName'
(col) => col.title === 'FirstName',
);
const rollupColumn = await createRollupColumn(context, {
@ -1066,7 +1067,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/groupby`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/groupby`,
)
.set('xc-auth', context.token)
.query({
@ -1105,7 +1106,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/count`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/count`,
)
.set('xc-auth', context.token)
.expect(200);
@ -1136,7 +1137,7 @@ function viewRowTests() {
const listResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}`,
)
.set('xc-auth', context.token)
.expect(200);
@ -1145,7 +1146,7 @@ function viewRowTests() {
const readResponse = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/${row['CustomerId']}`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/${row['CustomerId']}`,
)
.set('xc-auth', context.token)
.expect(200);
@ -1181,7 +1182,7 @@ function viewRowTests() {
const updateResponse = await request(context.app)
.patch(
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`,
)
.set('xc-auth', context.token)
.send({
@ -1207,7 +1208,7 @@ function viewRowTests() {
});
const testUpdateViewRowWithValidationAndInvalidData = async (
viewType: ViewTypes
viewType: ViewTypes,
) => {
const table = await createTable(context, project);
const emailColumn = await createColumn(context, table, {
@ -1228,7 +1229,7 @@ function viewRowTests() {
await request(context.app)
.patch(
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`,
)
.set('xc-auth', context.token)
.send({
@ -1253,7 +1254,7 @@ function viewRowTests() {
// todo: Test with form view
const testUpdateViewRowWithValidationAndValidData = async (
viewType: ViewTypes
viewType: ViewTypes,
) => {
const table = await createTable(context, project);
const emailColumn = await createColumn(context, table, {
@ -1273,7 +1274,7 @@ function viewRowTests() {
const response = await request(context.app)
.patch(
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`,
)
.set('xc-auth', context.token)
.send({
@ -1314,7 +1315,7 @@ function viewRowTests() {
await request(context.app)
.delete(
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`,
)
.set('xc-auth', context.token)
.expect(200);
@ -1338,8 +1339,8 @@ function viewRowTests() {
await testDeleteViewRow(ViewTypes.FORM);
});
const testDeleteViewRowWithForiegnKeyConstraint = async (
viewType: ViewTypes
const testDeleteViewRowWithForeignKeyConstraint = async (
viewType: ViewTypes,
) => {
const table = await createTable(context, project);
const relatedTable = await createTable(context, project, {
@ -1369,37 +1370,30 @@ function viewRowTests() {
rowId: row['Id'],
});
const response = await request(context.app)
await request(context.app)
.delete(
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`
`/api/v1/db/data/noco/${project.id}/${table.id}/views/${view.id}/${row['Id']}`,
)
.set('xc-auth', context.token)
.expect(200);
const deleteRow = await getRow(context, { project, table, id: row['Id'] });
if (!deleteRow) {
throw new Error('Should not delete');
}
if (
!(response.body.message[0] as string).includes(
'is a LinkToAnotherRecord of'
)
) {
throw new Error('Should give ltar foreign key error');
if (deleteRow && Object.keys(deleteRow).length > 0) {
console.log(deleteRow);
throw new Error('Wrong delete');
}
};
it('Delete view row with ltar foreign key constraint GALLERY', async function () {
await testDeleteViewRowWithForiegnKeyConstraint(ViewTypes.GALLERY);
await testDeleteViewRowWithForeignKeyConstraint(ViewTypes.GALLERY);
});
it('Delete view row with ltar foreign key constraint GRID', async function () {
await testDeleteViewRowWithForiegnKeyConstraint(ViewTypes.GRID);
await testDeleteViewRowWithForeignKeyConstraint(ViewTypes.GRID);
});
it('Delete view row with ltar foreign key constraint FORM', async function () {
await testDeleteViewRowWithForiegnKeyConstraint(ViewTypes.FORM);
await testDeleteViewRowWithForeignKeyConstraint(ViewTypes.FORM);
});
const testViewRowExists = async (viewType: ViewTypes) => {
@ -1415,7 +1409,7 @@ function viewRowTests() {
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/${row['CustomerId']}/exist`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/${row['CustomerId']}/exist`,
)
.set('xc-auth', context.token)
.expect(200);
@ -1445,7 +1439,7 @@ function viewRowTests() {
});
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/999999/exist`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/views/${view.id}/999999/exist`,
)
.set('xc-auth', context.token)
.expect(200);
@ -1475,7 +1469,7 @@ function viewRowTests() {
});
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/csv`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/csv`,
)
.set('xc-auth', context.token)
.expect(200);
@ -1499,7 +1493,7 @@ function viewRowTests() {
});
const response = await request(context.app)
.get(
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/excel`
`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.title}/views/${view.id}/export/excel`,
)
.set('xc-auth', context.token)
.expect(200);

Loading…
Cancel
Save