Skip to content

Commit

Permalink
fix: update cypress tests (cognito and flakyness)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Oct 27, 2021
1 parent 83d6ff5 commit 32cee07
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
88 changes: 42 additions & 46 deletions cypress/integration/admin/security/user/userAccess.spec.js
@@ -1,63 +1,60 @@
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";
// Create a user with `full-access` group

// 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
Expand All @@ -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");
Expand All @@ -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);
});
Expand Down
4 changes: 3 additions & 1 deletion cypress/support/login/authenticateWithCognito.js
Expand Up @@ -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);
}
Expand Down

0 comments on commit 32cee07

Please sign in to comment.