|
|
@ -9,7 +9,7 @@ import { |
|
|
|
createLtarColumn, |
|
|
|
createLtarColumn, |
|
|
|
createRollupColumn, |
|
|
|
createRollupColumn, |
|
|
|
} from './factory/column'; |
|
|
|
} from './factory/column'; |
|
|
|
import { createTable } from './factory/table'; |
|
|
|
import { createTable, getTable } from './factory/table'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
createRelation, |
|
|
|
createRelation, |
|
|
|
createRow, |
|
|
|
createRow, |
|
|
@ -21,6 +21,7 @@ import { |
|
|
|
import { isMysql, isSqlite } from '../init/db'; |
|
|
|
import { isMysql, isSqlite } from '../init/db'; |
|
|
|
import Model from '../../../../src/lib/models/Model'; |
|
|
|
import Model from '../../../../src/lib/models/Model'; |
|
|
|
import console from 'console'; |
|
|
|
import console from 'console'; |
|
|
|
|
|
|
|
import Project from '../../../../src/lib/models/Project'; |
|
|
|
|
|
|
|
|
|
|
|
const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => { |
|
|
|
const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => { |
|
|
|
const responseColumnsListStr = Object.keys(row).sort().join(','); |
|
|
|
const responseColumnsListStr = Object.keys(row).sort().join(','); |
|
|
@ -34,8 +35,8 @@ const isColumnsCorrectInResponse = (row, columns: ColumnType[]) => { |
|
|
|
|
|
|
|
|
|
|
|
function tableTest() { |
|
|
|
function tableTest() { |
|
|
|
let context; |
|
|
|
let context; |
|
|
|
let project; |
|
|
|
let project: Project; |
|
|
|
let sakilaProject; |
|
|
|
let sakilaProject: Project; |
|
|
|
let customerTable: Model; |
|
|
|
let customerTable: Model; |
|
|
|
let customerColumns; |
|
|
|
let customerColumns; |
|
|
|
|
|
|
|
|
|
|
@ -45,11 +46,7 @@ function tableTest() { |
|
|
|
sakilaProject = await createSakilaProject(context); |
|
|
|
sakilaProject = await createSakilaProject(context); |
|
|
|
project = await createProject(context); |
|
|
|
project = await createProject(context); |
|
|
|
|
|
|
|
|
|
|
|
customerTable = await Model.getByIdOrName({ |
|
|
|
customerTable = await getTable({project: sakilaProject, name: 'customer'}) |
|
|
|
project_id: sakilaProject.id, |
|
|
|
|
|
|
|
base_id: sakilaProject.bases[0].id, |
|
|
|
|
|
|
|
table_name: 'customer', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
customerColumns = await customerTable.getColumns(); |
|
|
|
customerColumns = await customerTable.getColumns(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -233,11 +230,7 @@ function tableTest() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Get sorted table data list with a lookup column', async function () { |
|
|
|
it('Get sorted table data list with a lookup column', async function () { |
|
|
|
const rentalTable = await Model.getByIdOrName({ |
|
|
|
const rentalTable = await getTable({project: sakilaProject, name: 'rental'}) |
|
|
|
project_id: sakilaProject.id, |
|
|
|
|
|
|
|
base_id: sakilaProject.bases[0].id, |
|
|
|
|
|
|
|
table_name: 'rental', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lookupColumn = await createLookupColumn(context, { |
|
|
|
const lookupColumn = await createLookupColumn(context, { |
|
|
|
project: sakilaProject, |
|
|
|
project: sakilaProject, |
|
|
@ -274,11 +267,7 @@ function tableTest() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Get filtered table data list with a lookup column', async function () { |
|
|
|
it('Get filtered table data list with a lookup column', async function () { |
|
|
|
const rentalTable = await Model.getByIdOrName({ |
|
|
|
const rentalTable = await getTable({project: sakilaProject, name: 'rental'}); |
|
|
|
project_id: sakilaProject.id, |
|
|
|
|
|
|
|
base_id: sakilaProject.bases[0].id, |
|
|
|
|
|
|
|
table_name: 'rental', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lookupColumn = await createLookupColumn(context, { |
|
|
|
const lookupColumn = await createLookupColumn(context, { |
|
|
|
project: sakilaProject, |
|
|
|
project: sakilaProject, |
|
|
@ -342,11 +331,7 @@ function tableTest() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('Get nested sorted filtered table data list with a lookup column', async function () { |
|
|
|
it('Get nested sorted filtered table data list with a lookup column', async function () { |
|
|
|
const rentalTable = await Model.getByIdOrName({ |
|
|
|
const rentalTable = await getTable({project: sakilaProject, name: 'rental'}); |
|
|
|
project_id: sakilaProject.id, |
|
|
|
|
|
|
|
base_id: sakilaProject.bases[0].id, |
|
|
|
|
|
|
|
table_name: 'rental', |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lookupColumn = await createLookupColumn(context, { |
|
|
|
const lookupColumn = await createLookupColumn(context, { |
|
|
|
project: sakilaProject, |
|
|
|
project: sakilaProject, |
|
|
@ -1527,6 +1512,65 @@ function tableTest() { |
|
|
|
throw new Error('Wrong error message'); |
|
|
|
throw new Error('Wrong error message'); |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Nested row list mm', async () => { |
|
|
|
|
|
|
|
const rowId = 1; |
|
|
|
|
|
|
|
const actorTable = await getTable({project: sakilaProject, name: 'actor'}); |
|
|
|
|
|
|
|
const filmTable = await getTable({project: sakilaProject, name: 'film'}); |
|
|
|
|
|
|
|
const filmListColumn = (await actorTable.getColumns()).find( |
|
|
|
|
|
|
|
(column) => column.title === 'Film List' |
|
|
|
|
|
|
|
)!; |
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
|
|
|
|
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pageInfo = response.body['pageInfo'] |
|
|
|
|
|
|
|
if(pageInfo['totalRows'] !== 19 || pageInfo['pageSize'] !== 25) { |
|
|
|
|
|
|
|
console.log(pageInfo) |
|
|
|
|
|
|
|
throw new Error('Wrong total rows'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Nested row list mm with limit and offset', async () => { |
|
|
|
|
|
|
|
const rowId = 1; |
|
|
|
|
|
|
|
const actorTable = await getTable({project: sakilaProject, name: 'actor'}); |
|
|
|
|
|
|
|
const filmTable = await getTable({project: sakilaProject, name: 'film'}); |
|
|
|
|
|
|
|
const filmListColumn = (await actorTable.getColumns()).find( |
|
|
|
|
|
|
|
(column) => column.title === 'Film List' |
|
|
|
|
|
|
|
)!; |
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
|
|
|
|
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.query({ |
|
|
|
|
|
|
|
limit: 30, |
|
|
|
|
|
|
|
offset: 10 |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.expect(200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pageInfo = response.body['pageInfo'] |
|
|
|
|
|
|
|
if(pageInfo['totalRows'] !== 19 || pageInfo['pageSize'] !== 30 || response.body.list.length !== 9) { |
|
|
|
|
|
|
|
console.log(pageInfo, response.body.list.length) |
|
|
|
|
|
|
|
throw new Error('Wrong total rows'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('Row list mm with invalid table id', async () => { |
|
|
|
|
|
|
|
const rowId = 1 |
|
|
|
|
|
|
|
const actorTable = await getTable({project: sakilaProject, name: 'actor'}); |
|
|
|
|
|
|
|
const filmListColumn = (await actorTable.getColumns()).find( |
|
|
|
|
|
|
|
(column) => column.title === 'Film List' |
|
|
|
|
|
|
|
)!; |
|
|
|
|
|
|
|
const response = await request(context.app) |
|
|
|
|
|
|
|
.get(`/api/v1/db/data/noco/${sakilaProject.id}/invalid-table-id/${rowId}/mm/${filmListColumn.id}`) |
|
|
|
|
|
|
|
.set('xc-auth', context.token) |
|
|
|
|
|
|
|
.expect(404); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(response.body['msg'] !== 'Table not found') { |
|
|
|
|
|
|
|
console.log(response.body) |
|
|
|
|
|
|
|
throw new Error('Wrong error message'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default function () { |
|
|
|
export default function () { |
|
|
|