Skip to content

Commit

Permalink
Merge pull request #625 from equinor/simplifyEvaluationSeed
Browse files Browse the repository at this point in the history
Replaced making first participant facilitator with throwing error if …
  • Loading branch information
petterwildhagen authored Sep 13, 2021
2 parents 72c7e8b + d344835 commit 5d9f1a7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.
8 changes: 5 additions & 3 deletions frontend/cypress/integration/bowtie_completion_date.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EvaluationSeed } from '../support/evaluation_seed'
import { Progression } from '../../src/api/models'
import { Progression, Role } from '../../src/api/models'
import FollowUpTabs from '../support/followup'
import { EvaluationPage } from '../support/evaluation'
import { getUsers } from '../support/mock/external/users'
Expand All @@ -13,10 +13,11 @@ describe('Workshop Summary', () => {
context('Bowtie model', () => {
it('User can not see complete date on an incomplete Evaluation', () => {
const progression = faker.random.arrayElement(Object.values(Progression).filter(p => p !== Progression.FollowUp))

const roles = [Role.Facilitator, Role.Participant]
seed = new EvaluationSeed({
progression,
users: getUsers(2),
roles,
})

seed.plant().then(() => {
Expand All @@ -32,10 +33,11 @@ describe('Workshop Summary', () => {

it('User can see complete date on a complete Evaluation', () => {
const today = new Date().toLocaleDateString()

const roles = [Role.Facilitator, Role.Participant]
seed = new EvaluationSeed({
progression: Progression.FollowUp,
users: getUsers(2),
roles,
})

seed.plant().then(() => {
Expand Down
11 changes: 6 additions & 5 deletions frontend/cypress/integration/create_evaluation_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ import ProjectPage from '../support/project'
import { users, User } from '../support/mock/external/users'
import * as faker from 'faker'

const createEvaluation = (creator: User, otherUser: User, prefix: string) => {
const createEvaluation = (creator: User, otherUser: User, roles: Role[], prefix: string) => {
let seed = new EvaluationSeed({
progression: faker.random.arrayElement(Object.values(Progression)),
users: [creator, otherUser],
roles,
namePrefix: prefix,
})
seed.participants[1].role = Role.Participant
return seed
}

describe('Creating a new Evaluation', () => {
const user = users[2]
const evalUserIsFacilitator = createEvaluation(user, users[0], 'user is Facilitator')
const evalUserIsParticipant = createEvaluation(users[0], user, 'user is Participant')
const evalUserIsNotInEvaluation = createEvaluation(users[0], users[1], 'user is not in evaluation')
const roles = [Role.Facilitator, Role.Participant]
const evalUserIsFacilitator = createEvaluation(user, users[0], roles, 'user is Facilitator')
const evalUserIsParticipant = createEvaluation(users[0], user, roles, 'user is Participant')
const evalUserIsNotInEvaluation = createEvaluation(users[0], users[1], roles, 'user is not in evaluation')
const previousEvaluations = [evalUserIsFacilitator, evalUserIsParticipant, evalUserIsNotInEvaluation]

before(() => {
Expand Down
8 changes: 3 additions & 5 deletions frontend/cypress/integration/nominations_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ describe('User management', () => {
})

function createSeed(progression: Progression = Progression.Nomination) {
let users = getUsers(5)
let users = getUsers(4)
const roles = [Role.Facilitator, Role.Participant, Role.OrganizationLead, Role.ReadOnly]
const seed = new EvaluationSeed({
progression: progression,
users,
roles,
})
seed.participants[1].role = Role.Facilitator
seed.participants[2].role = Role.Participant
seed.participants[3].role = Role.OrganizationLead
seed.participants[4].role = Role.ReadOnly
return seed
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/cypress/integration/sample_seed.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { EvaluationSeed } from '../support/evaluation_seed'
import { Organization, Priority, Progression, Severity } from '../../src/api/models'
import { Organization, Priority, Progression, Severity, Role } from '../../src/api/models'
import { Action, Answer, Note, Summary } from '../support/mocks'
import { getUsers } from '../support/mock/external/users'

const exampleSeed = () => {
let seed = new EvaluationSeed({
progression: Progression.Workshop,
users: getUsers(2),
roles: [Role.Facilitator, Role.Participant],
})

let facilitator = seed.participants[0]
Expand Down
25 changes: 11 additions & 14 deletions frontend/cypress/support/evaluation_seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export class EvaluationSeed {
} else {
users.forEach((u, index) => {
const r = roles[index]
cy.log('Creating participant ' + r)
participants.push(this.createParticipant({ user: u, role: r, progression: progression }))
})
}
Expand All @@ -102,10 +101,6 @@ export class EvaluationSeed {
}

addParticipant(participant: Participant) {
// The first participant is always a facilitator
if (this.participants.length == 0) {
participant.role = Role.Facilitator
}
this.participants.push(participant)
return this
}
Expand Down Expand Up @@ -183,16 +178,17 @@ export class EvaluationSeed {
* again.
*/
plant() {
return populateDB(this)
const facilitator = this.participants.find(e => e.role === Role.Facilitator)
if (facilitator === undefined) {
throw Error('Facilitator not found')
}
return populateDB(this, facilitator)
}
}

const populateDB = (seed: EvaluationSeed) => {
if (seed.participants === undefined || seed.participants.length < 1 || seed.participants[0].role !== Role.Facilitator) {
throw Error('First participant is not Facilitator')
}
const populateDB = (seed: EvaluationSeed, facilitator: Participant) => {
return cy
.login(seed.participants[0].user)
.login(facilitator.user)
.then(() => {
return cy.gql(GET_PROJECT, { variables: { fusionProjectId: seed.fusionProjectId } })
})
Expand All @@ -204,7 +200,8 @@ const populateDB = (seed: EvaluationSeed) => {
const evaluation = res.body.data.createEvaluation
seed.evaluationId = evaluation.id
seed.questions = evaluation.questions
seed.participants[0].id = evaluation.participants[0].id
seed.participants[seed.participants.indexOf(facilitator)].id =
evaluation.participants[seed.participants.indexOf(facilitator)].id
})
})
.then(e => {
Expand All @@ -217,7 +214,7 @@ const populateDB = (seed: EvaluationSeed) => {
})
})
.then(() => {
return seed.participants.slice(1)
return seed.participants.filter(x => x !== facilitator)
})
.each((participant: Participant) => {
cy.log(`EvaluationSeed: Adding Participants`)
Expand Down Expand Up @@ -327,6 +324,6 @@ const populateDB = (seed: EvaluationSeed) => {
}
})
.then(() => {
cy.login(seed.participants[0].user)
cy.login(facilitator.user)
})
}

0 comments on commit 5d9f1a7

Please sign in to comment.