PUT

import { expect, test } from '@playwright/test';
import { z } from 'zod';

test("[Basic] PUT API call update booking", async ({ request }) => {
    const getBookinsgResponse = await request.get('https://restful-booker.herokuapp.com/booking');
    const bookingList = await getBookinsgResponse.json();
    const bookingId = bookingList[0].bookingid;
    const accessToken = await request.post('https://restful-booker.herokuapp.com/auth', {
        data: {
            username: 'admin',
            password: 'password123'
        }
    });
    const tokenBody = await accessToken.json();
    const token = tokenBody.token;
    const response = await request.put(`https://restful-booker.herokuapp.com/booking/${bookingId}`,{
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Cookie': `token=${token}`
        },
        data: {
            firstname: 'Jim',
            lastname: 'Brown',
            totalprice: 111,
            depositpaid: true,
            bookingdates: {
                checkin: '2025-06-05',
                checkout: '2025-06-07'
            },
            additionalneeds: 'Breakfast'
        }
    });
    const body = await response.json();
    expect(response.ok()).toBeTruthy();

    const schema = z.object({
        firstname: z.string(),
        lastname: z.string(),
        totalprice: z.number(),
        depositpaid: z.boolean(),
        bookingdates: z.object({
            checkin: z.string(),
            checkout: z.string()
        }),
        additionalneeds: z.string()
    });

    expect(() => {
        schema.parse(body);
    }).not.toThrow();
}); 

Last updated