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:
17
tests/_helpers/env.ts
Normal file
17
tests/_helpers/env.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Centralized test environment constants for Playwright and unit tests.
|
||||
* Use snake_case names per project preference.
|
||||
*/
|
||||
export const test_base_url = 'http://demo.localhost:5173';
|
||||
export const dev_api_base = 'https://dev-api.oneskyit.com';
|
||||
export const demo_account_id = '_XY7DXtc9MY';
|
||||
export const demo_event_id = 'pjrcghqwert';
|
||||
|
||||
export const TEST_ENV = {
|
||||
test_base_url,
|
||||
dev_api_base,
|
||||
demo_account_id,
|
||||
demo_event_id
|
||||
};
|
||||
|
||||
export default TEST_ENV;
|
||||
73
tests/_helpers/minimal_v3_mocks.ts
Normal file
73
tests/_helpers/minimal_v3_mocks.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { Page } from '@playwright/test';
|
||||
|
||||
export const minimal_event = (event_id: string) => ({
|
||||
data: {
|
||||
id: event_id,
|
||||
event_id: event_id,
|
||||
name: 'Test Event (minimal)',
|
||||
cfg_json: {},
|
||||
mod_pres_mgmt_json: {},
|
||||
mod_badges_json: {},
|
||||
mod_abstracts_json: {},
|
||||
mod_exhibits_json: {},
|
||||
mod_meetings_json: {},
|
||||
},
|
||||
});
|
||||
|
||||
export const minimal_badge = (overrides: Record<string, any> = {}) => ({
|
||||
event_badge_id: 'badge-1',
|
||||
full_name_override: 'Test User',
|
||||
email: 'test@example.com',
|
||||
badge_type: 'test',
|
||||
...overrides,
|
||||
});
|
||||
|
||||
/**
|
||||
* Attach minimal V3 route handlers to a Playwright `page`.
|
||||
* - Responds to event GET, badge search/create/update/delete, and a simple site_domain/search.
|
||||
* - Keeps created badge state in-memory for the page session.
|
||||
*/
|
||||
export async function attach_minimal_v3_routes(page: Page, event_id: string) {
|
||||
let created_badge: any = null;
|
||||
|
||||
await page.route('**/v3/**', async (route) => {
|
||||
const req = route.request();
|
||||
const url = req.url();
|
||||
const method = req.method();
|
||||
|
||||
if (url.includes('site_domain/search')) {
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [{ id: 'td', site_id: 'ts' }] }) });
|
||||
}
|
||||
|
||||
if (url.includes(`/v3/crud/event/${event_id}`) && method === 'GET') {
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(minimal_event(event_id)) });
|
||||
}
|
||||
|
||||
if (url.includes(`/v3/crud/event/${event_id}/event_badge/search`) && method === 'POST') {
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: created_badge ? [created_badge] : [] }) });
|
||||
}
|
||||
|
||||
if (url.includes(`/v3/crud/event/${event_id}/event_badge`) && method === 'POST') {
|
||||
const post = await req.postData();
|
||||
const body = post ? JSON.parse(post) : {};
|
||||
created_badge = { ...minimal_badge(body) };
|
||||
return route.fulfill({ status: 201, contentType: 'application/json', body: JSON.stringify({ data: created_badge }) });
|
||||
}
|
||||
|
||||
if (url.match(new RegExp(`/v3/crud/event/${event_id}/event_badge/.+`)) && (method === 'PATCH' || method === 'PUT')) {
|
||||
const post = await req.postData();
|
||||
const body = post ? JSON.parse(post) : {};
|
||||
if (created_badge) created_badge = { ...created_badge, ...body };
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: created_badge }) });
|
||||
}
|
||||
|
||||
if (url.match(new RegExp(`/v3/crud/event/${event_id}/event_badge/.+`)) && method === 'DELETE') {
|
||||
created_badge = null;
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: true }) });
|
||||
}
|
||||
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
|
||||
});
|
||||
}
|
||||
|
||||
export default { minimal_event, minimal_badge, attach_minimal_v3_routes };
|
||||
Reference in New Issue
Block a user