|
|
@ -1,147 +1,181 @@ |
|
|
|
// import { expect } from 'chai';
|
|
|
|
|
|
|
|
import 'mocha'; |
|
|
|
import 'mocha'; |
|
|
|
import { createExternalProject } from './helpers/project'; |
|
|
|
import { createSakilaProject } from './helpers/project'; |
|
|
|
import Model from '../../../../lib/models/Model'; |
|
|
|
import Model from '../../../../lib/models/Model'; |
|
|
|
import init from '../init'; |
|
|
|
import init from '../init'; |
|
|
|
|
|
|
|
import request from 'supertest'; |
|
|
|
|
|
|
|
import { ColumnType } from 'nocodb-sdk'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isColumnsCorrectInResponse = (response, columns: ColumnType[]) => { |
|
|
|
|
|
|
|
const responseColumnsListStr = Object.keys(response.body.list[0]) |
|
|
|
|
|
|
|
.sort() |
|
|
|
|
|
|
|
.join(','); |
|
|
|
|
|
|
|
const customerColumnsListStr = columns |
|
|
|
|
|
|
|
.map((c) => c.title) |
|
|
|
|
|
|
|
.sort() |
|
|
|
|
|
|
|
.join(','); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return responseColumnsListStr === customerColumnsListStr; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function tableTest() { |
|
|
|
function tableTest() { |
|
|
|
let context; |
|
|
|
let context; |
|
|
|
let project; |
|
|
|
let project; |
|
|
|
|
|
|
|
let customerTable: Model; |
|
|
|
|
|
|
|
let customerColumns; |
|
|
|
|
|
|
|
|
|
|
|
beforeEach(async function () { |
|
|
|
beforeEach(async function () { |
|
|
|
context = await init(); |
|
|
|
context = await init(); |
|
|
|
|
|
|
|
|
|
|
|
project = await createExternalProject(context); |
|
|
|
project = await createSakilaProject(context); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// it('Get table data list', async function () {
|
|
|
|
customerTable = await Model.getByIdOrName({ |
|
|
|
// const rowCount = 10;
|
|
|
|
|
|
|
|
// await createRows(rowCount);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const response = await request(app)
|
|
|
|
|
|
|
|
// .get(`/api/v1/db/data/noco/${project.id}/${table.id}`)
|
|
|
|
|
|
|
|
// .set('xc-auth', token)
|
|
|
|
|
|
|
|
// .send({})
|
|
|
|
|
|
|
|
// .expect(200);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (response.body.list.length !== rowCount) {
|
|
|
|
|
|
|
|
// throw new Error('Wrong number of rows');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// it('Get table data list with required columns', async function () {
|
|
|
|
|
|
|
|
// const rowCount = 10;
|
|
|
|
|
|
|
|
// await createRows(rowCount);
|
|
|
|
|
|
|
|
// const newTitleColumn = columns.find((col) => col.title === 'New Title');
|
|
|
|
|
|
|
|
// const visibleColumns = [newTitleColumn.title];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const response = await request(app)
|
|
|
|
|
|
|
|
// .get(`/api/v1/db/data/noco/${project.id}/${table.id}`)
|
|
|
|
|
|
|
|
// .set('xc-auth', token)
|
|
|
|
|
|
|
|
// .query({
|
|
|
|
|
|
|
|
// fields: visibleColumns,
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .expect(200);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (response.body.list.length !== rowCount) {
|
|
|
|
|
|
|
|
// throw new Error('Wrong number of rows');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const sameArrayContent = (a: Array<any>, b: Array<any>) => {
|
|
|
|
|
|
|
|
// return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!sameArrayContent(Object.keys(response.body.list[0]), visibleColumns)) {
|
|
|
|
|
|
|
|
// console.error(Object.keys(response.body.list[0]), visibleColumns);
|
|
|
|
|
|
|
|
// throw new Error('Wrong column value');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// it('Get desc sorted table data list with required columns', async function () {
|
|
|
|
|
|
|
|
// const rowCount = 10;
|
|
|
|
|
|
|
|
// await createRows(rowCount);
|
|
|
|
|
|
|
|
// const newTitleColumn = columns.find((col) => col.title === 'New Title');
|
|
|
|
|
|
|
|
// const visibleColumns = [newTitleColumn.title];
|
|
|
|
|
|
|
|
// const sortInfo = [{ fk_column_id: newTitleColumn.id, direction: 'desc' }];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const response = await request(app)
|
|
|
|
|
|
|
|
// .get(`/api/v1/db/data/noco/${project.id}/${table.id}`)
|
|
|
|
|
|
|
|
// .set('xc-auth', token)
|
|
|
|
|
|
|
|
// .query({
|
|
|
|
|
|
|
|
// fields: visibleColumns,
|
|
|
|
|
|
|
|
// sortArrJson: JSON.stringify(sortInfo),
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .expect(200);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (response.body.list.length !== rowCount) {
|
|
|
|
|
|
|
|
// throw new Error('Wrong number of rows');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const sameArrayContent = (a: Array<any>, b: Array<any>) => {
|
|
|
|
|
|
|
|
// return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!sameArrayContent(Object.keys(response.body.list[0]), visibleColumns)) {
|
|
|
|
|
|
|
|
// console.error(Object.keys(response.body.list[0]), visibleColumns);
|
|
|
|
|
|
|
|
// throw new Error('Wrong column value');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (
|
|
|
|
|
|
|
|
// response.body.list[0][newTitleColumn.title] !== 'test-9' ||
|
|
|
|
|
|
|
|
// response.body.list[response.body.list.length - 1][
|
|
|
|
|
|
|
|
// newTitleColumn.title
|
|
|
|
|
|
|
|
// ] !== 'test-0'
|
|
|
|
|
|
|
|
// ) {
|
|
|
|
|
|
|
|
// throw new Error('Wrong sort');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// it('Get asc sorted table data list with required columns', async function () {
|
|
|
|
|
|
|
|
// const rowCount = 10;
|
|
|
|
|
|
|
|
// await createRows(rowCount);
|
|
|
|
|
|
|
|
// const newTitleColumn = columns.find((col) => col.title === 'New Title');
|
|
|
|
|
|
|
|
// const visibleColumns = [newTitleColumn.title];
|
|
|
|
|
|
|
|
// const sortInfo = [{ fk_column_id: newTitleColumn.id, direction: 'asc' }];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const response = await request(app)
|
|
|
|
|
|
|
|
// .get(`/api/v1/db/data/noco/${project.id}/${table.id}`)
|
|
|
|
|
|
|
|
// .set('xc-auth', token)
|
|
|
|
|
|
|
|
// .query({
|
|
|
|
|
|
|
|
// fields: visibleColumns,
|
|
|
|
|
|
|
|
// sortArrJson: JSON.stringify(sortInfo),
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .expect(200);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (response.body.list.length !== rowCount) {
|
|
|
|
|
|
|
|
// throw new Error('Wrong number of rows');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const sameArrayContent = (a: Array<any>, b: Array<any>) => {
|
|
|
|
|
|
|
|
// return a.length === b.length && a.every((v, i) => v === b[i]);
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!sameArrayContent(Object.keys(response.body.list[0]), visibleColumns)) {
|
|
|
|
|
|
|
|
// console.error(Object.keys(response.body.list[0]), visibleColumns);
|
|
|
|
|
|
|
|
// throw new Error('Wrong column value');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (
|
|
|
|
|
|
|
|
// response.body.list[0][newTitleColumn.title] !== 'test-0' ||
|
|
|
|
|
|
|
|
// response.body.list[response.body.list.length - 1][
|
|
|
|
|
|
|
|
// newTitleColumn.title
|
|
|
|
|
|
|
|
// ] !== 'test-9'
|
|
|
|
|
|
|
|
// ) {
|
|
|
|
|
|
|
|
// throw new Error('Wrong sort');
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Get actors', async () => { |
|
|
|
|
|
|
|
const actorTable = await Model.getByIdOrName({ |
|
|
|
|
|
|
|
project_id: project.id, |
|
|
|
project_id: project.id, |
|
|
|
base_id: project.bases[0].id, |
|
|
|
base_id: project.bases[0].id, |
|
|
|
table_name: 'actor', |
|
|
|
table_name: 'customer', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
customerColumns = await customerTable.getColumns(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Get table data list', async function () { |
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
|
|
|
|
.get(`/api/v1/db/data/noco/${project.id}/${customerTable.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.send({}) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.body.list.length !== 25) { |
|
|
|
|
|
|
|
throw new Error('Wrong number of rows'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isColumnsCorrectInResponse(response, customerColumns)) { |
|
|
|
|
|
|
|
throw new Error('Wrong columns'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Get table data list with required columns', async function () { |
|
|
|
|
|
|
|
const requiredColumns = customerColumns.filter((_, index) => index < 3); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
|
|
|
|
.get(`/api/v1/db/data/noco/${project.id}/${customerTable.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.query({ |
|
|
|
|
|
|
|
fields: requiredColumns.map((c) => c.title), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.body.list.length !== 25) { |
|
|
|
|
|
|
|
throw new Error('Wrong number of rows'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isColumnsCorrectInResponse(response, requiredColumns)) { |
|
|
|
|
|
|
|
throw new Error('Wrong columns'); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
console.log(actorTable); |
|
|
|
|
|
|
|
|
|
|
|
it('Get desc sorted table data list with required columns', async function () { |
|
|
|
|
|
|
|
const firstNameColumn = customerColumns.find( |
|
|
|
|
|
|
|
(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/${project.id}/${customerTable.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.query({ |
|
|
|
|
|
|
|
fields: visibleColumns.map((c) => c.title), |
|
|
|
|
|
|
|
sortArrJson: JSON.stringify(sortInfo), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
const pageInfo = response.body.pageInfo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.body.list.length !== 25) { |
|
|
|
|
|
|
|
throw new Error('Wrong number of rows'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isColumnsCorrectInResponse(response, visibleColumns)) { |
|
|
|
|
|
|
|
console.log(response.body.list); |
|
|
|
|
|
|
|
throw new Error('Wrong columns'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.body.list[0][firstNameColumn.title] !== 'ZACHARY') { |
|
|
|
|
|
|
|
console.log(response.body.list); |
|
|
|
|
|
|
|
throw new Error('Wrong sort'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lastPageOffset = |
|
|
|
|
|
|
|
Math.trunc(pageInfo.totalRows / pageInfo.pageSize) * pageInfo.pageSize; |
|
|
|
|
|
|
|
const lastPageResponse = await request(context.app) |
|
|
|
|
|
|
|
.get(`/api/v1/db/data/noco/${project.id}/${customerTable.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.query({ |
|
|
|
|
|
|
|
fields: visibleColumns.map((c) => c.title), |
|
|
|
|
|
|
|
sortArrJson: JSON.stringify(sortInfo), |
|
|
|
|
|
|
|
offset: lastPageOffset, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
lastPageResponse.body.list[lastPageResponse.body.list.length - 1][ |
|
|
|
|
|
|
|
firstNameColumn.title |
|
|
|
|
|
|
|
] !== 'AARON' |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
console.log(lastPageOffset, lastPageResponse.body.list); |
|
|
|
|
|
|
|
throw new Error('Wrong sort on last page'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Get asc sorted table data list with required columns', async function () { |
|
|
|
|
|
|
|
const firstNameColumn = customerColumns.find( |
|
|
|
|
|
|
|
(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/${project.id}/${customerTable.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.query({ |
|
|
|
|
|
|
|
fields: visibleColumns.map((c) => c.title), |
|
|
|
|
|
|
|
sortArrJson: JSON.stringify(sortInfo), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
const pageInfo = response.body.pageInfo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.body.list.length !== 25) { |
|
|
|
|
|
|
|
throw new Error('Wrong number of rows'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isColumnsCorrectInResponse(response, visibleColumns)) { |
|
|
|
|
|
|
|
console.log(response.body.list); |
|
|
|
|
|
|
|
throw new Error('Wrong columns'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response.body.list[0][firstNameColumn.title] !== 'AARON') { |
|
|
|
|
|
|
|
console.log(response.body.list); |
|
|
|
|
|
|
|
throw new Error('Wrong sort'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lastPageOffset = |
|
|
|
|
|
|
|
Math.trunc(pageInfo.totalRows / pageInfo.pageSize) * pageInfo.pageSize; |
|
|
|
|
|
|
|
const lastPageResponse = await request(context.app) |
|
|
|
|
|
|
|
.get(`/api/v1/db/data/noco/${project.id}/${customerTable.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.query({ |
|
|
|
|
|
|
|
fields: visibleColumns.map((c) => c.title), |
|
|
|
|
|
|
|
sortArrJson: JSON.stringify(sortInfo), |
|
|
|
|
|
|
|
offset: lastPageOffset, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
lastPageResponse.body.list[lastPageResponse.body.list.length - 1][ |
|
|
|
|
|
|
|
firstNameColumn.title |
|
|
|
|
|
|
|
] !== 'ZACHARY' |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
console.log(lastPageOffset, lastPageResponse.body.list); |
|
|
|
|
|
|
|
throw new Error('Wrong sort on last page'); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|