1+ // @ts -check
2+ const { test, expect } = require ( '@playwright/test' ) ;
3+
4+ var token
5+
6+ test ( 'should be able to update the booking details' , async ( { request } ) => {
7+
8+ // Create a Token which will be used in PUT request
9+
10+ const response = await request . post ( `/auth` , {
11+ data : {
12+ "username" : "admin" ,
13+ "password" : "password123"
14+ }
15+ } ) ;
16+ console . log ( await response . json ( ) ) ;
17+ expect ( response . ok ( ) ) . toBeTruthy ( ) ;
18+ expect ( response . status ( ) ) . toBe ( 200 ) ;
19+ const responseBody = await response . json ( ) ;
20+ token = responseBody . token ;
21+ console . log ( "New Token is: " + token ) ;
22+
23+ // PUT
24+ const updateRequest = await request . put ( `/booking/1` , {
25+ headers : {
26+ 'Content-Type' : 'application/json' ,
27+ 'Accept' : 'application/json' ,
28+ 'Cookie' : `token=${ token } ` ,
29+ } ,
30+ data : {
31+ "firstname" : "Jim" ,
32+ "lastname" : "Brown" ,
33+ "totalprice" : 111 ,
34+ "depositpaid" : true ,
35+ "bookingdates" : {
36+ "checkin" : "2023-06-01" ,
37+ "checkout" : "2023-06-15"
38+ } ,
39+ "additionalneeds" : "Breakfast"
40+ }
41+ } ) ;
42+ console . log ( await updateRequest . json ( ) ) ;
43+ expect ( updateRequest . ok ( ) ) . toBeTruthy ( ) ;
44+ expect ( updateRequest . status ( ) ) . toBe ( 200 ) ;
45+ const updatedResponseBody = await updateRequest . json ( )
46+ expect ( updatedResponseBody ) . toHaveProperty ( "firstname" , "Jim" ) ;
47+ expect ( updatedResponseBody ) . toHaveProperty ( "lastname" , "Brown" ) ;
48+ expect ( updatedResponseBody ) . toHaveProperty ( "totalprice" , 111 ) ;
49+ expect ( updatedResponseBody ) . toHaveProperty ( "depositpaid" , true ) ;
50+ } ) ;
0 commit comments