From 5d816a0b82dd16e3d74598af52199020631930ac Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Sat, 27 Aug 2022 16:20:35 +0530 Subject: [PATCH] refactor/Added some unit tests for project api --- .../__tests__/unit/rest/tests/project.test.ts | 65 ++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/packages/nocodb/src/__tests__/unit/rest/tests/project.test.ts b/packages/nocodb/src/__tests__/unit/rest/tests/project.test.ts index a5bc5dcf51..a576c395c2 100644 --- a/packages/nocodb/src/__tests__/unit/rest/tests/project.test.ts +++ b/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 // it('Delete project', async (done) => { // const toBeDeletedProject = await createProject(app, token, { @@ -94,27 +104,52 @@ function projectTest() { // }); // }); - it('Update projects', function (done) { + it('Read project', (done) => { request(app) - .patch(`/api/v1/db/meta/projects/${project.id}`) + .get(`/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; - } + .send() + .expect(200, (err, res) => { + if (err) return done(err); + + if (res.body.id !== project.id) return done('Got the wrong project'); 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 () {