Browse Source

fix/Integrated new testing scheme to project tests

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
dcdead507e
  1. 17
      packages/nocodb/src/__tests__/unit/rest/tests/helpers/project.ts
  2. 60
      packages/nocodb/src/__tests__/unit/rest/tests/project.test.ts

17
packages/nocodb/src/__tests__/unit/rest/tests/helpers/project.ts

@ -4,6 +4,21 @@ const defaultProjectValue = {
title: 'Title', title: 'Title',
}; };
const defaultSharedBaseValue = {
roles: 'viewer',
password: 'test',
};
const createSharedBase = async (app, token, project, sharedBaseArgs = {}) => {
await request(app)
.post(`/api/v1/db/meta/projects/${project.id}/shared`)
.set('xc-auth', token)
.send({
...defaultSharedBaseValue,
...sharedBaseArgs,
});
};
const createProject = async (app, token, projectArgs = defaultProjectValue) => { const createProject = async (app, token, projectArgs = defaultProjectValue) => {
const response = await request(app) const response = await request(app)
.post('/api/v1/db/meta/projects/') .post('/api/v1/db/meta/projects/')
@ -14,4 +29,4 @@ const createProject = async (app, token, projectArgs = defaultProjectValue) => {
return project; return project;
}; };
export { createProject }; export { createProject, createSharedBase };

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

@ -2,9 +2,10 @@ import 'mocha';
import request from 'supertest'; import request from 'supertest';
import server from '../server'; import server from '../server';
import Project from '../../../../lib/models/Project'; import Project from '../../../../lib/models/Project';
import { createProject } from './helpers/project'; import { createProject, createSharedBase } from './helpers/project';
import { createUser } from './helpers/user'; import { createUser } from './helpers/user';
import { beforeEach } from 'mocha'; import { beforeEach } from 'mocha';
import { Exception } from 'handlebars';
function projectTest() { function projectTest() {
let app; let app;
@ -198,78 +199,69 @@ function projectTest() {
}); });
}); });
it('Updated project shared base should have only editor or viewer role', (done) => { it('Updated project shared base should have only editor or viewer role', async () => {
request(app) await createSharedBase(app, token, project);
await request(app)
.patch(`/api/v1/db/meta/projects/${project.id}/shared`) .patch(`/api/v1/db/meta/projects/${project.id}/shared`)
.set('xc-auth', token) .set('xc-auth', token)
.send({ .send({
roles: 'commenter', roles: 'commenter',
password: 'test', password: 'test',
}) })
.expect(200, async (err) => { .expect(200);
if (err) return done(err);
const updatedProject = await Project.getByTitleOrId(project.id); const updatedProject = await Project.getByTitleOrId(project.id);
if (updatedProject.roles === 'commenter') { if (updatedProject.roles === 'commenter') {
return done('Shared base not updated properly'); throw new Exception('Shared base not updated properly');
} }
done();
});
}); });
it('Updated project shared base', (done) => { it('Updated project shared base', async () => {
request(app) await createSharedBase(app, token, project);
await request(app)
.patch(`/api/v1/db/meta/projects/${project.id}/shared`) .patch(`/api/v1/db/meta/projects/${project.id}/shared`)
.set('xc-auth', token) .set('xc-auth', token)
.send({ .send({
roles: 'editor', roles: 'editor',
password: 'test', password: 'test',
}) })
.expect(200, async (err) => { .expect(200);
if (err) return done(err);
const updatedProject = await Project.getByTitleOrId(project.id); const updatedProject = await Project.getByTitleOrId(project.id);
if (updatedProject.roles !== 'editor') { if (updatedProject.roles !== 'editor') {
return done('Shared base not updated properly'); throw new Exception('Shared base not updated properly');
} }
done();
});
}); });
it('Get project shared base', (done) => { it('Get project shared base', async () => {
request(app) await createSharedBase(app, token, project);
await request(app)
.get(`/api/v1/db/meta/projects/${project.id}/shared`) .get(`/api/v1/db/meta/projects/${project.id}/shared`)
.set('xc-auth', token) .set('xc-auth', token)
.send() .send()
.expect(200, async (err) => { .expect(200);
if (err) return done(err);
const updatedProject = await Project.getByTitleOrId(project.id); const updatedProject = await Project.getByTitleOrId(project.id);
if (!updatedProject.uuid) { if (!updatedProject.uuid) {
return done('Shared base not created'); throw new Exception('Shared base not created');
} }
done();
});
}); });
it('Delete project shared base', (done) => { it('Delete project shared base', async () => {
request(app) await createSharedBase(app, token, project);
await request(app)
.delete(`/api/v1/db/meta/projects/${project.id}/shared`) .delete(`/api/v1/db/meta/projects/${project.id}/shared`)
.set('xc-auth', token) .set('xc-auth', token)
.send() .send()
.expect(200, async (err) => { .expect(200);
if (err) return done(err);
const updatedProject = await Project.getByTitleOrId(project.id); const updatedProject = await Project.getByTitleOrId(project.id);
if (updatedProject.uuid) { if (updatedProject.uuid) {
return done('Shared base not delete'); throw new Exception('Shared base not deleted');
} }
done();
});
}); });
// todo: Do compare api test // todo: Do compare api test

Loading…
Cancel
Save