Browse Source

refactor/Added unit test to get table row and improved api validation

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
95e3c88a3d
  1. 10
      packages/nocodb/src/__tests__/unit/rest/tests/factory/row.ts
  2. 29
      packages/nocodb/src/__tests__/unit/rest/tests/tableRow.test.ts
  3. 12
      packages/nocodb/src/lib/models/Model.ts

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

@ -16,6 +16,14 @@ const rowValue = (column: ColumnType, index: number) => {
}
};
const getRow = async (context, project, table, id) => {
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${project.id}/${table.id}/${id}`)
.set('xc-auth', context.token);
return response.body;
};
const createRow = async (
context,
project,
@ -36,4 +44,4 @@ const createRow = async (
return response.body;
};
export { createRow };
export { createRow, getRow };

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

@ -9,6 +9,7 @@ import {
createLookupColumn,
createRollupColumn,
} from './factory/column';
import { createTable } from './factory/table';
const isColumnsCorrectInResponse = (response, columns: ColumnType[]) => {
const responseColumnsListStr = Object.keys(response.body.list[0])
@ -752,6 +753,34 @@ function tableTest() {
// console.log(response.body);
// });
it('Create table row', async function () {
const table = await createTable(context, project);
const response = await request(context.app)
.post(`/api/v1/db/data/noco/${project.id}/${table.id}`)
.set('xc-auth', context.token)
.send({
title: 'Test',
})
.expect(200);
const row = response.body;
if (row['Title'] !== 'Test') throw new Error('Wrong row title');
});
it('Create table row with wrong table id', async function () {
const response = await request(context.app)
.post(`/api/v1/db/data/noco/${project.id}/wrong-table-id`)
.set('xc-auth', context.token)
.send({
title: 'Test',
})
.expect(404);
if (response.body.msg !== 'Table not found')
throw new Error('Wrong error message');
});
}
export default function () {

12
packages/nocodb/src/lib/models/Model.ts

@ -628,11 +628,13 @@ export default class Model implements TableType {
],
}
);
await NocoCache.set(
`${CacheScope.MODEL}:${project_id}:${aliasOrId}`,
model.id
);
await NocoCache.set(`${CacheScope.MODEL}:${model.id}`, model);
if (model) {
await NocoCache.set(
`${CacheScope.MODEL}:${project_id}:${aliasOrId}`,
model.id
);
await NocoCache.set(`${CacheScope.MODEL}:${model.id}`, model);
}
return model && new Model(model);
}
return modelId && this.get(modelId);

Loading…
Cancel
Save