|
|
@ -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
|
|
|
|