Skip to content
Snippets Groups Projects
Commit 148c6512 authored by Tania Fecheta's avatar Tania Fecheta
Browse files

test(isAdmin): added unit tests for isAdmin function

parent 3fc0964a
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!204Hin 1232 send correct email to new author
...@@ -64,7 +64,7 @@ class User { ...@@ -64,7 +64,7 @@ class User {
return eics return eics
} }
async userIsAdmin(user) { async isAdmin(user) {
const { UserModel } = this const { UserModel } = this
const users = await UserModel.all() const users = await UserModel.all()
const admin = users.filter(user => user.admin) const admin = users.filter(user => user.admin)
......
...@@ -5,7 +5,7 @@ const { cloneDeep } = require('lodash') ...@@ -5,7 +5,7 @@ const { cloneDeep } = require('lodash')
const fixturesService = require('pubsweet-component-fixture-service') const fixturesService = require('pubsweet-component-fixture-service')
const { fixtures, Model } = fixturesService const { fixtures, Model } = fixturesService
const { Collection, Fragment } = require('../Helper') const { Collection, Fragment, User } = require('../Helper')
describe('Collection helper', () => { describe('Collection helper', () => {
let testFixtures = {} let testFixtures = {}
...@@ -231,4 +231,26 @@ describe('Collection helper', () => { ...@@ -231,4 +231,26 @@ describe('Collection helper', () => {
expect(canHEMakeRecommendation).toBe(false) expect(canHEMakeRecommendation).toBe(false)
}) })
}) })
describe('isAdmin', () => {
it('should return true if user is admin', async () => {
const { admin } = testFixtures.users
const adminId = admin.id
const UserModel = models.User
const userHelper = new User({ UserModel })
const isAdmin = await userHelper.isAdmin(adminId)
expect(isAdmin).toBe(true)
})
it('should return false if user is not admin', async () => {
const { reviewer } = testFixtures.users
const reviewerId = reviewer.id
const UserModel = models.User
const userHelper = new User({ UserModel })
const isAdmin = await userHelper.isAdmin(reviewerId)
expect(isAdmin).toBe(false)
})
})
}) })
...@@ -62,7 +62,7 @@ module.exports = models => async (req, res) => { ...@@ -62,7 +62,7 @@ module.exports = models => async (req, res) => {
fragment.files.manuscripts, fragment.files.manuscripts,
fragment.files.coverLetter, fragment.files.coverLetter,
fragment.files.supplementary, fragment.files.supplementary,
fragmentId, { id: fragmentId },
) )
fileKeys = fileKeys.map(file => file.id) fileKeys = fileKeys.map(file => file.id)
......
...@@ -57,9 +57,7 @@ module.exports = { ...@@ -57,9 +57,7 @@ module.exports = {
const fragmentHelper = new Fragment({ fragment }) const fragmentHelper = new Fragment({ fragment })
const collectionOwners = get(collection, 'owners') const collectionOwners = get(collection, 'owners')
const userHelper = new User({ UserModel }) const userHelper = new User({ UserModel })
const adminOwner = collectionOwners.find(owner => const adminOwner = collectionOwners.find(owner => userHelper.isAdmin(owner))
userHelper.userIsAdmin(owner),
)
const handlingEditor = get(collection, 'handlingEditor') const handlingEditor = get(collection, 'handlingEditor')
const parsedFragment = await fragmentHelper.getFragmentData({ const parsedFragment = await fragmentHelper.getFragmentData({
handlingEditor, handlingEditor,
......
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