-
Notifications
You must be signed in to change notification settings - Fork 15
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
Primeiro PR Teste #6
base: main
Are you sure you want to change the base?
Changes from all commits
1fa3116
8912001
6bc8287
83b1f60
e5aaf23
ae9103b
d76f37f
de13a3c
68f98e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// cypress.config.js | ||
const { defineConfig } = require("cypress"); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
baseUrl: 'http://localhost:3000', | ||
supportFile: false, | ||
}, | ||
env: { | ||
API_URL: 'http://localhost:3001', | ||
}, | ||
fixturesFolder: false, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// cypress/e2e/api/customers.cy.js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todos os testes deste arquivo estão falhando, portanto, não irei revisá-lo. |
||
|
||
describe('Customers API', () => { | ||
const CUSTOMERS_API_URL = '/customers'; | ||
|
||
it('returns a list of customers with default pagination', () => { | ||
cy.request(CUSTOMERS_API_URL).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
expect(body).to.have.property('customers').that.is.an('array'); | ||
expect(body.customers).to.have.length(10); | ||
expect(body).to.have.property('pageInfo'); | ||
expect(body.pageInfo.currentPage).to.eq(1); | ||
fabianoseller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(body.pageInfo).to.have.property('totalPages'); | ||
expect(body.pageInfo).to.have.property('totalCustomers'); | ||
}); | ||
}); | ||
|
||
it('handles custom pagination', () => { | ||
cy.request(`${CUSTOMERS_API_URL}?page=2&limit=5`).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
expect(body.customers).to.have.length(5); | ||
expect(body.pageInfo.currentPage).to.eq(2); | ||
}); | ||
}); | ||
|
||
it('filters customers by size', () => { | ||
cy.request(`${CUSTOMERS_API_URL}?size=Small`).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
body.customers.forEach((customer) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
expect(customer.size).to.eq('Small'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('filters customers by industry', () => { | ||
cy.request(`${CUSTOMERS_API_URL}?industry=Technology`).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
body.customers.forEach((customer) => { | ||
expect(customer.industry).to.eq('Technology'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('returns an error for invalid industry', () => { | ||
cy.request({ | ||
url: `${CUSTOMERS_API_URL}?industry=InvalidIndustry`, | ||
failOnStatusCode: false | ||
}).then(({ status, body }) => { | ||
expect(status).to.eq(400); | ||
expect(body.error).to.eq('Unsupported industry value. Supported values are All, Logistics, Retail, Technology, HR, and Finance.'); | ||
}); | ||
}); | ||
|
||
it('returns the correct customer data structure', () => { | ||
cy.request(CUSTOMERS_API_URL).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
|
||
if (body.customers.length > 0) { | ||
const customer = body.customers[0]; | ||
expect(customer).to.have.all.keys('id', 'name', 'employees', 'industry', 'contactInfo', 'address', 'size'); | ||
|
||
if (customer.contactInfo) { | ||
expect(customer.contactInfo).to.have.all.keys('name', 'email'); | ||
} | ||
|
||
if (customer.address) { | ||
expect(customer.address).to.have.all.keys('street', 'city', 'state', 'zipCode', 'country'); | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// cypress/e2e/api/customers.cy.js | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este comentário é complemente desnecessário, visto que simplemente replica o caminho do arquivo na estrutura de pastas. Recomendo removê-lo por completo. |
||
|
||
describe('Customers API', () => { | ||
const API_URL = Cypress.env('API_URL'); | ||
const CUSTOMERS_API_URL = `${API_URL}/customers`; | ||
|
||
it('returns a list of customers with default pagination', () => { | ||
cy.request(CUSTOMERS_API_URL).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
expect(body).to.have.property('customers').that.is.an('array'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Que tal verificar também as sub-propriedades de |
||
expect(body.customers).to.have.length(10); | ||
expect(body).to.have.property('pageInfo'); | ||
expect(body.pageInfo.currentPage).to.eq(1); | ||
expect(body.pageInfo).to.have.property('totalPages'); | ||
expect(body.pageInfo).to.have.property('totalCustomers'); | ||
}); | ||
}); | ||
|
||
it('handles custom pagination', () => { | ||
cy.request(`${CUSTOMERS_API_URL}?page=2&limit=5`).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
expect(body.customers).to.have.length(5); | ||
expect(body.pageInfo.currentPage).to.eq(2); | ||
}); | ||
}); | ||
|
||
it('filters customers by size', () => { | ||
cy.request(`${CUSTOMERS_API_URL}?size=Small`).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
body.customers.forEach((customer) => { | ||
expect(customer.size).to.eq('Small'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('filters customers by industry', () => { | ||
cy.request(`${CUSTOMERS_API_URL}?industry=Technology`).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
body.customers.forEach((customer) => { | ||
expect(customer.industry).to.eq('Technology'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('returns an error for invalid industry', () => { | ||
cy.request({ | ||
url: `${CUSTOMERS_API_URL}?industry=InvalidIndustry`, | ||
failOnStatusCode: false | ||
}).then(({ status, body }) => { | ||
expect(status).to.eq(400); | ||
expect(body.error).to.eq('Unsupported industry value. Supported values are All, Logistics, Retail, Technology, HR, and Finance.'); | ||
}); | ||
}); | ||
|
||
it('returns the correct customer data structure', () => { | ||
cy.request(CUSTOMERS_API_URL).then(({ status, body }) => { | ||
expect(status).to.eq(200); | ||
const customer = body.customers[0]; | ||
expect(customer).to.have.all.keys('id', 'name', 'employees', 'industry', 'contactInfo', 'address', 'size'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Estas verificações poderiam estar no primeiro teste desta suíte, evitando um teste a mais. Quanto menos testes, mais rápido o feedback. |
||
|
||
if (customer.contactInfo) { | ||
expect(customer.contactInfo).to.have.all.keys('name', 'email'); | ||
} | ||
|
||
if (customer.address) { | ||
expect(customer.address).to.have.all.keys('street', 'city', 'state', 'zipCode', 'country'); | ||
} | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,20 @@ | ||||||||
// *********************************************************** | ||||||||
// 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' | ||||||||
|
||||||||
// Alternatively you can use CommonJS syntax: | ||||||||
// require('./commands') | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Recomenda-se deixar uma linha em branco ao final de cada arquivo. Dessa forma, ferramentas como o GitHub não exibem o ícone de Isso é uma boa prática e convenção a ser seguida. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
"react-scripts": "^5.0.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-proposal-private-property-in-object": "^7.21.11" | ||
"@babel/plugin-proposal-private-property-in-object": "^7.21.11", | ||
"cypress": "^13.15.0" | ||
fabianoseller marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Visto que você não está testando o frontend à nível de componentes, não há a necessidade de instalar o Cypress na pasta |
||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Você está definindo a URL do frontend mas deletou todos os testes para esta parte da aplicação.
Se o frontend não está mais sendo testado, esta configuração não se faz necessária.
A propósito, o que o levou a deletar os testes do frontend?