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

Invite to pull request Alegria #14

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## File .env for process.env

BASEURL_API= ###
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
BASEURL_GUI= ###
2 changes: 2 additions & 0 deletions .gitignore
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ldasilvaNZ11, o .env.example deve sim ser versionado, visto que não contém dados sensíveis, é só um exemplo, como o nome indica, de qual estrutura deve ser usada no .env, esse sim não versionado.

Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@

# misc
.DS_Store
**.env
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved

20 changes: 20 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { defineConfig } = require("cypress");
require('dotenv').config()
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
require('@cypress/grep/src/plugin')(config);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ao fazer o que sugeri acima, tal lib nem mesmo seria necessária, tornando o projeto mais simples, que é o que procuramos quando se fala de um bom design: simplicidade.


//Config select environment
const environment = config.env.configEnv || 'ui'
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
if(environment === 'ui' || environment === 'UI'){
config.env.baseUrl = process.env.BASEURL_GUI
} else if (environment === 'api' || environment === 'API'){
config.env.baseUrl = process.env.BASEURL_API
}

guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
return config;
},
},
});
100 changes: 100 additions & 0 deletions cypress/e2e/apitest/customers_request.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/// <reference types="cypress" />

wlsf82 marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essa linha tbm pode ser removida pela mesma razão anterior.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visto que você não implementou a sugestão, essa conversa não deveria ter sido resolvida.


describe('All test intermediary API',() => {
context('Request all customers', () => {
beforeEach('Get request', () => {
cy.request(Cypress.env('baseUrl')).as('customers')
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseUrl não é uma env, portanto não é assim que acessa-se a mesma.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veja o comentário anterior.

})
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
it('Check status code return for all customers', () => {
cy.get('@customers').then((response) =>{
expect(response.status).to.eq(200)
})
})
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
it('Check length for return with all customers', () => {
cy.get('@customers').then((response) =>{
expect(response.body.customers).to.length(10)
})
})
})
context('Request all customers with pagination', () => {
const pagination = [1,2,3,4,5,6,7]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De onde saíram estes números?

E se só tiverem 20 clientes no banco de dados? A partir da página 3 já não viria nada.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faltou responder minha pergunta.

it.each(pagination)('Check pagination with all customers', (page) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pra que tal complexidade?

Veja abaixo uma solução simples e direta-ao-ponto.

it('paginates the customer list correctly', () => {
  cy.request('GET', `${CUSTOMERS_API_URL}?page=2`).as('getCustomersPageTwo')

  cy.get('@getCustomersPageTwo')
    .its('body.pageInfo.currentPage')
    .should('eq', 2) // Supposing there are at least 2 pages
})

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não gostou da minha sugestão?

cy.request(`${Cypress.env('baseUrl')}?page=${page}`).should((response) => {
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status).to.eq(200)
expect(response.body.pageInfo.currentPage).to.eq(page)
})
})
})
context('Request with get limit customer', () =>{
const limit = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
it.each(limit)('Filter to customers with inside limit', (limit) => {
cy.request(`${Cypress.env('baseUrl')}?page=1&limit=${limit}`).then((response) => {
expect(response.status).to.eq(200)
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.body.customers).to.length(limit)
})
})
})

context('Request with get industry customers', () => {
const industry = ['Logistics', 'Retail', 'HR', 'Logistics']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E a indústria Technology?

it.each(industry)('Filter to customers with industry', (industry) => {
cy.request(`${Cypress.env('baseUrl')}?page=1&industry=${industry}`).then((response) => {
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status).to.eq(200)
expect(response.body.customers[0].industry).to.eq(industry)
})
})
})
context('Request with get size customers', () => {
const sizes = ['Small','Medium','Enterprise','Large Enterprise','Very Large Enterprise']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const sizes = ['Small','Medium','Enterprise','Large Enterprise','Very Large Enterprise']
const sizes = ['Small', 'Medium', 'Enterprise', 'Large Enterprise', 'Very Large Enterprise']

Ao deixar um espaço em branco entre cada item do array, a legibilidade melhora.

it.each(sizes)('Filter to customer with size', (sizes) => {
cy.request(`${Cypress.env('baseUrl')}?page=1&size=${sizes}&industry=All`).then((response) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilize desestruturação de objetos.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O mesmo que demonstrei acima poderia ser aplicado aqui também.

expect(response.status).to.eq(200)
expect(response.body.customers[0].size).to.eq(sizes)
})
})
})

context('Bad Requests', () => {
it('Check message for invalid page', () => {
cy.request({url: `${Cypress.env('baseUrl')}?page=0`, failOnStatusCode: false}).then((response) => {
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status).to.eq(400)
expect(response.body.error).to.contain('Invalid page or limit. Both must be positive numbers.')
})
})
it('Check message for invalid limit', () => {
cy.request({url: `${Cypress.env('baseUrl')}?page=1&limit=0`, failOnStatusCode: false}).then((response) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilize desestruturação de objetos.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mesma coisa aqui.

expect(response.status).to.eq(400)
expect(response.body.error).to.contain('Invalid page or limit. Both must be positive numbers.')
})
})
it('Check message for invalid page with insert string', () => {
cy.request({url: `${Cypress.env('baseUrl')}?page=teste&limit=0`, failOnStatusCode: false}).then((response) => {
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status).to.eq(400)
expect(response.body.error).to.contain('Invalid page or limit. Both must be positive numbers.')
})
})
it('Check message for invalid limit with insert boolean', () => {
cy.request({url: `${Cypress.env('baseUrl')}?page=teste&limit=true`, failOnStatusCode: false}).then((response) => {
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status).to.eq(400)
expect(response.body.error).to.contain('Invalid page or limit. Both must be positive numbers.')
})
})
it('Check message for invalid size', () => {
const message = 'Unsupported size value. Supported values are All, Small, Medium, Enterprise, Large Enterprise, and Very Large Enterprise.'
cy.request({ url: `${Cypress.env('baseUrl')}?page=1&limit=10&size=0`, failOnStatusCode: false}).then((response) => {
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status).to.eq(400)
expect(response.body.error).to.contain(message)
})
})
it('Check message for invalid industry', () => {
const message = 'Unsupported industry value. Supported values are All, Logistics, Retail, Technology, HR, and Finance.'
cy.request({ url: `${Cypress.env('baseUrl')}?page=1&limit=10&size=All&industry=0`, failOnStatusCode: false}).then((response) => {
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
expect(response.status).to.eq(400)
expect(response.body.error).to.contain(message)
})
})
})

guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
})
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions cypress/e2e/uitest/table_customers.cy.js
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="cypress" />

describe('',() => {
context('', () => {
it('', () => {

})
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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"
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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) => { ... })
23 changes: 23 additions & 0 deletions cypress/support/e2e.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tem algum motivo pelo qual optaste por criar esse arquivo, ao invés de utilizar o cypress/support/commands.js?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este arquivo faz parte da estrutura padrão do Cypress @ldasilvaNZ11.

Ele é o arquivo principal dos comandos customizados, onde plugins externos são importados e também comandos customizados (cypress/support/commands.j).

Ou seja, tudo certo!

Eu só removeria esse monte de comentários, pra dar uma limpada no arquivo.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Algum motivo por não ter removido os comentários?

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ***********************************************************
// This example support/e2e.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'
import 'cypress-axe'
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
import 'cypress-each'

// Alternatively you can use CommonJS syntax:
// require('./commands')
require('@cypress/skip-test/support')
guilhermealegria marked this conversation as resolved.
Show resolved Hide resolved
Loading