← back to IWasCute
verification/TK-11380/verify.cjs
58 lines
const assert = require('node:assert/strict');
const fs = require('node:fs');
const { chromium } = require('/Users/macstudio3/Projects/Designer-Wallcoverings/node_modules/playwright');
const base = process.env.VERIFY_URL || 'http://127.0.0.1:19962';
const output = process.env.VERIFY_OUTPUT || __dirname;
const publisher = 'ca-pub-5278231299883833';
const results = [];
(async () => {
const browser = await chromium.launch({ executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', headless: true });
try {
const page = await browser.newPage();
const adRequests = [];
page.on('request', req => { if (/adsbygoogle|googlesyndication|doubleclick/.test(req.url())) adRequests.push(req.url()); });
// Keep this verification isolated: no third-party requests or real ad impressions.
await page.route('**/*', route => new URL(route.request().url()).origin === new URL(base).origin ? route.continue() : route.abort());
for (const path of ['/', '/v1', '/v2', '/v3', '/browse', '/login', '/licensor', '/dashboard', '/admin']) {
const response = await fetch(base + path);
assert.equal(response.status, 200, path);
const html = await response.text();
assert.match(html, /<meta name="google-adsense-account" content="ca-pub-5278231299883833"/);
assert.doesNotMatch(html, /adsbygoogle\.js/);
assert.ok(html.includes('G-2DHDBP8R78'), 'Preserve existing GA4 identity: ' + path);
await page.goto(base + path, { waitUntil: 'domcontentloaded' });
await page.locator('body').waitFor({ state: 'visible' });
// The uploader has ongoing work; network-idle is not its readiness contract.
await page.waitForTimeout(750);
assert.equal(await page.locator('meta[name="google-adsense-account"]').getAttribute('content'), publisher);
assert.equal(await page.locator('script[src*="adsbygoogle"]').count(), 0);
await page.waitForFunction(() => Array.isArray(window.dataLayer) && window.dataLayer.some(entry => entry[0] === 'config' && entry[1] === 'G-2DHDBP8R78'));
results.push({ path, html: 'PASS', hydrated: 'PASS' });
}
await page.goto(base, { waitUntil: 'networkidle' });
await page.locator('a[href="/v1"]').first().click();
await page.waitForURL('**/v1');
await page.locator('a[href="/login"]').first().click();
await page.waitForURL('**/login');
await page.waitForLoadState('networkidle');
assert.equal(await page.locator('script[src*="adsbygoogle"]').count(), 0);
assert.deepEqual(adRequests, []);
results.push({ journey: 'home -> v1 -> login', adRequests: 0, verdict: 'PASS' });
const admin = await fetch(base + '/api/admin');
assert.equal(admin.status, 401);
assert.deepEqual(await admin.json(), { error: 'Unauthorized' });
const adminPost = await fetch(base + '/api/admin', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'verification_probe' }) });
assert.equal(adminPost.status, 401);
assert.deepEqual(await adminPost.json(), { error: 'Unauthorized' });
const ads = await fetch(base + '/ads.txt');
assert.equal(ads.status, 200);
assert.equal((await ads.text()).trim(), 'google.com, pub-5278231299883833, DIRECT, f08c47fec0942fa0');
results.push({ adminWithoutCookie: 401, adminPostWithoutCookie: 401, analyticsConfig: 'G-2DHDBP8R78', adsTxt: 'PASS' });
fs.mkdirSync(output, { recursive: true });
await page.screenshot({ path: output + '/login.png', fullPage: true });
fs.writeFileSync(output + '/results.json', JSON.stringify({ timestamp: new Date().toISOString(), base, results, adRequests, thirdPartyRequestsBlocked: true }, null, 2) + '\n');
console.log(JSON.stringify({ verdict: 'PASS', checkedRoutes: 9, clientNavigation: 'PASS', adminAuth: 'PASS', adRequests: 0 }));
} finally { await browser.close(); }
})().catch(err => { console.error(err); process.exitCode = 1; });