-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from CollabCodeTech/feature/save-jwt
feature/save-jwt
- Loading branch information
Showing
5 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
|
@@ -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("[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-_.+/=]*$/ | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters