Skip to content

Commit

Permalink
Fix creation of user in cypress tests
Browse files Browse the repository at this point in the history
This failed due to random hash added to the mail address
in the last commit.
  • Loading branch information
Splines committed Sep 25, 2024
1 parent 939bb92 commit 6ed2190
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/controllers/cypress/user_creator_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Cypress
# Creates a user for use in Cypress tests.
class UserCreatorController < CypressController
CYPRESS_PASSWORD = "cypress123".freeze

def create
unless params[:role].is_a?(String)
msg = "First argument must be a string indicating the user role."
Expand All @@ -14,11 +16,11 @@ def create

user = User.create(name: "#{role} Cypress #{random_hash}",
email: "#{role}-#{random_hash}@mampf.cypress",
password: "cypress123", consents: true, admin: is_admin,
password: CYPRESS_PASSWORD, consents: true, admin: is_admin,
locale: I18n.default_locale)
user.confirm

render json: user.to_json, status: :created
render json: user.as_json.merge({ password: CYPRESS_PASSWORD }), status: :created
end
end
end
4 changes: 2 additions & 2 deletions spec/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Cypress.Commands.add("login", (user) => {
});

Cypress.Commands.add("createUserAndLogin", (role) => {
cy.createUser(role).then((user) => {
cy.login({ email: `${role}@mampf.cypress`, password: "cypress123" }).then((_) => {
return cy.createUser(role).then((user) => {
cy.login({ email: user.email, password: user.password }).then((_) => {
cy.wrap(user);
});
});
Expand Down

0 comments on commit 6ed2190

Please sign in to comment.