Skip to content

Commit f1fcffa

Browse files
Merge pull request #18 from CollabCodeTech/feature/save-jwt
feature/save-jwt
2 parents 7ba5bb0 + fc05daa commit f1fcffa

File tree

5 files changed

+93
-12
lines changed

5 files changed

+93
-12
lines changed

cypress/integration/pages/Signup/index.test.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import UserBuilder from "../../../libs/user.builder";
2+
13
describe("Page Signup", function() {
4+
before(function() {
5+
Cypress.Cookies.debug(true);
6+
});
7+
28
it("Open page on Desktop", function() {
39
cy.visit("/auth/signup");
410
});
@@ -26,7 +32,7 @@ describe("Page Signup", function() {
2632
cy.get("input[name=password]");
2733
});
2834

29-
it("Send form without filling in the inputs", function() {
35+
it("Send the form without filling in the inputs", function() {
3036
cy.visit("/auth/signup");
3137
cy.contains("Enviar").click();
3238

@@ -35,32 +41,61 @@ describe("Page Signup", function() {
3541
cy.contains("Senha é obrigatória");
3642
});
3743

38-
it("Send form with name invalid", function() {
44+
it("Send the form with name invalid that has only one char", function() {
45+
const { name } = UserBuilder.nameInvalid();
46+
3947
cy.visit("/auth/signup");
40-
cy.get("input[name=name]").type("a");
48+
cy.get("input[name=name]").type(name);
4149
cy.contains("Enviar").click();
4250
cy.contains("Nome tem que ter 2 ou mais caracteres");
4351
});
4452

45-
it("Send form with email invalid", function() {
53+
it("Send the form with email invalid", function() {
54+
const { email } = UserBuilder.emailInvalid();
55+
4656
cy.visit("/auth/signup");
47-
cy.get("input[name=email]").type("marco");
57+
cy.get("input[name=email]").type(email);
4858
cy.contains("Enviar").click();
4959
cy.contains("Preencha com email válido");
5060
});
5161

52-
it("Send form with password invalid", function() {
62+
it("Send the form with password invalid", function() {
63+
const { password } = UserBuilder.passwordInvalid();
64+
5365
cy.visit("/auth/signup");
54-
cy.get("input[name=password]").type("1234567");
66+
cy.get("input[name=password]").type(password);
5567
cy.contains("Enviar").click();
5668
cy.contains("Senha tem que ter 8 ou mais caracteres");
5769
});
5870

59-
it("Send form with all fields valid", function() {
71+
it("Send the form with the fields name, email and password valid", function() {
72+
const { name, email, password } = UserBuilder.randomUserInfo();
73+
74+
cy.visit("/auth/signup");
75+
cy.get("input[name=name]").type(name);
76+
cy.get("input[name=email]").type(email);
77+
cy.get("input[name=password]").type(password);
78+
cy.contains("Enviar").click();
79+
cy.location("pathname").should("include", "dashboard");
80+
});
81+
82+
it("Verify if the cookie jwt was create", function() {
83+
const { name, email, password } = UserBuilder.randomUserInfo();
84+
85+
cy.clearCookies();
6086
cy.visit("/auth/signup");
61-
cy.get("input[name=name]").type("Henri");
62-
cy.get("input[name=email]").type("marco.bruno.br@gmail.com");
63-
cy.get("input[name=password]").type("q1w2e3r4");
87+
cy.get("input[name=name]").type(name);
88+
cy.get("input[name=email]").type(email);
89+
cy.get("input[name=password]").type(password);
6490
cy.contains("Enviar").click();
91+
cy.location("pathname").should("include", "dashboard");
92+
cy.contains("Dashboard").then(function() {
93+
cy.getCookie("jwt")
94+
.should("have.property", "value")
95+
.and(
96+
"match",
97+
/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/
98+
);
99+
});
65100
});
66101
});

cypress/libs/user.builder.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import faker from "faker";
2+
3+
const generateName = () => {
4+
const firstName = faker.name.firstName();
5+
const lastName = faker.name.lastName();
6+
7+
return { name: `${firstName} ${lastName}` };
8+
};
9+
10+
const nameInvalid = () => ({ name: faker.internet.password(1) });
11+
const emailInvalid = () => ({ email: faker.lorem.word() });
12+
const passwordInvalid = () => ({ password: faker.internet.password(7) });
13+
const emailValid = () => ({ email: faker.internet.email() });
14+
const passwordValid = () => ({ password: faker.internet.password() });
15+
16+
const randomUserInfo = (options = {}) => {
17+
const blank = {};
18+
19+
return Object.assign(
20+
blank,
21+
{
22+
name: generateName().name,
23+
email: emailValid().email,
24+
password: passwordValid().password
25+
},
26+
{ ...options }
27+
);
28+
};
29+
30+
export default {
31+
generateName,
32+
randomUserInfo,
33+
nameInvalid,
34+
emailInvalid,
35+
passwordInvalid,
36+
emailValid,
37+
passwordValid
38+
};

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"eslint-plugin-jsx-a11y": "^6.2.3",
4545
"eslint-plugin-prettier": "^3.1.2",
4646
"eslint-plugin-react": "^7.18.3",
47-
"eslint-plugin-react-hooks": "^1.7.0"
47+
"eslint-plugin-react-hooks": "^1.7.0",
48+
"faker": "^4.1.0"
4849
}
4950
}

src/containers/FormSignup/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function FormLogin() {
2222

2323
function sendUser() {
2424
AuthService.signup(value)
25+
.withCredentials()
2526
.then(function() {
2627
history.replace("/dashboard");
2728
})

0 commit comments

Comments
 (0)