Skip to content
Snippets Groups Projects
Commit 348d9f30 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

Merge branch 'master' of gitlab.coko.foundation:xpub/xpub-faraday

parents 0d84c1db 1f8c43d3
No related branches found
No related tags found
No related merge requests found
...@@ -46,9 +46,11 @@ const CollectionsInvitations = app => { ...@@ -46,9 +46,11 @@ const CollectionsInvitations = app => {
require(`${routePath}/post`)(app.locals.models), require(`${routePath}/post`)(app.locals.models),
) )
/** /**
* @api {get} /api/collections/:collectionId/invitations List collections invitations * @api {get} /api/collections/:collectionId/invitations/{:invitationId}?role=:role List collections invitations
* @apiGroup CollectionsInvitations * @apiGroup CollectionsInvitations
* @apiParam {collectionId} id Collection id * @apiParam {id} collectionId Collection id
* @apiParam {id} [invitationId] Invitation id
* @apiParam {String} role The role to search for: handlingEditor, reviewer, author
* @apiSuccessExample {json} Success * @apiSuccessExample {json} Success
* HTTP/1.1 200 OK * HTTP/1.1 200 OK
* [{ * [{
...@@ -56,6 +58,7 @@ const CollectionsInvitations = app => { ...@@ -56,6 +58,7 @@ const CollectionsInvitations = app => {
* "timestamp": "123223121", * "timestamp": "123223121",
* "email": "email@example.com", * "email": "email@example.com",
* "status": "pending", * "status": "pending",
* "invitationId": "1990881"
* }] * }]
* @apiErrorExample {json} List errors * @apiErrorExample {json} List errors
* HTTP/1.1 403 Forbidden * HTTP/1.1 403 Forbidden
......
...@@ -11,8 +11,8 @@ const getInvitationData = (invitations, userId, role) => { ...@@ -11,8 +11,8 @@ const getInvitationData = (invitations, userId, role) => {
status = 'refused' status = 'refused'
} }
const { timestamp } = matchingInvitation const { timestamp, id } = matchingInvitation
return { timestamp, status } return { timestamp, status, id }
} }
const setupInvitation = async (userId, role, collection) => { const setupInvitation = async (userId, role, collection) => {
......
...@@ -5,10 +5,10 @@ const inviteHelper = require('../../helpers/Invitation') ...@@ -5,10 +5,10 @@ const inviteHelper = require('../../helpers/Invitation')
const configRoles = config.get('roles') const configRoles = config.get('roles')
module.exports = models => async (req, res) => { module.exports = models => async (req, res) => {
const { userId, role } = req.query const { role } = req.query
// TO DO: authsome // TO DO: authsome
if (!helpers.checkForUndefinedParams(userId, role)) { if (!helpers.checkForUndefinedParams(role)) {
res.status(400).json({ error: 'User ID and Role are required' }) res.status(400).json({ error: 'Role is required' })
return return
} }
...@@ -32,11 +32,12 @@ module.exports = models => async (req, res) => { ...@@ -32,11 +32,12 @@ module.exports = models => async (req, res) => {
return return
} }
// TO DO: handle case for when the invitationID is provided
const membersData = members.map(async member => { const membersData = members.map(async member => {
const user = await models.User.find(member) const user = await models.User.find(member)
const { timestamp, status } = inviteHelper.getInvitationData( const { timestamp, status, id } = inviteHelper.getInvitationData(
collection.invitations, collection.invitations,
userId, user.id,
role, role,
) )
return { return {
...@@ -44,6 +45,7 @@ module.exports = models => async (req, res) => { ...@@ -44,6 +45,7 @@ module.exports = models => async (req, res) => {
timestamp, timestamp,
email: user.email, email: user.email,
status, status,
invitationId: id,
} }
}) })
......
...@@ -42,21 +42,6 @@ describe('Delete Collections Invitations route handler', () => { ...@@ -42,21 +42,6 @@ describe('Delete Collections Invitations route handler', () => {
const data = JSON.parse(res._getData()) const data = JSON.parse(res._getData())
expect(data.error).toEqual('Invitation invalid-id not found') expect(data.error).toEqual('Invitation invalid-id not found')
}) })
it('should return an error when the request user is not editorInChief or admin', async () => {
const { user } = testFixtures.users
const { collection } = testFixtures.collections
const req = httpMocks.createRequest()
req.params.collectionId = collection.id
req.params.invitationId = collection.invitations[0].id
req.user = user.id
const res = httpMocks.createResponse()
await require(deletePath)(models)(req, res)
expect(res.statusCode).toBe(403)
const data = JSON.parse(res._getData())
expect(data.error).toEqual(
'The request user must be Editor in Chief or Admin',
)
})
it('should return success when the collection and invitation exist', async () => { it('should return success when the collection and invitation exist', async () => {
const { editorInChief } = testFixtures.users const { editorInChief } = testFixtures.users
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
......
...@@ -40,7 +40,7 @@ describe('Get collection invitations route handler', () => { ...@@ -40,7 +40,7 @@ describe('Get collection invitations route handler', () => {
await require(getPath)(models)(req, res) await require(getPath)(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('User ID and Role are required') expect(data.error).toEqual('Role is required')
}) })
it('should return an error when the collection does not exist', async () => { it('should return an error when the collection does not exist', async () => {
const { editorInChief, handlingEditor } = testFixtures.users const { editorInChief, handlingEditor } = testFixtures.users
...@@ -96,23 +96,4 @@ describe('Get collection invitations route handler', () => { ...@@ -96,23 +96,4 @@ describe('Get collection invitations route handler', () => {
`The requested collection does not have a ${req.query.role} Team`, `The requested collection does not have a ${req.query.role} Team`,
) )
}) })
it('should return an error when the request user is not EiC or Admin', async () => {
const { user, handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections
const req = httpMocks.createRequest()
req.query = {
role: 'handlingEditor',
userId: handlingEditor.id,
}
req.params.collectionId = collection.id
req.user = user.id
const res = httpMocks.createResponse()
const models = Model.build()
await require(getPath)(models)(req, res)
expect(res.statusCode).toBe(403)
const data = JSON.parse(res._getData())
expect(data.error).toEqual(
`The request user must be Editor in Chief or Admin`,
)
})
}) })
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