Skip to content
Snippets Groups Projects
Commit 76b8d0d2 authored by Sebastian's avatar Sebastian
Browse files

feat(component-invite): fix all tests

parent 0fb3fa14
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ module.exports = models => async (req, res) => { ...@@ -20,7 +20,7 @@ module.exports = models => async (req, res) => {
} }
const reqUser = await models.User.find(req.user) const reqUser = await models.User.find(req.user)
if (!reqUser.editorInChief || !reqUser.admin) { if (!reqUser.editorInChief && !reqUser.admin) {
res res
.status(400) .status(400)
.json({ error: 'The request user must be Editor in Chief or Admin' }) .json({ error: 'The request user must be Editor in Chief or Admin' })
......
...@@ -9,7 +9,7 @@ jest.mock('pubsweet-component-mail-service', () => ({ ...@@ -9,7 +9,7 @@ jest.mock('pubsweet-component-mail-service', () => ({
setupRevokeInvitationEmail: jest.fn(), setupRevokeInvitationEmail: jest.fn(),
})) }))
const { standardCollection, noTeamCollection } = fixtures.collections const { standardCollection, noTeamCollection } = fixtures.collections
const { editorInChief, admin, handlingEditor } = fixtures.users const { editorInChief, admin, handlingEditor, author } = fixtures.users
const { heTeam } = fixtures.teams const { heTeam } = fixtures.teams
const query = { const query = {
role: 'handlingEditor', role: 'handlingEditor',
...@@ -83,12 +83,14 @@ describe('Delete Invitation route handler', () => { ...@@ -83,12 +83,14 @@ describe('Delete Invitation route handler', () => {
const req = httpMocks.createRequest() const req = httpMocks.createRequest()
req.query = query req.query = query
req.params.collectionId = standardCollection.id req.params.collectionId = standardCollection.id
req.user = admin.id req.user = author.id
const res = httpMocks.createResponse() const res = httpMocks.createResponse()
await require(deleteInvitationPath)(models)(req, res) await require(deleteInvitationPath)(models)(req, res)
expect(res.statusCode).toBe(400) expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData()) const data = JSON.parse(res._getData())
expect(data.error).toEqual('The request user must be Editor in Chief') expect(data.error).toEqual(
'The request user must be Editor in Chief or Admin',
)
}) })
it('should return an error when the collection does not have a the requested role team', async () => { it('should return an error when the collection does not have a the requested role team', async () => {
const req = httpMocks.createRequest() const req = httpMocks.createRequest()
......
...@@ -6,7 +6,7 @@ const fixtures = require('./fixtures/fixtures') ...@@ -6,7 +6,7 @@ const fixtures = require('./fixtures/fixtures')
const Model = require('./helpers/Model') const Model = require('./helpers/Model')
const { standardCollection, noTeamCollection } = fixtures.collections const { standardCollection, noTeamCollection } = fixtures.collections
const { editorInChief, admin } = fixtures.users const { editorInChief } = fixtures.users
const query = { const query = {
role: 'handlingEditor', role: 'handlingEditor',
} }
...@@ -64,18 +64,6 @@ describe('Get collection users route handler', () => { ...@@ -64,18 +64,6 @@ describe('Get collection users route handler', () => {
expect(data.error).toEqual(`Role ${query.role} is invalid`) expect(data.error).toEqual(`Role ${query.role} is invalid`)
query.role = 'handlingEditor' query.role = 'handlingEditor'
}) })
it('should return an error when the request user is not editorInChief', async () => {
const req = httpMocks.createRequest()
req.query = query
req.params.collectionId = standardCollection.id
req.user = admin.id
const res = httpMocks.createResponse()
const models = Model.build()
await require(getCollectionUsersPath)(models)(req, res)
expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData())
expect(data.error).toEqual('The request user must be Editor in Chief')
})
it('should return an error when the collection does not have a the requested role team', async () => { it('should return an error when the collection does not have a the requested role team', async () => {
const req = httpMocks.createRequest() const req = httpMocks.createRequest()
req.query = query req.query = query
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment