Skip to content

Commit

Permalink
#161 Test import with same mail address
Browse files Browse the repository at this point in the history
Test user import with users that have the same mail address. In this
process, previously added methods were updated to be applicable for a
wider range of cases.

# Conflicts:
#	integrationTests/cypress/support/step_definitions/then.ts
  • Loading branch information
lgorzitze committed Sep 13, 2024
1 parent d9aafef commit 39e2906
Show file tree
Hide file tree
Showing 11 changed files with 3,131 additions and 55 deletions.
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
61 changes: 61 additions & 0 deletions integrationTests/cypress/e2e/import_same_mailAddress.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Feature: Tests for uploading file with users with same mail address

Background:
Given the user "manager" exists
And the user "manager" is member of the group "cesManager"
And the user "manager" with password "newuserpassword1234A$" is logged in

Scenario: a user selects a file for upload
When the user opens the user import page
And the user selects the file "tap_userimport_mailpara.csv"
Then a table of the file content for the file "tap_userimport_mailpara.csv" is displayed

@clean_before
@clear_downloadDir
Scenario Outline: a user uploads a file
When the user opens the user import page
And the user uploads the file "tap_userimport_mailpara.csv"
Then the user import page shows an import with the message "<message>" and the details "<details>"

Examples:
| message | details |
| Import completed with errors! | Created accounts (4) |
| Import completed with errors! | Skipped data rows (1) |

Scenario Outline: after uploading a file a user inspects the user import details page about the created accounts
When the user opens the user import details page
And the user clicks on the details regarding the "created" user import
Then the table shows the information about the "created" user "<username>"

Examples:
| username |
| Testertest |
| Mustertest |
| Neutest |
| Haustest |

Scenario: after uploading a file a user inspects the user import details page about the skipped accounts
When the user opens the user import details page
And the user clicks on the details regarding the "skipped" user import
Then the table shows the error message "The following columns contained a value that is marked as unique and was already assigned: 'mail'."

Scenario: after uploading a file a user downloads the import overview
When the user opens the user import details page
And the user downloads the import overview
Then the import result is downloaded and contains information regarding "4" created, "0" updated and "1" skipped accounts in the file "tap_userimport_mailpara.csv"

Scenario Outline: after uploading a file a user inspects the users page
When the user opens the users page
Then the new user "<username>" was added

Examples:
| username |
| Testertest |
| Mustertest |
| Neutest |
| Haustest |

@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: 4, Updated: 0, Skipped: 1" regarding the file "tap_userimport_mailpara.csv" is shown
6 changes: 6 additions & 0 deletions integrationTests/cypress/fixtures/tap_userimport_mailpara.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
displayname,external,mail,pwdreset,surname,username,givenname
Test,TRUE,[email protected],TRUE,Tester,Testertest,Tester
Muster,TRUE,[email protected],TRUE,Muster,Mustertest,Muster
Neu,TRUE,[email protected],TRUE,Neu,Neutest,Neu
Alt,TRUE,[email protected],TRUE,Alt,Alt,Alt
Haus,TRUE,[email protected],TRUE,Haus,Haustest,Haus
2 changes: 1 addition & 1 deletion integrationTests/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const cleanupTestUsers = () => {
}).then((response) => {
expect(response.status).to.eq(200);
// @ts-ignore
return response.body.data.filter(el => el.displayName.startsWith("Tester") || el.username.startsWith("testUser")) || el.username.contains("new");
return response.body.data.filter(el => el.displayName.startsWith("Tester") || el.displayName.endsWith("Test") || el.username.startsWith("testUser") || el.username.endsWith("test")) || el.username.contains("new");
}).then(testUsers => {
cy.log("testUsers: ", testUsers);
testUsers.filter(testUser => {
Expand Down
73 changes: 19 additions & 54 deletions integrationTests/cypress/support/step_definitions/then.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,7 @@ Then("a table of the file content for the file {string} is displayed", function
cy.get('button[data-testid="reset-button"]').should('be.visible').and('not.be.disabled')
})

Then("the user import page shows a failed import", function () {
cy.get('h1').contains("Userimport")
cy.get('p[data-testid="import-status-message"]').contains("Import failed!")
cy.get('details[data-testid="failed-import-details"]').invoke('find', 'summary').invoke('attr', 'text').contains("Skipped data rows (1)")
cy.get('details[data-testid="failed-import-details"]').invoke('attr', 'open').should('not.exist')
cy.get('p[data-testid="import-download-link"]').invoke('find', 'a').contains("Download import overview")
})

Then("the import result is downloaded and contains error information regarding the file {string}", function (fileName: string) {
Then("the import result is downloaded and contains information regarding {string} created, {string} updated and {string} skipped accounts in the file {string}", function (created: string, updated: string, skipped: string, fileName: string) {
// To test the download, the generated import ID is extracted from the URL
cy.url()
.then(url => {
Expand All @@ -355,28 +347,22 @@ Then("the import result is downloaded and contains error information regarding t
expect(fileContent.importID).to.eq(fileId)
expect(fileContent.filename).to.eq(fileName)
expect(fileContent.timestamp).contains(/[0-9]+/)
expect(fileContent.created).is.empty
expect(fileContent.updated).is.empty
expect(fileContent.errors[0].errorCode).to.eq(202)
expect(fileContent.errors[0].lineNumber).to.eq(2)
expect(fileContent.errors[0].message).to.eq("entity is not valid")
expect(fileContent.errors[0].params.columns[0]).to.eq("username")
expect(fileContent.summary.importID).to.eq(fileId)
expect(fileContent.summary.filename).to.eq(fileName)
expect(fileContent.summary.timestamp).contains(/[0-9]+/)
expect(fileContent.summary.summary.created).to.eq(0)
expect(fileContent.summary.summary.updated).to.eq(0)
expect(fileContent.summary.summary.skipped).to.eq(1)
expect(fileContent.summary.summary.created).to.eq(parseInt(created))
expect(fileContent.summary.summary.updated).to.eq(parseInt(updated))
expect(fileContent.summary.summary.skipped).to.eq(parseInt(skipped))
})
})
})

Then("the table shows that the username was not in the correct format", function () {
cy.get('details[data-testid="failed-import-details"]').invoke('attr', 'open').should('exist')
cy.get('details[data-testid="failed-import-details"]').invoke('find', 'table').should('be.visible')
Then("the table shows the error message {string}", function (errorMessage: string) {
cy.get('details[data-testid="skipped-import-details"]').invoke('attr', 'open').should('exist')
cy.get('details[data-testid="skipped-import-details"]').invoke('find', 'table').should('be.visible')
cy.get('tr').as('row')
cy.get('@row').should('be.visible')
cy.get('@row').find("td:nth-of-type(2)").contains("The following columns do not match the default format: 'username'.")
cy.get('@row').find("td:nth-of-type(2)").contains(errorMessage)
})

Then("the new user {string} was not added", function (username: string) {
Expand All @@ -386,13 +372,13 @@ Then("the new user {string} was not added", function (username: string) {
cy.get('@row').invoke('text').should('not.equal', username)
})

Then("a table with the import information regarding the file {string} is shown", function (fileName: string) {
Then("a table with the import information {string} regarding the file {string} is shown", function (importInfo: string, fileName: string) {
cy.get('h1').contains("Import overviews")
cy.get('table').should('be.visible')
cy.get('tr').as('row')
cy.get('@row').should('be.visible')
cy.get('@row').find("td:nth-of-type(1)").contains(fileName)
//cy.get('@row').find("td:nth-of-type(3)").contains("New: 0, Updated: 0, Skipped: 1")
cy.get('@row').find("td:nth-of-type(3)").contains(importInfo)
})

Then("no content is displayed and upload is not possible", function () {
Expand All @@ -402,45 +388,24 @@ Then("no content is displayed and upload is not possible", function () {
cy.get('button[data-testid="reset-button"]').should('be.visible').and('be.disabled')
})

Then("the user import page shows a successful import", function () {
Then("the user import page shows an import with the message {string} and the details {string}", function (message: string, details: string) {
let messageDetails = details.split(" ")
let status = messageDetails[0].toLowerCase()
cy.get('h1').contains("Userimport")
cy.get('p[data-testid="import-status-message"]').contains("Import successfully completed!")
cy.get('details[data-testid="created-import-details"]').invoke('find', 'summary').invoke('attr', 'text').contains("Created accounts (1)")
cy.get('details[data-testid="created-import-details"]').invoke('attr', 'open').should('not.exist')
cy.get('p[data-testid="import-status-message"]').contains(message)
cy.get('details[data-testid="' + status + '-import-details"]').invoke('find', 'summary').invoke('attr', 'text').contains(details)
cy.get('details[data-testid="' + status + '-import-details"]').invoke('attr', 'open').should('not.exist')
cy.get('p[data-testid="import-download-link"]').invoke('find', 'a').contains("Download import overview")
})

Then("the table shows the information about the user {string}", function (username: string) {
cy.get('details[data-testid="created-import-details"]').invoke('attr', 'open').should('exist')
cy.get('details[data-testid="created-import-details"]').invoke('find', 'table').should('be.visible')
Then("the table shows the information about the {string} user {string}", function (importStatus: string, username: string) {
cy.get('details[data-testid="' + importStatus + '-import-details"]').invoke('attr', 'open').should('exist')
cy.get('details[data-testid="' + importStatus + '-import-details"]').invoke('find', 'table').should('be.visible')
cy.get('tr').as('row')
cy.get('@row').should('be.visible')
cy.get('@row').find("td:nth-of-type(1)").contains(username)
})

Then("the import result is downloaded and contains information regarding the file {string}", function (fileName: string) {
// To test the download, the generated import ID is extracted from the URL
cy.url()
.then(url => {
let urlSplit = url.split("/");
let fileId = urlSplit[6];
cy.readFile("cypress/downloads/" + fileId + ".json").then((fileContent) => {
expect(fileContent.importID).to.eq(fileId)
expect(fileContent.filename).to.eq(fileName)
expect(fileContent.timestamp).contains(/[0-9]+/)
expect(fileContent.created).is.not.empty
expect(fileContent.updated).is.empty
expect(fileContent.errors).is.empty
expect(fileContent.summary.importID).to.eq(fileId)
expect(fileContent.summary.filename).to.eq(fileName)
expect(fileContent.summary.timestamp).contains(/[0-9]+/)
expect(fileContent.summary.summary.created).to.eq(1)
expect(fileContent.summary.summary.updated).to.eq(0)
expect(fileContent.summary.summary.skipped).to.eq(0)
})
})
})

Then("the new user {string} was added", function (username: string) {
cy.get('table').should('be.visible')
cy.get('tr').as('row')
Expand Down
Loading

0 comments on commit 39e2906

Please sign in to comment.