GET
import { expect, test } from '@playwright/test';
import { z } from 'zod';
test("[Basic] Get API call has a valide response", async ({ request }) => {
const response = await request.get('https://restful-booker.herokuapp.com/booking');
const body = await response.json();
expect(response.ok()).toBeTruthy();
const schema = z.array(z.object({
bookingid: z.number()
}));
expect(() => {
schema.parse(body);
}).not.toThrow();
expect(body.length).toBeGreaterThan(0);
});
test("[Basic] GET API call get booking", async ({ request }) => {
const response = await request.get('https://restful-booker.herokuapp.com/booking/1');
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