Skip to content

Commit fcebd3e

Browse files
committed
add tests getBookingById
1 parent 0f9985c commit fcebd3e

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

cypress/e2e/getBookingById.cy.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,44 @@
22
import { fakerPT_BR as faker } from '@faker-js/faker';
33

44
describe('Funcionalidade de consultar a reserva com o ID', () => {
5-
it('Verificar dados da reserva após consulta por ID', () => {
65

6+
var reserva = {
7+
"firstname": faker.name.firstName(),
8+
"lastname": faker.name.lastName(),
9+
"totalprice": 3500,
10+
"depositpaid": faker.datatype.boolean(),
11+
"bookingdates": {
12+
"checkin": "2026-09-26",
13+
"checkout": "2025-10-02"
14+
},
15+
"additionalneeds": faker.word.words()
16+
}
17+
it('Verificar que dados da reserva estão corretos após consulta por ID', () => {
18+
//criação da reserva
19+
cy.createBooking(reserva).then((response) => {
20+
const bookingId = response.body.bookingid
21+
22+
23+
//consulta e valida reserva
24+
cy.getBookingById(bookingId).then((response) => {
25+
expect(response.status).to.eq(200)
26+
27+
expect(response.body).to.have.property('firstname', reserva.firstname)
28+
expect(response.body.lastname).to.eq(reserva.lastname)
29+
expect(response.body).to.have.property('totalprice', reserva.totalprice)
30+
expect(response.body).to.have.property('depositpaid', reserva.depositpaid)
31+
expect(response.body.bookingdates).to.have.property('checkin', reserva.bookingdates.checkin)
32+
expect(response.body.bookingdates).to.have.property('checkout', reserva.bookingdates.checkout)
33+
expect(response.body).to.have.property('additionalneeds', reserva.additionalneeds)
34+
})
35+
})
36+
})
37+
38+
it('Verificar erro 404 ao consultar por ID inexistente', () => {
39+
const bookingId = 789654
40+
cy.getBookingById(bookingId).then((response) => {
41+
expect(response.status).to.eq(404)
42+
expect(response.body).contains('Not Found')
43+
})
744
})
845
})

cypress/e2e/getBookingId.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('Funcionalidade de consultar o ID', () => {
123123
})
124124

125125
it.skip('Verificar response vazio ao consultar ID com uma data de checkin não cadastrada', () => {
126-
//Existe bug na api.
126+
//Existe bug na api.| Filtro não funciona, e retorna diversas reservas
127127
const data = '2012-08-11'
128128

129129
cy.getBookingId(parametro, data).then((response) => {
@@ -160,7 +160,7 @@ describe('Funcionalidade de consultar o ID', () => {
160160
})
161161
})
162162
it.skip('Verificar response vazio ao consultar ID com uma data de checkout não cadastrada', () => {
163-
//Existe bug na api.
163+
//Existe bug na api. | Filtro não funciona, e retorna diversas reservas
164164
const data = '2015-08-11'
165165

166166
// cy.api({

cypress/support/commands.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,18 @@ Cypress.Commands.add('createBooking', (dadosReserva) => {
4444
})
4545
})
4646

47-
//Criar lógica para incluir parâmetro enviado
4847
Cypress.Commands.add('getBookingId', (parametro, dado) => {
4948
cy.api({
5049
method: 'GET',
5150
url: `${Cypress.config('baseUrl')}/booking?${parametro}=${dado}`
5251
//`${Cypress.config('baseUrl')}/booking?checkin=${checkin}`
5352
})
53+
})
54+
55+
Cypress.Commands.add('getBookingById', (bookingId) => {
56+
cy.api({
57+
method: 'GET',
58+
url: `${Cypress.config('baseUrl')}/booking/${bookingId}`,
59+
failOnStatusCode: false
60+
})
5461
})

0 commit comments

Comments
 (0)