From 32cee07890163a331be8b26f219dd2c6d40aa439 Mon Sep 17 00:00:00 2001 From: Pavel Denisjuk Date: Wed, 27 Oct 2021 16:57:50 +0200 Subject: [PATCH] fix: update cypress tests (cognito and flakyness) --- .../admin/security/user/userAccess.spec.js | 88 +++++++++---------- .../support/login/authenticateWithCognito.js | 4 +- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/cypress/integration/admin/security/user/userAccess.spec.js b/cypress/integration/admin/security/user/userAccess.spec.js index e859ea6f483..1d1f48ee662 100644 --- a/cypress/integration/admin/security/user/userAccess.spec.js +++ b/cypress/integration/admin/security/user/userAccess.spec.js @@ -1,6 +1,6 @@ import uniqid from "uniqid"; -context("Security Users", async () => { +context("Security Users", () => { it('should verify user access for a "full-access" user', async () => { let fullAccessGroupUser; let password = "12345678"; @@ -8,56 +8,53 @@ context("Security Users", async () => { // eslint-disable-next-line jest/valid-expect-in-promise cy.securityReadGroup({ slug: "full-access" }).then(group => { - return cy - .securityCreateUser({ - data: { - email: uniqid("", "@gmail.com"), - firstName: uniqid("first name-"), - lastName: uniqid("last name-"), - password, - group: group.id - } - }) - .then(user => { - fullAccessGroupUser = user; - // Login with new user - cy.login({ username: fullAccessGroupUser.email, password }); - cy.visit("/"); - // Verify the access - cy.findByText(`Hi ${user.firstName} ${user.lastName}!`).should("be.visible"); - cy.findByText(/To get started - pick one of the actions below:/i).should( - "be.visible" - ); - - // Should have Page Builder card - cy.findByTestId("admin-welcome-screen-widget-page-builder").within(() => { - cy.findByText("Page Builder").should("be.visible"); - cy.findByText(/Build a new Page/i).should("be.visible"); - }); + cy.securityCreateUser({ + data: { + email: uniqid("", "@gmail.com"), + firstName: uniqid("first name-"), + lastName: uniqid("last name-"), + password, + group: group.id + } + }).then(user => { + fullAccessGroupUser = user; + // Login with new user + cy.login({ username: fullAccessGroupUser.email, password }); + cy.visit("/"); + // Verify the access + cy.findByText(`Hi ${user.firstName} ${user.lastName}!`).should("be.visible"); + cy.findByText(/To get started - pick one of the actions below:/i).should( + "be.visible" + ); - // Should have Form Builder card - cy.findByTestId("admin-welcome-screen-widget-form-builder").within(() => { - cy.findByText("Form Builder").should("be.visible"); - cy.findByText(/Create a new Form/i).should("be.visible"); - }); + // Should have Page Builder card + cy.findByTestId("admin-welcome-screen-widget-page-builder").within(() => { + cy.findByText("Page Builder").should("be.visible"); + cy.findByText(/Build a new Page/i).should("be.visible"); + }); - // Should have Headless CMS card - cy.findByTestId("admin-welcome-screen-widget-headless-cms").within(() => { - cy.findByText("Headless CMS").should("be.visible"); - cy.findByText(/New content model/i).should("be.visible"); - }); + // Should have Form Builder card + cy.findByTestId("admin-welcome-screen-widget-form-builder").within(() => { + cy.findByText("Form Builder").should("be.visible"); + cy.findByText(/Create a new Form/i).should("be.visible"); + }); - // Delete user - // eslint-disable-next-line jest/valid-expect-in-promise - cy.securityDeleteUser({ - id: fullAccessGroupUser.id - }).then(data => assert.isTrue(data)); + // Should have Headless CMS card + cy.findByTestId("admin-welcome-screen-widget-headless-cms").within(() => { + cy.findByText("Headless CMS").should("be.visible"); + cy.findByText(/New content model/i).should("be.visible"); }); + + // Delete user + // eslint-disable-next-line jest/valid-expect-in-promise + cy.securityDeleteUser({ + id: fullAccessGroupUser.id + }).then(data => assert.isTrue(data)); + }); }); }); it('should verify user access for a "anonymous" user', () => { - let fullAccessGroupUser; let password = "12345678"; // Create a user with `full-access` group // eslint-disable-next-line jest/valid-expect-in-promise @@ -73,9 +70,8 @@ context("Security Users", async () => { } }) .then(user => { - fullAccessGroupUser = user; // Login with new user - cy.login({ username: fullAccessGroupUser.email, password }); + cy.login({ username: user.email, password }); cy.visit("/"); // Verify the access cy.findByText(`Hi ${user.firstName} ${user.lastName}!`).should("be.visible"); @@ -95,7 +91,7 @@ context("Security Users", async () => { // Delete user // eslint-disable-next-line jest/valid-expect-in-promise cy.securityDeleteUser({ - id: fullAccessGroupUser.id + id: user.id }).then(data => { assert.isTrue(data); }); diff --git a/cypress/support/login/authenticateWithCognito.js b/cypress/support/login/authenticateWithCognito.js index 0f15f198eaf..4a90a419838 100644 --- a/cypress/support/login/authenticateWithCognito.js +++ b/cypress/support/login/authenticateWithCognito.js @@ -37,13 +37,15 @@ export default ({ username, password }) => { delete userAttributes.email_verified; // it's returned but not valid to submit const newPassword = "12345678"; + userAttributes.email = username; cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, { onSuccess: resolve, onFailure: function (err) { console.log( `An error occurred while executing login command ("cognitoUser.completeNewPasswordChallenge")`, - err + err, + userAttributes ); reject(err); }