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

Primeiro PR Teste #6

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions cypress.config.js
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',
Copy link
Owner

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?

supportFile: false,
},
env: {
API_URL: 'http://localhost:3001',
},
fixturesFolder: false,
});
72 changes: 72 additions & 0 deletions cypress/e2e/EngageSphere.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// cypress/e2e/api/customers.cy.js
Copy link
Owner

Choose a reason for hiding this comment

The 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);
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) => {
Copy link
Owner

Choose a reason for hiding this comment

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

👍🏻

Copy link
Author

Choose a reason for hiding this comment

The 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');
}
}
});
});
});
70 changes: 70 additions & 0 deletions cypress/e2e/api/customers.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// cypress/e2e/api/customers.cy.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 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');
Copy link
Owner

Choose a reason for hiding this comment

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

Que tal verificar também as sub-propriedades de customers, assim como fez com as sub-propriedades de pageInfo?

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');
Copy link
Owner

Choose a reason for hiding this comment

The 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');
}
});
});
});
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
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')
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
// require('./commands')
// require('./commands')

Recomenda-se deixar uma linha em branco ao final de cada arquivo.

Dessa forma, ferramentas como o GitHub não exibem o ícone de No newline at end of file.

Isso é uma boa prática e convenção a ser seguida.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 está testando o frontend à nível de componentes, não há a necessidade de instalar o Cypress na pasta frontend/.

},
"scripts": {
"start": "react-scripts start",
Expand Down
Loading