tests: add Playwright event badge CRUD + interaction tests; add minimal V3 mocks and env helper; update presenter/badge smoke tests to use helpers; convert test locals to snake_case

This commit is contained in:
Scott Idem
2026-02-24 17:49:43 -05:00
parent 39614c9cc2
commit 197adff33b
10 changed files with 439 additions and 120 deletions

View File

@@ -1,7 +1,8 @@
import { test, expect } from '@playwright/test';
import { ae_app_local_data_defaults } from './_helpers/ae_defaults';
import { demo_event_id, demo_account_id } from './_helpers/env';
const testEventId = 'pjrcghqwert';
const demo_event = demo_event_id;
test.describe('Event Badge - interaction', () => {
test.beforeEach(async ({ page }) => {
@@ -11,25 +12,19 @@ test.describe('Event Badge - interaction', () => {
console.error(`BROWSER [${msg.type().toUpperCase()}]: ${msg.text()}`);
});
// Minimal network mock: fulfill only what's necessary for the UI to render
await page.route('**/v3/**', async (route) => {
const req = route.request();
const url = req.url();
if (url.includes('site_domain/search')) {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ data: [{ id: 'test-site-domain-id', site_id: 'test-site-id', account_id: '_XY7DXtc9MY' }] })
});
}
if (url.includes(`/v3/crud/event/${testEventId}`) && req.method() === 'GET') {
// Provide the minimal event payload for the settings page to render
if (url.includes(`/v3/crud/event/${demo_event}`) && req.method() === 'GET') {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ data: {
id: testEventId,
event_id: testEventId,
id: demo_event,
event_id: demo_event,
name: 'Test Event for Badge Interaction',
cfg_json: {},
mod_pres_mgmt_json: {},
@@ -41,14 +36,12 @@ test.describe('Event Badge - interaction', () => {
});
}
if (url.includes(`/v3/crud/event/${testEventId}/event_badge`) && req.method() === 'POST') {
const post = await req.postData();
console.log('Captured POST to event_badge endpoint:', url, post ? post.slice(0,200) : '');
const body = post ? JSON.parse(post) : {};
const created = { ...body, event_badge_id: 'new-badge-1' };
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ data: created }) });
// For badge create requests, return a simple created envelope with a fixed id.
if (url.includes(`/v3/crud/event/${demo_event}/event_badge`) && req.method() === 'POST') {
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ data: { event_badge_id: 'new-badge-1' } }) });
}
// Default: empty envelope so other calls don't error
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
});
@@ -57,58 +50,60 @@ test.describe('Event Badge - interaction', () => {
});
await page.addInitScript(
({ defaults, eventId }) => {
({ defaults, event_id, account_id }) => {
const testData = {
...defaults,
account_id: '_XY7DXtc9MY',
account_id: account_id,
manager_access: true,
administrator_access: true,
edit_mode: true,
mod: { ...defaults.mod, events: { ...defaults.mod.events, event_id: eventId } }
mod: { ...defaults.mod, events: { ...defaults.mod.events, event_id: event_id } }
};
window.localStorage.setItem('ae_loc', JSON.stringify(testData));
},
{ defaults: ae_app_local_data_defaults, eventId: testEventId }
{ defaults: ae_app_local_data_defaults, event_id: demo_event, account_id: demo_account_id }
);
});
test('creates a badge via UI and posts to nested endpoint', async ({ page }) => {
await page.goto(`/events/${testEventId}/settings`);
await page.goto(`/events/${demo_event}/settings`);
const addBtn = page.getByRole('button', { name: 'Add New Badge' });
await expect(addBtn).toBeVisible();
await addBtn.click();
const add_btn = page.getByRole('button', { name: 'Add New Badge' });
await expect(add_btn).toBeVisible();
await add_btn.click();
const form = page.locator('form:has-text("Create Badge")');
await expect(form).toBeVisible();
const fullNameInput = form.locator('label:has-text("Full Name Override") input');
await expect(fullNameInput).toBeVisible();
await fullNameInput.fill('Test User');
const full_name_input = form.locator('label:has-text("Full Name Override") input');
await expect(full_name_input).toBeVisible();
await full_name_input.fill('Test User');
const emailInput = form.locator('label:has-text("Email") input');
await emailInput.fill('testuser@example.com');
const email_input = form.locator('label:has-text("Email") input');
await email_input.fill('testuser@example.com');
const select = form.locator('label:has-text("Badge Type") select');
await select.selectOption('test');
const badge_type_select = form.locator('label:has-text("Badge Type") select');
await badge_type_select.selectOption('test');
const checkbox = form.locator('label:has-text("Allow Tracking") input[type="checkbox"]');
await checkbox.check();
const allow_tracking_checkbox = form.locator('label:has-text("Allow Tracking") input[type="checkbox"]');
await allow_tracking_checkbox.check();
const [request] = await Promise.all([
page.waitForRequest((r) => r.url().includes(`/v3/crud/event/${testEventId}/event_badge`) && r.method() === 'POST'),
page.getByRole('button', { name: 'Create Badge' }).click()
]);
const [create_request] = await Promise.all([
page.waitForRequest((r) => r.url().includes(`/v3/crud/event/${demo_event}/event_badge`) && r.method() === 'POST'),
page.getByRole('button', { name: 'Create Badge' }).click()
]);
const postBody = request.postData();
const postJson = postBody ? JSON.parse(postBody) : {};
expect(postJson.email).toBe('testuser@example.com');
expect(postJson.full_name_override).toBe('Test User');
const post_body = create_request.postData();
const post_json = post_body ? JSON.parse(post_body) : {};
expect(post_json.email).toBe('testuser@example.com');
expect(post_json.full_name_override).toBe('Test User');
const response = await page.waitForResponse((r) => r.url().includes(`/v3/crud/event/${testEventId}/event_badge`) && (r.status() === 201 || r.status() === 200));
const respJson = await response.json();
expect(respJson).toBeDefined();
expect(respJson.data).toBeDefined();
expect(respJson.data.event_badge_id).toBe('new-badge-1');
// Use the request's response for reliability (page.request bypasses page.route otherwise)
const response = await create_request.response();
expect(response).not.toBeNull();
const resp_json = response ? await response.json() : {};
expect(resp_json).toBeDefined();
expect(resp_json.data).toBeDefined();
expect(resp_json.data.event_badge_id).toBe('new-badge-1');
});
});