Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic committed Sep 5, 2024
1 parent e1394c9 commit 67f8f74
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 337 deletions.
256 changes: 129 additions & 127 deletions test/browser/AnswerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,143 +111,145 @@ class AnswerSpec extends Specification with Tables with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
"userCodeName" |
"instructor-test" |
"invited-expert-test" |
"invited-user-test" |
"helper-test" |> { (userSeed: String) =>
val tokenService = app.injector.instanceOf[TokenService]
val userService = app.injector.instanceOf[UserService]
val groupService = app.injector.instanceOf[UserGroupService]
val applicationService = app.injector.instanceOf[ApplicationService]

// Generate data and save in DB
val testSeed = scala.util.Random.nextInt()
val helperGroup = generateGroup(testSeed, "helper", groupService)
val answerGroup = generateGroup(testSeed, "answer", groupService)
val expertGroup = generateGroup(testSeed, "expert", groupService)
val instructorUser = generateUser(
testSeed,
userSeed = "instructor-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"J'instruit $testSeed",
userQualite = s"Instructeur Testeur $testSeed",
isHelper = true,
isInstructor = true,
isExpert = false,
groups = List(answerGroup),
userService = userService
)
val invitedExpertUser = generateUser(
testSeed,
userSeed = "invited-expert-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"Je suis un expert TEST $testSeed",
userQualite = s"Expert $testSeed",
isHelper = true,
isInstructor = false,
isExpert = true,
groups = List(expertGroup),
userService = userService
)
val invitedUser = generateUser(
testSeed,
userSeed = "invited-user-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"Je suis un agent TEST $testSeed",
userQualite = s"Agent $testSeed",
isHelper = true,
isInstructor = false,
isExpert = false,
groups = List(answerGroup),
userService = userService
)
val helperUser = generateUser(
testSeed,
userSeed = "helper-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"J'aide TEST $testSeed",
userQualite = s"Aidant Testeur $testSeed",
isHelper = true,
isInstructor = false,
isExpert = false,
groups = List(helperGroup),
userService = userService
)
val users = List(
instructorUser,
invitedExpertUser,
invitedUser,
helperUser
)
users.map(user => userService.validateCGU(user.id))
val expertInvited = userSeed === "invited-expert-test"
val userInvited = userSeed === "invited-user-test"
val invitedUsers =
List(
instructorUser.some,
invitedExpertUser.some.filter(_ => expertInvited),
invitedUser.some.filter(_ => userInvited)
).flatten
val application =
generateApplication(
helperUser,
helperGroup,
invitedUsers,
applicationService
override def running() = {
"userCodeName" |
"instructor-test" |
"invited-expert-test" |
"invited-user-test" |
"helper-test" |> { (userSeed: String) =>
val tokenService = app.injector.instanceOf[TokenService]
val userService = app.injector.instanceOf[UserService]
val groupService = app.injector.instanceOf[UserGroupService]
val applicationService = app.injector.instanceOf[ApplicationService]

// Generate data and save in DB
val testSeed = scala.util.Random.nextInt()
val helperGroup = generateGroup(testSeed, "helper", groupService)
val answerGroup = generateGroup(testSeed, "answer", groupService)
val expertGroup = generateGroup(testSeed, "expert", groupService)
val instructorUser = generateUser(
testSeed,
userSeed = "instructor-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"J'instruit $testSeed",
userQualite = s"Instructeur Testeur $testSeed",
isHelper = true,
isInstructor = true,
isExpert = false,
groups = List(answerGroup),
userService = userService
)
val invitedExpertUser = generateUser(
testSeed,
userSeed = "invited-expert-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"Je suis un expert TEST $testSeed",
userQualite = s"Expert $testSeed",
isHelper = true,
isInstructor = false,
isExpert = true,
groups = List(expertGroup),
userService = userService
)
val invitedUser = generateUser(
testSeed,
userSeed = "invited-user-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"Je suis un agent TEST $testSeed",
userQualite = s"Agent $testSeed",
isHelper = true,
isInstructor = false,
isExpert = false,
groups = List(answerGroup),
userService = userService
)
val helperUser = generateUser(
testSeed,
userSeed = "helper-test",
firstName = "FirstName",
lastName = "LastName",
userName = s"J'aide TEST $testSeed",
userQualite = s"Aidant Testeur $testSeed",
isHelper = true,
isInstructor = false,
isExpert = false,
groups = List(helperGroup),
userService = userService
)
val users = List(
instructorUser,
invitedExpertUser,
invitedUser,
helperUser
)
users.map(user => userService.validateCGU(user.id))
val expertInvited = userSeed === "invited-expert-test"
val userInvited = userSeed === "invited-user-test"
val invitedUsers =
List(
instructorUser.some,
invitedExpertUser.some.filter(_ => expertInvited),
invitedUser.some.filter(_ => userInvited)
).flatten
val application =
generateApplication(
helperUser,
helperGroup,
invitedUsers,
applicationService
)

// Helper login
val answerUserId = userId(testSeed, userSeed)
val loginToken =
LoginToken.forUserId(answerUserId, 5, "127.0.0.1")
tokenService.create(loginToken)

val loginURL = controllers.routes.LoginController.magicLinkAntiConsumptionPage
.absoluteURL(false, s"localhost:$port")

// Helper login
val answerUserId = userId(testSeed, userSeed)
val loginToken =
LoginToken.forUserId(answerUserId, 5, "127.0.0.1")
tokenService.create(loginToken)

val loginURL = controllers.routes.LoginController.magicLinkAntiConsumptionPage
.absoluteURL(false, s"localhost:$port")

browser.goTo(s"$loginURL?token=${loginToken.token}&path=/")
browser.goTo(s"$loginURL?token=${loginToken.token}&path=/")

// Wait for login
eventually {
browser.url must endWith(
controllers.routes.ApplicationController.myApplications.url.substring(1)
)
}
// Wait for login
eventually {
browser.url must endWith(
controllers.routes.ApplicationController.myApplications.url.substring(1)
)
}

// Submit answer
val applicationURL =
controllers.routes.ApplicationController
.show(application.id)
.absoluteURL(false, s"localhost:$port")
browser.goTo(applicationURL)
// Submit answer
val applicationURL =
controllers.routes.ApplicationController
.show(application.id)
.absoluteURL(false, s"localhost:$port")
browser.goTo(applicationURL)

val answerMessage = "Il y a juste à faire ça!"
val answerMessage = "Il y a juste à faire ça!"

browser.waitUntil(browser.el(s"textarea[name='message']").clickable())
browser.el("textarea[name='message']").fill().withText(answerMessage)
browser.el("button[id='review-validation']").click()
browser.waitUntil(browser.el(s"textarea[name='message']").clickable())
browser.el("textarea[name='message']").fill().withText(answerMessage)
browser.el("button[id='review-validation']").click()

// Wait for form submit
eventually {
browser.pageSource must contain(helperUser.name)
}
// Wait for form submit
eventually {
browser.pageSource must contain(helperUser.name)
}

val changedApplicationOption = applicationService
.allByArea(helperGroup.areaIds.head, anonymous = false)
.find(app => app.id === application.id)
val changedApplicationOption = applicationService
.allByArea(helperGroup.areaIds.head, anonymous = false)
.find(app => app.id === application.id)

changedApplicationOption mustNotEqual None
val changedApplication = changedApplicationOption.get
changedApplicationOption mustNotEqual None
val changedApplication = changedApplicationOption.get

val answer = changedApplication.answers.head
answer.message mustEqual answerMessage
answer.creatorUserID mustEqual answerUserId
}
val answer = changedApplication.answers.head
answer.message mustEqual answerMessage
answer.creatorUserID mustEqual answerUserId
}
}
}
}
}
45 changes: 32 additions & 13 deletions test/browser/ApplicationAccessSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ApplicationAccessSpec extends Specification with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
applicationAccessTest(app, browser, port, "instructor-test", shouldExpectAnError = false)
override def running() =
applicationAccessTest(app, browser, port, "instructor-test", shouldExpectAnError = false)
}
}

Expand All @@ -30,13 +31,14 @@ class ApplicationAccessSpec extends Specification with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
applicationAccessTest(
app,
browser,
port,
"instructor-test-unrelated",
shouldExpectAnError = true
)
override def running() =
applicationAccessTest(
app,
browser,
port,
"instructor-test-unrelated",
shouldExpectAnError = true
)
}
}

Expand All @@ -45,7 +47,8 @@ class ApplicationAccessSpec extends Specification with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
applicationAccessTest(app, browser, port, "helper-test", shouldExpectAnError = false)
override def running() =
applicationAccessTest(app, browser, port, "helper-test", shouldExpectAnError = false)
}
}

Expand All @@ -54,7 +57,8 @@ class ApplicationAccessSpec extends Specification with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
applicationAccessTest(app, browser, port, "helper-test-friend", shouldExpectAnError = false)
override def running() =
applicationAccessTest(app, browser, port, "helper-test-friend", shouldExpectAnError = false)
}
}

Expand All @@ -63,7 +67,14 @@ class ApplicationAccessSpec extends Specification with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
applicationAccessTest(app, browser, port, "helper-test-unrelated", shouldExpectAnError = true)
override def running() =
applicationAccessTest(
app,
browser,
port,
"helper-test-unrelated",
shouldExpectAnError = true
)
}
}

Expand All @@ -72,7 +83,14 @@ class ApplicationAccessSpec extends Specification with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
applicationAccessTest(app, browser, port, "expert-test-unrelated", shouldExpectAnError = true)
override def running() =
applicationAccessTest(
app,
browser,
port,
"expert-test-unrelated",
shouldExpectAnError = true
)
}
}

Expand All @@ -81,7 +99,8 @@ class ApplicationAccessSpec extends Specification with BaseSpec {
webDriver = webDriver,
app = applicationWithBrowser
) {
applicationAccessTest(app, browser, port, "helper-test-manager", shouldExpectAnError = true)
override def running() =
applicationAccessTest(app, browser, port, "helper-test-manager", shouldExpectAnError = true)
}
}

Expand Down
Loading

0 comments on commit 67f8f74

Please sign in to comment.