Skip to content

Commit

Permalink
Merge pull request #18 from CollabCodeTech/feature/save-jwt
Browse files Browse the repository at this point in the history
feature/save-jwt
  • Loading branch information
marcobrunodev authored Mar 14, 2020
2 parents 7ba5bb0 + fc05daa commit f1fcffa
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 12 deletions.
57 changes: 46 additions & 11 deletions cypress/integration/pages/Signup/index.test.js
Original file line number Diff line number Diff line change
@@ -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");
});
Expand Down Expand Up @@ -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();

Expand All @@ -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("[email protected]");
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-_.+/=]*$/
);
});
});
});
38 changes: 38 additions & 0 deletions cypress/libs/user.builder.js
Original file line number Diff line number Diff line change
@@ -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
};
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
1 change: 1 addition & 0 deletions src/containers/FormSignup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function FormLogin() {

function sendUser() {
AuthService.signup(value)
.withCredentials()
.then(function() {
history.replace("/dashboard");
})
Expand Down

0 comments on commit f1fcffa

Please sign in to comment.