Commit b2a8b32b authored by Yannis Barlas's avatar Yannis Barlas

test(submission form): initial submission e2e test

parent 80942423
......@@ -5,19 +5,40 @@ const isEqual = require('lodash/isEqual')
const difference = require('lodash/difference')
const xor = require('lodash/xor')
// const logger = require('@pubsweet/logger')
const isFromServer = operation =>
['create', 'read', 'update', 'delete'].includes(operation)
// Helper functions
const isTeamMember = async (user, roles, object, context) => {
const getUser = async (userId, operation, context) => {
const id = getId(userId)
const fromServer = isFromServer(operation)
let user
if (fromServer) {
user = await context.models.User.find(id, {
eager: 'teams.members.[user, alias]',
})
} else {
user = await context.models.User.find(id)
}
return user
}
const isTeamMember = async (user, roles, object, context, operation) => {
const teams = await Promise.all(
user.teams.map(teamId => context.models.Team.find(getId(teamId))),
)
const rolesArray = Array.isArray(roles) ? roles : [roles]
const objectId = isFromServer(operation) ? 'objectId' : 'object.objectId'
const team = teams.find(
aTeam =>
!aTeam.global &&
// object.id === aTeam.object.objectId &&
object.id === aTeam.objectId &&
object.id === get(aTeam, objectId) &&
rolesArray.includes(aTeam.role),
)
......@@ -25,7 +46,6 @@ const isTeamMember = async (user, roles, object, context) => {
}
const isGlobalTeamMember = async (user, roles, context) => {
// console.log(user)
const teams = await Promise.all(
user.teams.map(teamId => context.models.Team.find(getId(teamId))),
)
......@@ -48,14 +68,14 @@ const isScienceOfficer = (user, context) =>
const isGlobal = (user, context) =>
isGlobalTeamMember(user, ['editors', 'scienceOfficers'], context)
const isAuthor = async (user, object, context) =>
isTeamMember(user, 'author', object, context)
const isAuthor = async (user, object, context, operation) =>
isTeamMember(user, 'author', object, context, operation)
const isAcceptedReviewer = (user, object, context) =>
isTeamMember(user, 'reviewersAccepted', object, context)
const isAcceptedReviewer = (user, object, context, operation) =>
isTeamMember(user, 'reviewersAccepted', object, context, operation)
const isInvitedReviewer = (user, object, context) =>
isTeamMember(user, 'reviewersInvited', object, context)
const isInvitedReviewer = (user, object, context, operation) =>
isTeamMember(user, 'reviewersInvited', object, context, operation)
const updatedProperties = (current, update) => {
const diff = Object.keys(current).filter(k => {
......@@ -87,14 +107,12 @@ const permissions = {
before: async (userId, operation, object, context) => {
if (operation === 'isGlobalAndNotAuthor') return false
const user = await context.models.User.find(userId)
const user = await getUser(userId, operation, context)
if (user.admin) return true
},
create: (userId, operation, object, context) => true,
read: async (userId, operation, object, context) => {
const user = await context.models.User.find(userId, {
eager: 'teams.members.[user, alias]',
})
const user = await getUser(userId, operation, context)
// Everyone can list the manuscripts
if (object === 'Manuscript') {
......@@ -108,9 +126,14 @@ const permissions = {
!object.status.submission.full &&
!object.status.submission.initial
) {
return isTeamMember(user, 'author', object, context)
return isTeamMember(user, 'author', object, context, operation)
} else if (object.status.submission.initial) {
const isAuthorMember = await isAuthor(user, object, context)
const isAuthorMember = await isAuthor(
user,
object,
context,
operation,
)
const isGlobalMember = await isGlobal(user, context)
return isAuthorMember || isGlobalMember
}
......@@ -160,7 +183,7 @@ const permissions = {
return false
},
update: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
const user = await getUser(userId, operation, context)
if (!user) return false
// Everyone can update the manuscripts, in principle
......@@ -204,7 +227,7 @@ const permissions = {
}
}
if (isAuthor(user, object, context)) {
if (isAuthor(user, object, context, operation)) {
// WARNING: remove status
const authorWhitelist = [
'acknowledgements',
......@@ -228,7 +251,7 @@ const permissions = {
if (
arrayContains(authorWhitelist, updatedProperties(current, update))
) {
return isTeamMember(user, 'author', current, context)
return isTeamMember(user, 'author', current, context, operation)
}
}
}
......@@ -258,9 +281,10 @@ const permissions = {
if (!isEqual(affectedIds, [userId])) return false
const reviewerInvited = await isInvitedReviewer(
user,
// { id: current.object.objectId }, // pass article as object, not team
{ id: current.objectId }, // pass article as object, not team
{ id: current.object.objectId }, // pass article as object, not team
// { id: current.objectId }, // pass article as object, not team
context,
operation,
)
const reviewerAllow = ['reviewersAccepted', 'reviewersRejected']
if (reviewerAllow.includes(role)) return reviewerInvited
......@@ -293,35 +317,35 @@ const permissions = {
return false
},
isAcceptedReviewer: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
return isAcceptedReviewer(user, object, context)
const user = await getUser(userId, operation, context)
return isAcceptedReviewer(user, object, context, operation)
},
isAuthor: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
return isAuthor(user, object, context)
const user = await getUser(userId, operation, context)
return isAuthor(user, object, context, operation)
},
isEditor: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
const user = await getUser(userId, operation, context)
return isEditor(user, context)
},
isGlobal: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
const user = await getUser(userId, operation, context)
return isGlobal(user, context)
},
isGlobalAndNotAuthor: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
const user = await getUser(userId, operation, context)
const global = await isGlobal(user, context)
const author = await isAuthor(user, object, context)
const author = await isAuthor(user, object, context, operation)
return (user.admin || global) && !author
},
isGlobalOrAcceptedReviewer: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
const user = await getUser(userId, operation, context)
const global = await isGlobal(user, context)
const accepted = await isAcceptedReviewer(user, object, context)
const accepted = await isAcceptedReviewer(user, object, context, operation)
return global || accepted
},
isScienceOfficer: async (userId, operation, object, context) => {
const user = await context.models.User.find(getId(userId))
const user = await getUser(userId, operation, context)
return isScienceOfficer(user, context)
},
}
......
......@@ -7,6 +7,8 @@ const logger = new winston.Logger({
transports: [
new winston.transports.Console({
colorize: true,
humanReadableUnhandledException: true,
prettyPrint: true,
}),
new winston.transports.DailyRotateFile({
datePattern: 'DD-MM-YYYY',
......
......@@ -21,11 +21,8 @@ describe('Author creates new submission', () => {
})
it('should make initial submission', () => {
// cy.wait(3000)
cy.getById('new-submission-button').click()
// cy.wait(7000)
cy.get('[data-test-id="authorinput-author.name"] input')
.type('John Brown')
.get('[data-test-id="authorinput-author"] .react-select__control')
......@@ -102,12 +99,12 @@ describe('Author creates new submission', () => {
'Nunc aliquam mi massa, non egestas sem bibendum sit amet.',
)
cy.get('[data-test-id="disclaimer"] span').click()
cy.getById('acknowledgements').type('I acknowledge everything')
cy.get('[data-test-id="suggested-reviewer"] input').type('Jackie Brown')
cy.get('[data-test-id="disclaimer"] span').click()
cy.get('[data-test-id="comments"] .ProseMirror').type(
'Quisque bibendum, lectus et facilisis luctus.',
)
......@@ -120,5 +117,7 @@ describe('Author creates new submission', () => {
cy.contains('successful submission').should('exist')
cy.contains('button', 'OK').click()
cy.contains('Article Preview').should('exist')
})
})
......@@ -7,7 +7,8 @@ const resolver = async (_, vars, ctx) => {
// TO DO -- currently have the version that doesn't use objection.js
// Switch to Team.query().where(...) when you upgrade
try {
teams = await Team.findByField('object.objectId', id)
// teams = await Team.findByField('object.objectId', id)
teams = await Team.findByField('objectId', id)
} catch (e) {
teams = []
}
......
......@@ -4482,10 +4482,10 @@ cyclist@~0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-0.2.2.tgz#1b33792e11e914a2fd6d6ed6447464444e5fa640"
cypress@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-3.3.2.tgz#105d9283c747884d534b88a8e6c857d977887024"
integrity sha512-d2gFX0KBBdNfMMZ/ud9ouNqjDtMM3Tf5Z50hkl8Ldb8T+jKc7RLFo/4FjMu9i28T2x+50Sx8sN/kLzxr2oeWNg==
cypress@3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-3.4.0.tgz#8053ee107eb6309f26abd57e882d05578bdc3391"
integrity sha512-vUE+sK3l23fhs5qTN3dKpveyP0fGr37VmK3FSYaTEjbqC/qh4DbA1Ych/3bLStUpHP4rpE5KAx7i1s/tpdD9vQ==
dependencies:
"@cypress/listr-verbose-renderer" "0.4.1"
"@cypress/xvfb" "1.2.4"
......@@ -4513,7 +4513,7 @@ cypress@^3.3.2:
moment "2.24.0"
ramda "0.24.1"
request "2.88.0"
request-progress "0.4.0"
request-progress "3.0.0"
supports-color "5.5.0"
tmp "0.1.0"
url "0.11.0"
......@@ -9589,11 +9589,6 @@ nocache@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/nocache/-/nocache-2.0.0.tgz#202b48021a0c4cbde2df80de15a17443c8b43980"
node-eta@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/node-eta/-/node-eta-0.1.1.tgz#4066109b39371c761c72b7ebda9a9ea0a5de121f"
integrity sha1-QGYQmzk3HHYccrfr2pqeoKXeEh8=
node-fetch@1.6.3:
version "1.6.3"
resolved "http://registry.npmjs.org/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04"
......@@ -12208,13 +12203,12 @@ replace-ext@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"
request-progress@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/request-progress/-/request-progress-0.4.0.tgz#c1954e39086aa85269c5660bcee0142a6a70d7e7"
integrity sha1-wZVOOQhqqFJpxWYLzuAUKmpw1+c=
request-progress@3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/request-progress/-/request-progress-3.0.0.tgz#4ca754081c7fec63f505e4faa825aa06cd669dbe"
integrity sha1-TKdUCBx/7GP1BeT6qCWqBs1mnb4=
dependencies:
node-eta "^0.1.1"
throttleit "^0.0.2"
throttleit "^1.0.0"
request-promise-core@1.1.1:
version "1.1.1"
......@@ -13476,10 +13470,10 @@ throat@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a"
throttleit@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-0.0.2.tgz#cfedf88e60c00dd9697b61fdd2a8343a9b680eaf"
integrity sha1-z+34jmDADdlpe2H90qg0OptoDq8=
throttleit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-1.0.0.tgz#9e785836daf46743145a5984b6268d828528ac6c"
integrity sha1-nnhYNtr0Z0MUWlmEtiaNgoUorGw=
through2@^2.0.0, through2@^2.0.2:
version "2.0.3"
......
Markdown is supported
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