← back to Carmelwallpapers

verification/TK-11380/verify-disclosures.cjs

56 lines

const assert = require('node:assert/strict');
const fs = require('node:fs');
const { chromium } = require('/Users/macstudio3/Projects/Designer-Wallcoverings/node_modules/playwright');
const live = process.argv.includes('--live');
const sites = [
  { name: 'carmel', base: live ? 'https://carmelwallpapers.com' : 'http://127.0.0.1:19961', domain: 'carmelwallpapers.com', minimum: 1000, product: '/p/' },
  { name: 'hospitality', base: live ? 'https://hospitalitydesignreps.com' : 'http://127.0.0.1:19963', domain: 'hospitalitydesignreps.com', minimum: 60, product: '/rep/' },
];
(async () => {
  const browser = await chromium.launch({ executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', headless: true });
  const proof = { timestamp: new Date().toISOString(), environment: live ? 'live' : 'local', sites: [] };
  try {
    for (const site of sites) {
      const get = async path => {
        const response = await fetch(site.base + path, { headers: { 'User-Agent': 'TK-11380-readiness-check' } });
        assert.equal(response.status, 200, site.name + path);
        return response.text();
      };
      const home = await get('/');
      assert.ok(home.includes('href="/privacy"'));
      const privacy = await get('/privacy');
      assert.match(privacy, /My Ad Center/);
      assert.match(privacy, /YourAdChoices/);
      assert.ok(privacy.replace(/<[^>]+>/g, ' ').split(/\s+/).length > 150);
      const about = await get('/about');
      assert.doesNotMatch(about, /there is no advertising on the site/);
      const robots = await get('/robots.txt');
      assert.ok(robots.includes('https://' + site.domain + '/sitemap.xml'));
      const xml = await get('/sitemap.xml');
      const urls = [...xml.matchAll(/<loc>(.*?)<\/loc>/g)].map(m => m[1]);
      assert.ok(urls.length >= site.minimum);
      const first = urls.find(u => new URL(u).pathname.startsWith(site.product));
      assert.ok(first);
      await get(new URL(first).pathname);
      const page = await browser.newPage();
      const errors = [];
      page.on('pageerror', e => errors.push(e.message));
      // No advertising execution/impressions during readiness verification.
      await page.route('**/*', route => {
        const url = new URL(route.request().url());
        return url.origin === new URL(site.base).origin ? route.continue() : route.abort();
      });
      await page.goto(site.base, { waitUntil: 'domcontentloaded' });
      await page.locator('a[href="/privacy"]').first().click();
      await page.waitForURL('**/privacy');
      await page.locator('h1').filter({ hasText: 'Privacy' }).waitFor();
      await page.screenshot({ path: __dirname + '/' + site.name + '-privacy-' + proof.environment + '.png', fullPage: true });
      assert.deepEqual(errors, []);
      proof.sites.push({ name: site.name, paths: 'PASS', publicPrivacyLink: 'PASS', privacyRender: 'PASS', sitemapUrls: urls.length, sampledProduct: new URL(first).pathname, jsErrors: errors, adRequestsBlocked: true });
      await page.close();
    }
    fs.writeFileSync(__dirname + '/disclosures-' + proof.environment + '.json', JSON.stringify(proof, null, 2) + '\n');
    console.log(JSON.stringify(proof));
  } finally { await browser.close(); }
})().catch(err => { console.error(err); process.exitCode = 1; });