1+ /// <reference types="cypress" />
2+ import { fakerPT_BR as faker } from '@faker-js/faker' ;
3+
4+ describe ( 'Testes referente a funcionalidade de exclusão de reservas via API' , ( ) => {
5+ var reserva = {
6+ "firstname" : faker . name . firstName ( ) ,
7+ "lastname" : faker . name . lastName ( ) ,
8+ "totalprice" : 2800 ,
9+ "depositpaid" : faker . datatype . boolean ( ) ,
10+ "bookingdates" : {
11+ "checkin" : "2026-09-26" ,
12+ "checkout" : "2025-10-02"
13+ } ,
14+ "additionalneeds" : faker . word . words ( )
15+ }
16+
17+ it ( 'Verificar exclusão de reserva com sucesso usando autenticação com Authorization' , ( ) => {
18+ //criação da reserva
19+ //exclusão da reserva
20+
21+ cy . createBooking ( reserva ) . then ( ( response ) => {
22+ const bookingId = response . body . bookingid ;
23+
24+ cy . deleteBooking ( bookingId ) . then ( ( response ) => {
25+ expect ( response . status ) . to . eq ( 201 )
26+ } )
27+ //Validar que reserva não existe mais
28+ cy . getBookingById ( bookingId ) . then ( ( response ) => {
29+ expect ( response . status ) . to . eq ( 404 )
30+ expect ( response . body ) . contains ( 'Not Found' )
31+ } )
32+ } )
33+
34+ } )
35+
36+ it . only ( 'com token' , ( ) => {
37+
38+ //finalizar teste , e descrever etapas , (uso do alias, etc)
39+ const credentials = {
40+ "username" : "admin" ,
41+ "password" : "password123"
42+ }
43+
44+ cy . createToken ( credentials ) ;
45+
46+ cy . get ( '@authToken' ) . then ( ( token ) => {
47+ cy . createBooking ( reserva ) . then ( ( response ) => {
48+ const bookingId = response . body . bookingid ;
49+
50+ cy . api ( {
51+ method : 'DELETE' ,
52+ url : `${ Cypress . config ( 'baseUrl' ) } /booking/${ bookingId } ` ,
53+ headers : {
54+ Cookie : `token=${ token } `
55+ }
56+ } ) . then ( ( response ) => {
57+ expect ( response . status ) . to . eq ( 201 )
58+ } )
59+ //Validar que reserva não existe mais
60+ // cy.getBookingById(bookingId).then((response) => {
61+ // expect(response.status).to.eq(404)
62+ // expect(response.body).contains('Not Found')
63+ // })
64+ } )
65+
66+ } )
67+ } )
68+ } )
0 commit comments