← back to CelebritySignatures

screenrecord/verify2-murals.mjs

63 lines

import { createRequire } from 'node:module';
import fs from 'fs';
const require = createRequire(import.meta.url);
const { chromium } = require('/Users/macstudio3/.npm-global/lib/node_modules/playwright');
const PORT = fs.readFileSync('/tmp/cs_murals_port', 'utf8').trim();
const BASE = `http://127.0.0.1:${PORT}`;
const OUT = 'screenrecord/verify2-out.txt';
const sleep = ms => new Promise(r => setTimeout(r, ms));
const out = [];
const say = s => { out.push(s); fs.writeFileSync(OUT, out.join('\n') + '\n'); };

async function freshPage(ctx) {
  const p = await ctx.newPage();
  await p.goto(BASE + '/murals', { waitUntil: 'domcontentloaded' });
  await sleep(1500);
  await p.locator('#gallery [data-place]').first().click().catch(() => {}); // sets `cur`
  await sleep(500);
  return p;
}

const b = await chromium.launch();
const ctx = await b.newContext();
await ctx.route('**/*', r => { const u = r.request().url(); if (r.request().isNavigationRequest() && !u.includes('127.0.0.1:' + PORT) && !u.startsWith('data:')) return r.abort(); return r.continue(); });

// PHASE B: fields intact -> Pay fires checkout
{
  const p = await freshPage(ctx);
  const calls = [];
  p.on('response', async r => { if (r.url().includes('/api/mural-checkout')) { let body = ''; try { body = (await r.text()).slice(0, 150); } catch {} calls.push({ status: r.status(), body }); } });
  await p.locator('#orderForm [name=name]').fill('Rec Test').catch(() => {});
  await p.locator('#orderForm [name=email]').fill('t@example.com').catch(() => {});
  const msgBefore = await p.locator('#orderMsg').textContent().catch(() => '');
  await p.locator('#payBtn').click().catch(() => {});
  await sleep(1500);
  say('(B) PAY with fields intact -> checkoutCalls=' + JSON.stringify(calls) + ' | orderMsgBeforeNavGuard="' + (msgBefore || '').trim() + '"');
  await p.close().catch(() => {});
}

// PHASE C: submit quote (resets fields) THEN pay -> observe guard message
{
  const p = await freshPage(ctx);
  const calls = [];
  p.on('response', r => { if (r.url().includes('/api/mural-checkout')) calls.push(r.status()); });
  await p.locator('#orderForm [name=name]').fill('Rec Test').catch(() => {});
  await p.locator('#orderForm [name=email]').fill('t@example.com').catch(() => {});
  await p.locator('#orderForm button[type=submit]').click().catch(() => {}); // "Request a quote instead"
  await sleep(1000);
  const fields = await p.evaluate(() => {
    const n = document.querySelector('#orderForm [name=name]');
    const e = document.querySelector('#orderForm [name=email]');
    return { name: n ? n.value : 'NULL', email: e ? e.value : 'NULL', msg: (document.querySelector('#orderMsg').textContent || '').trim() };
  }).catch(e => ({ err: '' + e }));
  say('(C) after "Request a quote instead": fields=' + JSON.stringify(fields));
  await p.locator('#payBtn').click().catch(() => {});
  await sleep(900);
  const msgC = await p.locator('#orderMsg').textContent().catch(() => '');
  say('(C) then PAY -> checkoutCalls=' + JSON.stringify(calls) + ' | orderMsg="' + (msgC || '').trim() + '"');
  await p.close().catch(() => {});
}

await b.close();
say('DONE');