test: modernize v3 API security tests (mock /v3/, deterministic headers); add runnable modern copy
This commit is contained in:
@@ -13,11 +13,12 @@ test.describe('V3 API Header Integrity', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// Mock all API requests to ensure tests are fast and independent of the network.
|
||||
await page.route('**/*oneskyit.com/**', async (route) => {
|
||||
const url = route.request().url();
|
||||
// Mock all local /v3/ API requests so tests are deterministic.
|
||||
await page.route('**/v3/**', async (route) => {
|
||||
const req = route.request();
|
||||
const url = req.url();
|
||||
|
||||
// 1. Handshake Mock: Provide a complete response to allow the app to boot.
|
||||
// Handshake mock so app boots predictably
|
||||
if (url.includes('site_domain/search')) {
|
||||
return route.fulfill({
|
||||
status: 200,
|
||||
@@ -26,7 +27,6 @@ test.describe('V3 API Header Integrity', () => {
|
||||
data: [
|
||||
{
|
||||
id: 'test-site-domain-id',
|
||||
id_random: 'test-site-domain-id',
|
||||
account_id: 'test-account-id',
|
||||
site_id: 'test-site-id',
|
||||
account_name: 'Test Account',
|
||||
@@ -37,12 +37,18 @@ test.describe('V3 API Header Integrity', () => {
|
||||
})
|
||||
});
|
||||
}
|
||||
// 2. Default Mock: Provide a generic empty success response for all other API calls.
|
||||
return route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ data: [] })
|
||||
});
|
||||
|
||||
// Provide lightweight responses for endpoints we assert on
|
||||
if (url.includes('/v3/lookup/country/list')) {
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
|
||||
}
|
||||
|
||||
if (url.includes('/v3/crud/user/search')) {
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
|
||||
}
|
||||
|
||||
// Default handler
|
||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ data: [] }) });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user