refactor: extract seed_trusted_session + setup_badge_test_page into shared test helpers
All 4 badge test files had identical ~35-line beforeEach blocks (pageerror listener,
inline V3 route mocks, addInitScript localStorage seed). Replaced with two helpers
in minimal_v3_mocks.ts:
seed_trusted_session(page, event_id, account_id?)
— seeds ae_loc localStorage with trusted/manager auth via addInitScript;
account_id defaults to testing_account_id
setup_badge_test_page(page, event_id)
— one-call beforeEach: pageerror listener + attach_minimal_v3_routes +
seed_trusted_session
Each test file's beforeEach is now 1-3 lines. All 12 tests still pass.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
import { mock_site_domain } from './env';
|
||||
import { mock_site_domain, testing_account_id } from './env';
|
||||
import { ae_app_local_data_defaults } from './ae_defaults';
|
||||
|
||||
export const minimal_event = (event_id: string) => ({
|
||||
data: {
|
||||
@@ -75,4 +76,49 @@ export async function attach_minimal_v3_routes(page: Page, event_id: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export default { minimal_event, minimal_badge, attach_minimal_v3_routes };
|
||||
/**
|
||||
* Seed localStorage with a trusted/manager session for the given event.
|
||||
*
|
||||
* Must be called via page.addInitScript — runs before page JS executes so the
|
||||
* store_versions.ts guard sees __version and leaves ae_loc intact.
|
||||
*
|
||||
* @param account_id Defaults to testing_account_id from env.ts.
|
||||
*/
|
||||
export async function seed_trusted_session(
|
||||
page: Page,
|
||||
event_id: string,
|
||||
account_id: string = testing_account_id
|
||||
): Promise<void> {
|
||||
await page.addInitScript(
|
||||
([defaults, e_id, a_id]: [typeof ae_app_local_data_defaults, string, string]) => {
|
||||
const data: any = {
|
||||
...defaults,
|
||||
account_id: a_id,
|
||||
allow_access: true,
|
||||
authenticated_access: true,
|
||||
trusted_access: true,
|
||||
manager_access: true,
|
||||
edit_mode: false,
|
||||
};
|
||||
data.mod = { ...defaults.mod, events: { ...defaults.mod.events, event_id: e_id } };
|
||||
window.localStorage.setItem('ae_loc', JSON.stringify(data));
|
||||
},
|
||||
[ae_app_local_data_defaults, event_id, account_id] as [typeof ae_app_local_data_defaults, string, string]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* One-call beforeEach setup for badge print/render tests.
|
||||
*
|
||||
* Wires:
|
||||
* - page.on('pageerror') → stderr
|
||||
* - attach_minimal_v3_routes() — mock all /v3/ API calls
|
||||
* - seed_trusted_session() — seed ae_loc localStorage with trusted auth
|
||||
*/
|
||||
export async function setup_badge_test_page(page: Page, event_id: string): Promise<void> {
|
||||
page.on('pageerror', (err) => console.error(`BROWSER ERROR: ${err.message}`));
|
||||
await attach_minimal_v3_routes(page, event_id);
|
||||
await seed_trusted_session(page, event_id);
|
||||
}
|
||||
|
||||
export default { minimal_event, minimal_badge, attach_minimal_v3_routes, seed_trusted_session, setup_badge_test_page };
|
||||
|
||||
Reference in New Issue
Block a user