Browse Source

refactor/Added some unit tests for project api

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
5d816a0b82
  1. 65
      packages/nocodb/src/__tests__/unit/rest/tests/project.test.ts

65
packages/nocodb/src/__tests__/unit/rest/tests/project.test.ts

@ -70,6 +70,16 @@ function projectTest() {
}); });
}); });
it('Create projects with existing title', function (done) {
request(app)
.post(`/api/v1/db/meta/projects/`)
.set('xc-auth', token)
.send({
title: project.title,
})
.expect(400, done);
});
// todo: fix passport user role popluation bug // todo: fix passport user role popluation bug
// it('Delete project', async (done) => { // it('Delete project', async (done) => {
// const toBeDeletedProject = await createProject(app, token, { // const toBeDeletedProject = await createProject(app, token, {
@ -94,27 +104,52 @@ function projectTest() {
// }); // });
// }); // });
it('Update projects', function (done) { it('Read project', (done) => {
request(app) request(app)
.patch(`/api/v1/db/meta/projects/${project.id}`) .get(`/api/v1/db/meta/projects/${project.id}`)
.set('xc-auth', token) .set('xc-auth', token)
.send({ .send()
title: 'NewTitle', .expect(200, (err, res) => {
}) if (err) return done(err);
.expect(200, async (err) => {
if (err) { if (res.body.id !== project.id) return done('Got the wrong project');
done(err);
return;
}
const newProject = await Project.getByTitleOrId(project.id);
if (newProject.title !== 'NewTitle') {
done('Project not updated');
return;
}
done(); done();
}); });
}); });
// it('Update projects', function (done) {
// request(app)
// .patch(`/api/v1/db/meta/projects/${project.id}`)
// .set('xc-auth', token)
// .send({
// title: 'NewTitle',
// })
// .expect(200, async (err) => {
// if (err) {
// done(err);
// return;
// }
// const newProject = await Project.getByTitleOrId(project.id);
// if (newProject.title !== 'NewTitle') {
// done('Project not updated');
// return;
// }
// done();
// });
// });
it('Update projects with existing title', async function () {
const newProject = await createProject(app, token, { title: 'NewTitle1' });
return await request(app)
.patch(`/api/v1/db/meta/projects/${project.id}`)
.set('xc-auth', token)
.send({
title: newProject.title,
})
.expect(400);
});
} }
export default function () { export default function () {

Loading…
Cancel
Save