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

refactor(user.test.js): move the tests for isAdmin function from collection.test.js to user.test.js

parent d7f8a406
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!204Hin 1232 send correct email to new author
......@@ -5,7 +5,7 @@ const { cloneDeep } = require('lodash')
const fixturesService = require('pubsweet-component-fixture-service')
const { fixtures, Model } = fixturesService
const { Collection, Fragment, User } = require('../Helper')
const { Collection, Fragment } = require('../Helper')
describe('Collection helper', () => {
let testFixtures = {}
......@@ -231,26 +231,4 @@ describe('Collection helper', () => {
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)
})
})
})
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
process.env.SUPPRESS_NO_CONFIG_WARNING = true
const { cloneDeep } = require('lodash')
const fixturesService = require('pubsweet-component-fixture-service')
const { fixtures, Model } = fixturesService
const { User } = require('../Helper')
describe('User helper', () => {
let testFixtures = {}
let models
beforeEach(() => {
testFixtures = cloneDeep(fixtures)
models = Model.build(testFixtures)
})
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)
})
})
})
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