Skip to content

Commit

Permalink
#161 Include testing of mails
Browse files Browse the repository at this point in the history
Include the possibility to test the sending or receiving of emails via
mailhog. Additionally, the test for a user import with the password
reset enabled has been extended with the mail feature. In addition, a
cleanup step for the mails was also added.
  • Loading branch information
lgorzitze committed Sep 11, 2024
1 parent 8675284 commit 6e8869b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 2 deletions.
3 changes: 3 additions & 0 deletions integrationTests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export default defineConfig({
"AdminGroup": "CesAdministrators",
"groups" : 0,
"users" : 0,
mailHogUrl: "https://192.168.56.2/mailhog/",
"mailHogUsername": "adminuser",
"mailHogPassword": "adminpw"
},
videoCompression: false,
experimentalRunAllSpecs: true,
Expand Down
18 changes: 17 additions & 1 deletion integrationTests/cypress/e2e/import_PWDReset_true.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Tests for uploading file with user that has password reset enabled

@clean_before
@clear_downloadDir
@clear_mails
Scenario: a user uploads a file
When the user opens the user import page
And the user uploads the file "tap_userimport_pwd_t.csv"
Expand All @@ -36,7 +37,22 @@ Feature: Tests for uploading file with user that has password reset enabled
And the user clicks on the edit-user button for the user "testUser"
Then the password reset flag is checked

@clean_user_import
Scenario: after uploading a file a user inspects the user import summaries page
When the user opens the user import summaries page
Then a table with the import information "New: 1, Updated: 0, Skipped: 0" regarding the file "tap_userimport_pwd_t.csv" is shown

@clean_user_import
Scenario: after the user import the newly created user receives an email
Then the user "testUser" receives an email with his user details

Scenario: a newly created user tries to log in for the first time
When the user logs out by visiting the cas logout page
And the user "testUser" tries to log in with his generated password
Then the newly created user is asked to change his password

Scenario: a newly created user logs in for the first time
When the user "testUser" tries to log in with his generated password
And the user sets the new password to "testuserpassword1234A$"
And the user "testUser" with password "testuserpassword1234A$" logs in
Then the account page for user "testUser" is shown
And users, groups, user import and import overview should not be visible in the navbar
2 changes: 1 addition & 1 deletion integrationTests/cypress/fixtures/tap_userimport_pwd_t.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
displayname,external,mail,pwdreset,surname,username,givenname
Test Muster,TRUE,[email protected],TRUE,Tester,testUser,Tester
Test Muster,TRUE,[email protected],TRUE,Tester,testUser,Tester
5 changes: 5 additions & 0 deletions integrationTests/cypress/support/step_definitions/before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ Before({tags: "@add_user"}, () => {
cy.usermgtCreateUser(userData.username, userData.givenname, userData.surname, userData.displayName, userData.mail, userData.password,false, [])
})
})

Before({tags: "@clear_mails"}, () => {
cy.log("delete previous mails in Mailhog");
cy.mhDeleteAll()
})
13 changes: 13 additions & 0 deletions integrationTests/cypress/support/step_definitions/then.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@bahmutov/cy-api'
import {Then} from "@badeball/cypress-cucumber-preprocessor";
import env from "@cloudogu/dogu-integration-test-library/lib/environment_variables";
import 'cypress-mailhog';

Then("the newly created user is asked to change his password", function () {
cy.get('div[data-testid="login-reset-pw-msg"]').should('be.visible')
Expand Down Expand Up @@ -437,3 +438,15 @@ Then("the user {string} has his mail updated to {string} and his display name to
cy.get('@row').find("td:nth-of-type(2)").contains(displayName)
cy.get('@row').find("td:nth-of-type(3)").contains(mail)
})

Then("the user {string} receives an email with his user details", function (username: string) {
cy.mhGetMailsBySender("[email protected]").should('exist')
cy.mhGetMailsBySender("[email protected]").mhFirst().mhGetBody().then((body) => {
expect(body).contains("Benutzername: " + username)
expect(body).contains("Passwort")
})
})

Then("the user is prompted to change the password", function () {
cy.log("Change password!")
})
26 changes: 26 additions & 0 deletions integrationTests/cypress/support/step_definitions/when.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,29 @@ When("deletes the entry for the user import", function () {
}
})
})

When("the user {string} tries to log in with his generated password", function (username: string) {
cy.mhGetMailsBySender("[email protected]").mhFirst().mhGetBody().then((body) => {
let strings: string[]
strings = body.split(" ")
let password = strings[8]

cy.clearCookies()

cy.visit("/" + env.GetDoguName(), {failOnStatusCode: false})
cy.clickWarpMenuCheckboxIfPossible()

cy.get('input[data-testid="login-username-input-field"]').type(username)
cy.get('input[data-testid="login-password-input-field"]').type(password)
})
})

When("the user sets the new password to {string}", function (password: string) {
cy.get('input[data-testid="password-input"]').type(password)
cy.get('input[data-testid="confirmedPassword-input"]').type(password)
cy.get('button').find('span').contains("Submit").click()
})

When("the user {string} with password {string} logs in", function (username: string, password: string) {
cy.login(username, password, env.GetMaxRetryCount())
})
3 changes: 3 additions & 0 deletions integrationTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
},
"scripts": {
"updateTests": "mkdir -p cypress/e2e/dogu_integration_test_lib && cp -r node_modules/@cloudogu/dogu-integration-test-library/lib/integration/* cypress/e2e/dogu_integration_test_lib"
},
"devDependencies": {
"cypress-mailhog": "^2.4.0"
}
}
10 changes: 10 additions & 0 deletions integrationTests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,16 @@ cypress-fs@^0.2.5:
cypress "^13.2.0"
typescript "^5.0.4"

cypress-mailhog@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/cypress-mailhog/-/cypress-mailhog-2.4.0.tgz#1f1732d4c4777ccbda828b8a85cd0fa1798d1060"
integrity sha512-CKCuaNBJOM3P0f68YzfBOY3seOX2dOK253xJ8Zw7axNWOvtmbrvV0MGax6iO94afHIynoowYlZ26cmPiawum1Q==

cypress-mailpit@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/cypress-mailpit/-/cypress-mailpit-1.2.1.tgz#7c0b507459db2623120caab17bc6d0b0bfdc6f22"
integrity sha512-9bwHh1+rKlS8tAHU0CwviwyhLCwMHFkFZPaD4/8Z2kKLcc8R806cGA1PnELCt3h0X561kfsHkGLolO9HBhnwbg==

cypress@^12.9.0:
version "12.9.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.9.0.tgz#e6ab43cf329fd7c821ef7645517649d72ccf0a12"
Expand Down

0 comments on commit 6e8869b

Please sign in to comment.