Browse Source

refactor/Added unit test for delete relation apis

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
0e4b95f06e
  1. 4
      packages/nocodb/tests/unit/rest/tests/factory/row.ts
  2. 79
      packages/nocodb/tests/unit/rest/tests/tableRow.test.ts

4
packages/nocodb/tests/unit/rest/tests/factory/row.ts

@ -145,6 +145,10 @@ const createRelation = async (
`/api/v1/db/data/noco/${project.id}/${table.id}/${rowId}/${type}/${column.title}/${childRowId}` `/api/v1/db/data/noco/${project.id}/${table.id}/${rowId}/${type}/${column.title}/${childRowId}`
) )
.set('xc-auth', context.token); .set('xc-auth', context.token);
const row = await getRow(context, { project, table, id: rowId });
return row;
}; };
export { export {

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

@ -1760,6 +1760,85 @@ function tableTest() {
.set('xc-auth', context.token) .set('xc-auth', context.token)
.expect(400) .expect(400)
}) })
it('Delete mm existing ref row 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 refId = 1;
const lisResponseBeforeDelete = 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);
await request(context.app)
.delete(`/api/v1/db/data/noco/${sakilaProject.id}/${actorTable.id}/${rowId}/mm/${filmListColumn.id}/${refId}`)
.set('xc-auth', context.token)
.expect(200);
global.touchedSakilaDb = true;
const lisResponseAfterDelete = 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);
if(lisResponseAfterDelete.body.pageInfo.totalRows !== lisResponseBeforeDelete.body.pageInfo.totalRows - 1) {
throw new Error('Item not deleted');
}
})
it('Delete list hm with existing ref row id with non nullable clause', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(
(column) => column.title === 'Rental List'
)!;
const refId = 76;
const response = await request(context.app)
.delete(`/api/v1/db/data/noco/${sakilaProject.id}/${customerTable.id}/${rowId}/hm/${rentalListColumn.id}/${refId}`)
.set('xc-auth', context.token)
.expect(400);
if(!response.body.msg.includes("Column 'customer_id' cannot be null")){
console.log(response.body)
throw new Error('Wrong error message')
}
})
it('Delete list hm with existing ref row id', async () => {
const table = await createTable(context, project);
const relatedTable = await createTable(context, project, {
table_name: 'Table2',
title: 'Table2_Title',
});
const ltarColumn = await createLtarColumn(context, {
title: 'Ltar',
parentTable: table,
childTable: relatedTable,
type: 'hm',
});
const row = await createRelation(context, { project, table,childTable: relatedTable, column:ltarColumn, type: 'hm' });
const childRow = row['Ltar'][0]
const response = await request(context.app)
.delete(`/api/v1/db/data/noco/${project.id}/${table.id}/${row['Id']}/hm/${ltarColumn.id}/${childRow['Id']}`)
.set('xc-auth', context.token)
.expect(200);
const updatedRow = await getRow(context, {project, table,id: row['Id']})
if(updatedRow['Ltar'].length !== 0){
throw new Error('Was not deleted')
}
if(response.body['msg'] !== 'success') {
throw new Error('Response incorrect')
}
})
} }
export default function () { export default function () {

Loading…
Cancel
Save