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) => {
}
const reqUser = await models.User.find(req.user)
if (!reqUser.editorInChief || !reqUser.admin) {
if (!reqUser.editorInChief && !reqUser.admin) {
res
.status(400)
.json({ error: 'The request user must be Editor in Chief or Admin' })
......
......@@ -9,7 +9,7 @@ jest.mock('pubsweet-component-mail-service', () => ({
setupRevokeInvitationEmail: jest.fn(),
}))
const { standardCollection, noTeamCollection } = fixtures.collections
const { editorInChief, admin, handlingEditor } = fixtures.users
const { editorInChief, admin, handlingEditor, author } = fixtures.users
const { heTeam } = fixtures.teams
const query = {
role: 'handlingEditor',
......@@ -83,12 +83,14 @@ describe('Delete Invitation route handler', () => {
const req = httpMocks.createRequest()
req.query = query
req.params.collectionId = standardCollection.id
req.user = admin.id
req.user = author.id
const res = httpMocks.createResponse()
await require(deleteInvitationPath)(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')
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 () => {
const req = httpMocks.createRequest()
......
......@@ -6,7 +6,7 @@ const fixtures = require('./fixtures/fixtures')
const Model = require('./helpers/Model')
const { standardCollection, noTeamCollection } = fixtures.collections
const { editorInChief, admin } = fixtures.users
const { editorInChief } = fixtures.users
const query = {
role: 'handlingEditor',
}
......@@ -64,18 +64,6 @@ describe('Get collection users route handler', () => {
expect(data.error).toEqual(`Role ${query.role} is invalid`)
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 () => {
const req = httpMocks.createRequest()
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