This repository has been archived on 2024-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
fotochallenge/tests/requestid.test.ts

38 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2024-08-18 15:34:36 +02:00
import { expect, test } from '@playwright/test';
import { validate, NIL } from 'uuid';
import { requestIdHeader } from '$lib';
2024-08-18 15:38:03 +02:00
test('response contains request-id header', async ({ playwright }) => {
2024-08-18 15:34:36 +02:00
const context = await playwright.request.newContext();
const response = await context.get('health');
2024-08-18 15:38:03 +02:00
const headers = response.headers();
await expect(headers).toHaveProperty(requestIdHeader);
2024-08-18 15:34:36 +02:00
});
2024-08-18 15:38:03 +02:00
test('request-id is valid uuid', async ({ playwright }) => {
2024-08-18 15:34:36 +02:00
const context = await playwright.request.newContext();
const response = await context.get('health');
2024-08-18 15:38:03 +02:00
const headers = response.headers();
const requestId = headers[requestIdHeader];
await expect(validate(requestId)).toBe(true);
2024-08-18 15:34:36 +02:00
});
2024-08-18 15:38:03 +02:00
test('reuse valid incoming uuid', async ({ playwright }) => {
2024-08-18 15:34:36 +02:00
const context = await playwright.request.newContext();
2024-08-18 15:38:03 +02:00
const response = await context.get('health', { headers: { [requestIdHeader]: NIL } });
const headers = response.headers();
const requestId = headers[requestIdHeader];
await expect(requestId).toBe(NIL);
2024-08-18 15:34:36 +02:00
});
2024-08-18 15:38:03 +02:00
test('ignore invalid incoming uuid', async ({ playwright }) => {
const invalid = '00000000-0000-0000-0000-00000000000z';
2024-08-18 15:34:36 +02:00
const context = await playwright.request.newContext();
2024-08-18 15:38:03 +02:00
const response = await context.get('health', { headers: { [requestIdHeader]: invalid } });
const headers = response.headers();
const requestId = headers[requestIdHeader];
await expect(requestId).not.toBe(invalid);
});