diff --git a/cypress/integration/pages/Signup/index.test.js b/cypress/integration/pages/Signup/index.test.js index 7524a96..4219082 100644 --- a/cypress/integration/pages/Signup/index.test.js +++ b/cypress/integration/pages/Signup/index.test.js @@ -1,4 +1,10 @@ +import UserBuilder from "../../../libs/user.builder"; + describe("Page Signup", function() { + before(function() { + Cypress.Cookies.debug(true); + }); + it("Open page on Desktop", function() { cy.visit("/auth/signup"); }); @@ -26,7 +32,7 @@ describe("Page Signup", function() { cy.get("input[name=password]"); }); - it("Send form without filling in the inputs", function() { + it("Send the form without filling in the inputs", function() { cy.visit("/auth/signup"); cy.contains("Enviar").click(); @@ -35,32 +41,61 @@ describe("Page Signup", function() { cy.contains("Senha é obrigatória"); }); - it("Send form with name invalid", function() { + it("Send the form with name invalid that has only one char", function() { + const { name } = UserBuilder.nameInvalid(); + cy.visit("/auth/signup"); - cy.get("input[name=name]").type("a"); + cy.get("input[name=name]").type(name); cy.contains("Enviar").click(); cy.contains("Nome tem que ter 2 ou mais caracteres"); }); - it("Send form with email invalid", function() { + it("Send the form with email invalid", function() { + const { email } = UserBuilder.emailInvalid(); + cy.visit("/auth/signup"); - cy.get("input[name=email]").type("marco"); + cy.get("input[name=email]").type(email); cy.contains("Enviar").click(); cy.contains("Preencha com email válido"); }); - it("Send form with password invalid", function() { + it("Send the form with password invalid", function() { + const { password } = UserBuilder.passwordInvalid(); + cy.visit("/auth/signup"); - cy.get("input[name=password]").type("1234567"); + cy.get("input[name=password]").type(password); cy.contains("Enviar").click(); cy.contains("Senha tem que ter 8 ou mais caracteres"); }); - it("Send form with all fields valid", function() { + it("Send the form with the fields name, email and password valid", function() { + const { name, email, password } = UserBuilder.randomUserInfo(); + + cy.visit("/auth/signup"); + cy.get("input[name=name]").type(name); + cy.get("input[name=email]").type(email); + cy.get("input[name=password]").type(password); + cy.contains("Enviar").click(); + cy.location("pathname").should("include", "dashboard"); + }); + + it("Verify if the cookie jwt was create", function() { + const { name, email, password } = UserBuilder.randomUserInfo(); + + cy.clearCookies(); cy.visit("/auth/signup"); - cy.get("input[name=name]").type("Henri"); - cy.get("input[name=email]").type("marco.bruno.br@gmail.com"); - cy.get("input[name=password]").type("q1w2e3r4"); + cy.get("input[name=name]").type(name); + cy.get("input[name=email]").type(email); + cy.get("input[name=password]").type(password); cy.contains("Enviar").click(); + cy.location("pathname").should("include", "dashboard"); + cy.contains("Dashboard").then(function() { + cy.getCookie("jwt") + .should("have.property", "value") + .and( + "match", + /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/ + ); + }); }); }); diff --git a/cypress/libs/user.builder.js b/cypress/libs/user.builder.js new file mode 100644 index 0000000..2bd17e3 --- /dev/null +++ b/cypress/libs/user.builder.js @@ -0,0 +1,38 @@ +import faker from "faker"; + +const generateName = () => { + const firstName = faker.name.firstName(); + const lastName = faker.name.lastName(); + + return { name: `${firstName} ${lastName}` }; +}; + +const nameInvalid = () => ({ name: faker.internet.password(1) }); +const emailInvalid = () => ({ email: faker.lorem.word() }); +const passwordInvalid = () => ({ password: faker.internet.password(7) }); +const emailValid = () => ({ email: faker.internet.email() }); +const passwordValid = () => ({ password: faker.internet.password() }); + +const randomUserInfo = (options = {}) => { + const blank = {}; + + return Object.assign( + blank, + { + name: generateName().name, + email: emailValid().email, + password: passwordValid().password + }, + { ...options } + ); +}; + +export default { + generateName, + randomUserInfo, + nameInvalid, + emailInvalid, + passwordInvalid, + emailValid, + passwordValid +}; diff --git a/package-lock.json b/package-lock.json index 319caba..38c15cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5646,6 +5646,12 @@ "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" }, + "faker": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/faker/-/faker-4.1.0.tgz", + "integrity": "sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8=", + "dev": true + }, "fast-deep-equal": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", diff --git a/package.json b/package.json index 368c9d6..5766d81 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-prettier": "^3.1.2", "eslint-plugin-react": "^7.18.3", - "eslint-plugin-react-hooks": "^1.7.0" + "eslint-plugin-react-hooks": "^1.7.0", + "faker": "^4.1.0" } } diff --git a/src/containers/FormSignup/index.js b/src/containers/FormSignup/index.js index 24aca1b..f6fe50c 100644 --- a/src/containers/FormSignup/index.js +++ b/src/containers/FormSignup/index.js @@ -22,6 +22,7 @@ function FormLogin() { function sendUser() { AuthService.signup(value) + .withCredentials() .then(function() { history.replace("/dashboard"); })