Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] chore: update tests #26

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Expand Up @@ -103,6 +103,8 @@ dist
# TernJS port file
.tern-port

# CUSTOM
.vscode/

# IDE
.vscode/
cypress/videos
cypress/screenshots
1 change: 1 addition & 0 deletions cypress.json
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
77 changes: 77 additions & 0 deletions cypress/integration/cep/cep.spec.js
@@ -0,0 +1,77 @@
/// <reference types="cypress" />

function makeInvalidRequest(cep, validationError) {
cy.request({
method: "get",
url: `http://localhost:3000/api/cep/v1/${cep}`,
failOnStatusCode: false
}).should(response => {
expect(response.status).to.eq(404);
expect(response.body).to.deep.equal(validationError);
});
}

context("Cep HTTP Cases", () => {
it("Open HomePage with Success", () => {
cy.visit("http://localhost:3000");
cy.get("main").within(() => {
cy.get("a").contains("Brasil API");
cy.get("p").contains("Vamos transformar o Brasil em uma API?");
});
});

it("Get CEP with success", () => {
const myAdress = {
cep: "55540000",
state: "PE",
city: "Palmares",
neighborhood: "",
street: ""
};
cy.request(`http://localhost:3000/api/cep/v1/${myAdress.cep}`).should(
response => {
expect(response.status).to.eq(200);
expect(response.body).to.deep.equal(myAdress);
}
);
});

it("Use CEP with invalid pattern and get validation error", () => {
const validationError = {
name: "CepPromiseError",
message: "Todos os serviços de CEP retornaram erro.",
type: "service_error",
errors: [
{
name: "ServiceError",
message: "CEP INVÁLIDO",
service: "correios"
},
{
name: "ServiceError",
message: "CEP não encontrado na base do ViaCEP.",
service: "viacep"
}
]
};
const cep = 123;
makeInvalidRequest(cep, validationError);

});

it("Use CEP with more than 8 characteres and get validation error", () => {
const validationError = {
name: "CepPromiseError",
message: "CEP deve conter exatamente 8 caracteres.",
type: "validation_error",
errors: [
{
message: "CEP informado possui mais do que 8 caracteres.",
service: "cep_validation"
}
]
};
const cep = 11122233344;
makeInvalidRequest(cep, validationError);
});
});
21 changes: 21 additions & 0 deletions cypress/plugins/index.js
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
10 changes: 7 additions & 3 deletions package.json
Expand Up @@ -8,11 +8,15 @@
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"devDependencies": {},
"devDependencies": {
"cypress": "^4.0.1"
},
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
"start": "next start",
"cypress:run": "cypress run",
"cypress:open": "cypress open"
},
"repository": {
"type": "git",
Expand All @@ -24,4 +28,4 @@
"url": "https://github.com/filipedeschamps/BrasilAPI/issues"
},
"homepage": "https://github.com/filipedeschamps/BrasilAPI#readme"
}
}