Skip to content

Instantly share code, notes, and snippets.

@checklyalex
Last active September 12, 2023 09:12
Show Gist options
  • Save checklyalex/c81e00c0d27f19322155ff07bd0042ff to your computer and use it in GitHub Desktop.
Save checklyalex/c81e00c0d27f19322155ff07bd0042ff to your computer and use it in GitHub Desktop.
An example of a Checkly Multi-Step API check utilising Playwright Test
import { test, expect } from '@playwright/test'
const token = '_ZMd4xxx'
const url = 'https://crudapi.co.uk/api/v1/tasks'
const headers = {
Authorization: `Bearer ${token}`
}
test('multi-step api', async ({ request }) => {
/**
* Step 1: GET all tasks
*/
const tasks = await test.step('get all', async () => {
return request.get(url, { headers })
})
expect(tasks).toBeOK()
const { items } = await tasks.json()
expect(items.length).toEqual(0)
/**
* Step 2: POST create new task
*/
const taskTitle = 'New task!'
const newTask = await test.step('create task', async () => {
return request.post(url, {
data: [{ title: taskTitle }],
headers,
})
})
expect(newTask).toBeOK()
const { items: [{ title, _uuid }] } = await newTask.json()
expect(title).toBe(taskTitle)
expect(_uuid).toBeDefined()
/**
* Step 3: DELETE remove task
*/
const deletedTask = await test.step('delete task', async () => {
return request.delete(url, {
data: [{ _uuid }],
headers,
})
})
expect(deletedTask).toBeOK()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment