test: add v3 latency probe and modernize api coverage

This commit is contained in:
Scott Idem
2026-05-21 17:48:00 -04:00
parent f5cf1ef398
commit 55d3d49595
4 changed files with 341 additions and 36 deletions

View File

@@ -101,46 +101,25 @@ test.describe('V3 API Nested CRUD Integrity', () => {
});
test('should send a nested request when creating an Event Location', async ({ page }) => {
// We'll perform the UI action and assert the resulting UI change (and the route handler
// separately logs the POST). Relying on DOM update is less flaky than waiting
// directly for the network request in this environment.
// The page is now loaded. The test will automatically fail because
// the UI is not yet interactive enough to trigger the POST request.
// The console output will show us which GET requests we need to mock.
// Validate the real app flow: click the UI button and assert the outgoing
// nested POST request shape and endpoint.
const requestPromise = page.waitForRequest(
(request) =>
request.method() === 'POST' &&
request.url().includes(`/v3/crud/event/${testing_event_id}/event_location`)
);
// Ensure the Add Location button is present
const addBtn = page.getByRole('button', { name: 'Add Location' });
await expect(addBtn).toBeVisible();
await addBtn.click();
// Instead of relying on the complex client-side helper to call the nested create,
// POST directly from the browser context to the nested endpoint so the page.route
// handler is exercised and we can assert nested endpoint behavior.
const resp = await page.evaluate(async (eventId) => {
const r = await fetch(`/v3/crud/event/${eventId}/event_location/`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'TEMP Location Name', event_id: eventId })
});
try { return { status: r.status, json: await r.json() }; } catch(e) { return { status: r.status, json: null }; }
}, testing_event_id as any);
const request = await requestPromise;
const postData = JSON.parse(request.postData() ?? '{}');
expect(resp.status === 200 || resp.status === 201).toBeTruthy();
expect(resp.json).toBeDefined();
if (resp.json && resp.json.data) expect(resp.json.data.name).toBe('TEMP Location Name');
expect(request.url()).toContain(`/v3/crud/event/${testing_event_id}/event_location`);
expect(postData.name).toBe('TEMP Location Name');
expect(postData.event_id).toBe(testing_event_id);
// Wait for the request to be captured
// const request = await requestPromise;
// const postData = request.postDataJSON();
// Assert that the request was sent to the correct nested URL
// expect(request.url()).toContain(`/v3/crud/event/${testing_event_id}/event_location`);
// Assert that the payload contains the correct fields and *does not* contain the parent ID
// expect(postData.fields).toBeDefined();
// expect(postData.fields.name).toBe('Test Location');
// expect(postData.fields.event_id).toBeUndefined();
});
});