7be213311f
Orlando (#30) could only pause, resume or top up a banner or login ad with a wrong link. - POST /api/my/campaigns/<id>/edit (owner) and /api/admin/campaigns/<id>/edit (any ad, free, never uses the member's free edit). Banner: link, image, name. Text: link, headline, line, name. Login and the rest: link, name. Type, size, budget, geo, schedule, audience are refused. - Create and edit share one path: checkName/checkTarget/checkBannerImage/checkTextCopy in ads.js (validate() now calls them) and adChecks() in server.js (frame check + a new banner image check: loads, is a real PNG/JPG/GIF/WebP, up to 3 MB; own uploads read off the volume). - Fee: campaigns.edits counts member edits; the first is free, each later one costs the site setting campaignEditFee (default 100, admin Settings). Charged from the engine pool via spendEarned (earned first, then credited purchased); with neither, a burn row on the best-funded position (the normal burn queue). Guarded claim so two saves cannot both be free; a failed save refunds exactly what was taken. - History: campaigns.edit_log (ts, by, fields, old/new values, fee), last 50. - NAS: clicks already route through /api/ads/click/<id>, so a new link needs no write; a new image or text goes to the NAS row via nas.updateCreative. Failures never block the edit and retry on the next reconcile pass. Open ad-viewer tokens get the new link. - UI: Edit button on the Ads screen (CR.dialog editor, real-size preview, upload, free/fee note and confirm), /ads#edit=<id> deep link from the /tools list, admin Member content shows edit count + history with an Edit action. Chatbot canned answer + FACTS. - qa/adedit.mjs: 51 checks against a throwaway DATA_DIR, Playwright screenshots in D:/tmp/ad-edit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
258 lines
23 KiB
JavaScript
258 lines
23 KiB
JavaScript
// Ad editing end-to-end test (2026-10-18, Orlando's ask). Boots server.js on its own port with a throwaway, seeded data
|
|
// dir (JSON store, no DB, no mail key, devCode sign-in, NAS off, no chain: free members only), then checks:
|
|
// create banner + login ads with seeded credits; first edit free, second charges the fee, third refused when short;
|
|
// bad URL / bad image / blocked-framing link refused; type, size, budget locked; non-owner refused; history recorded;
|
|
// a NAS-linked campaign edits with NAS off (no crash); admin edit is free and keeps the member's free edit;
|
|
// the Ads screen Edit flow in Playwright with screenshots.
|
|
// node qa/adedit.mjs (from the site dir; needs internet for the frame check on example.com)
|
|
// Env: PORT (default 8963), PW (playwright package dir), SHOTS (default D:/tmp/ad-edit)
|
|
import { pathToFileURL } from 'node:url';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import http from 'node:http';
|
|
import zlib from 'node:zlib';
|
|
import crypto from 'node:crypto';
|
|
import { spawn } from 'node:child_process';
|
|
|
|
const PW = process.env.PW || 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright';
|
|
const { chromium } = (await import(pathToFileURL(PW + '/index.js').href)).default;
|
|
const PORT = Number(process.env.PORT || 8963);
|
|
const BASE = 'http://127.0.0.1:' + PORT;
|
|
const SHOTS = process.env.SHOTS || 'D:/tmp/ad-edit';
|
|
const ADMIN_PW = 'localtest-ae';
|
|
const results = []; let failed = 0;
|
|
const check = (ok, what, detail) => { results.push((ok ? 'PASS ' : 'FAIL ') + what + (detail ? ' :: ' + detail : '')); if (!ok) failed++; };
|
|
|
|
function crc32(buf) { let c, crc = 0xffffffff; for (let n = 0; n < buf.length; n++) { c = (crc ^ buf[n]) & 0xff; for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1; crc = (crc >>> 8) ^ c; } return (crc ^ 0xffffffff) >>> 0; }
|
|
function png(w, h, rgb) {
|
|
const chunk = (t, d) => { const l = Buffer.alloc(4); l.writeUInt32BE(d.length); const td = Buffer.concat([Buffer.from(t), d]); const c = Buffer.alloc(4); c.writeUInt32BE(crc32(td)); return Buffer.concat([l, td, c]); };
|
|
const ih = Buffer.alloc(13); ih.writeUInt32BE(w, 0); ih.writeUInt32BE(h, 4); ih[8] = 8; ih[9] = 2;
|
|
const raw = Buffer.alloc((w * 3 + 1) * h);
|
|
for (let y = 0; y < h; y++) { const o = y * (w * 3 + 1); for (let x = 0; x < w; x++) { const i = o + 1 + x * 3; const st = ((x >> 4) & 1) ? 40 : 0; raw[i] = Math.min(255, rgb[0] + st); raw[i + 1] = rgb[1]; raw[i + 2] = rgb[2]; } }
|
|
return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk('IHDR', ih), chunk('IDAT', zlib.deflateSync(raw)), chunk('IEND', Buffer.alloc(0))]);
|
|
}
|
|
|
|
// ── seed: two free members (no member id, so no chain calls), engine-pool credits, one NAS-linked campaign ──
|
|
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'ae-qa-'));
|
|
fs.mkdirSync(path.join(DATA, 'uploads'));
|
|
const now = Date.now();
|
|
const acct = (email, username) => ({ email, username, code: username.slice(0, 7), memberId: 0, created: now - 86400000, sponsorRef: '' });
|
|
const A = 'orlando@ae.test', B = 'other@ae.test';
|
|
const accounts = { v: 2, byEmail: { [A]: acct(A, 'aeorlando'), [B]: acct(B, 'aeother') }, byAddress: {}, byCode: {}, joins: 2, positions: {} };
|
|
for (const a of Object.values(accounts.byEmail)) accounts.byCode[a.code] = a.email;
|
|
fs.writeFileSync(path.join(DATA, 'accounts.json'), JSON.stringify(accounts));
|
|
// A: 1000 credited purchased (the login slot) + 200 viewing (110 free once two banners hold 90); B: 500 viewing
|
|
fs.writeFileSync(path.join(DATA, 'earned.json'), JSON.stringify({ [A]: { balance: 1200, grade: 1000, welcomed: true }, [B]: { balance: 500, welcomed: true } }));
|
|
// a banner of A's that is syndicated to NAS (nasAdId set), so the edit walks the network branch with NAS off
|
|
fs.writeFileSync(path.join(DATA, 'campaigns.json'), JSON.stringify({ v: 1, nextId: 2, burnsPending: [], campaigns: [{ id: 1, owner: A, memberId: 0, type: 'banner', name: 'Old network banner',
|
|
targetUrl: 'https://example.com/', imageUrl: 'https://example.com/old.png', title: null, body: null, budget: 40, spent: 0, accrued: 0, imps: 0, clicks: 0, batchImps: 0,
|
|
width: 468, height: 60, nasAdId: 4242, status: 'active', created: now - 3600000 }] }));
|
|
const IMG = { a: png(468, 60, [200, 40, 40]), b: png(468, 60, [40, 160, 60]), c: png(300, 250, [40, 80, 220]) };
|
|
fs.mkdirSync(SHOTS, { recursive: true });
|
|
for (const [k, b] of Object.entries(IMG)) fs.writeFileSync(path.join(DATA, k + '.png'), b);
|
|
|
|
const site = path.resolve(path.dirname(new URL(import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, '$1')), '..');
|
|
const env = Object.assign({}, process.env, { PORT: String(PORT), DATA_DIR: DATA, ADMIN_PASSWORD: ADMIN_PW, ADMIN_EMAIL: 'admin@ae.test' });
|
|
for (const k of ['NODE_ENV', 'DATABASE_URL', 'ENGINE_KEY', 'LS_SYNC_SECRET', 'OUTBOUND', 'LS_TESTERS', 'CURTAIN', 'NAS_DB_HOST', 'NAS_DB_USER', 'NAS_DB_PASSWORD', 'NAS_DB_NAME', 'SENDGRID_API_KEY']) delete env[k];
|
|
const log = fs.createWriteStream(path.join(SHOTS, 'server.log'));
|
|
const srv = spawn(process.execPath, ['server.js'], { cwd: site, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
srv.stdout.pipe(log); srv.stderr.pipe(log);
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
function req(method, p, o) {
|
|
o = o || {};
|
|
return new Promise((resolve, reject) => {
|
|
const headers = Object.assign({ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) QA' }, o.headers || {});
|
|
if (o.cookie) headers.Cookie = o.cookie; if (o.ip) headers['X-Forwarded-For'] = o.ip;
|
|
let body = o.body; if (body && !Buffer.isBuffer(body)) { body = Buffer.from(JSON.stringify(body)); headers['Content-Type'] = 'application/json'; }
|
|
if (body) headers['Content-Length'] = body.length;
|
|
const r = http.request({ host: '127.0.0.1', port: PORT, path: p, method, headers }, res => { const ch = []; res.on('data', c => ch.push(c)); res.on('end', () => { const buf = Buffer.concat(ch); let j = null; try { j = JSON.parse(buf.toString()); } catch (e) {} resolve({ status: res.statusCode, headers: res.headers, buf, json: j }); }); });
|
|
r.on('error', reject); if (body) r.write(body); r.end();
|
|
});
|
|
}
|
|
async function signIn(email) {
|
|
const ip = '10.8.' + crypto.randomInt(250) + '.' + crypto.randomInt(250);
|
|
const s = await req('POST', '/api/auth/email/start', { ip, body: { email, fts: Date.now() - 8000, hp_field_x9: '', pick: null } });
|
|
if (!s.json || !s.json.devCode) throw new Error('no devCode for ' + email + ': ' + s.buf.toString().slice(0, 200));
|
|
const v = await req('POST', '/api/auth/email/verify', { ip, body: { email, code: s.json.devCode } });
|
|
const sc = [].concat(v.headers['set-cookie'] || []).map(c => c.split(';')[0]).join('; ');
|
|
if (!sc) throw new Error('no session cookie for ' + email);
|
|
return sc;
|
|
}
|
|
const err = r => (r.json && r.json.error) || ('HTTP ' + r.status);
|
|
const ADMIN = { Authorization: 'Bearer ' + ADMIN_PW };
|
|
|
|
let browser, page = null; const pageErrors = [];
|
|
try {
|
|
for (let i = 0; i < 40; i++) { try { const r = await req('GET', '/api/config'); if (r.status === 200) break; } catch (e) {} await sleep(500); }
|
|
const cA = await signIn(A), cB = await signIn(B);
|
|
const earnA = async () => (await req('GET', '/api/my/earn', { cookie: cA })).json;
|
|
const campsA = async () => (await req('GET', '/api/my/campaigns', { cookie: cA })).json;
|
|
|
|
// ── create: a banner (uploaded image) and a login slot ──
|
|
const up = await req('POST', '/api/my/upload', { cookie: cA, body: IMG.a, headers: { 'Content-Type': 'image/png' } });
|
|
check(up.status === 200 && /^\/uploads\//.test(up.json.url), 'banner image uploads', err(up));
|
|
const imgA = BASE + up.json.url;
|
|
const mkB = await req('POST', '/api/my/campaigns', { cookie: cA, body: { type: 'banner', name: 'Orlando banner', targetUrl: 'https://example.com/', budget: 50, size: '468x60', imageUrl: imgA } });
|
|
check(mkB.status === 200 && mkB.json.campaign && mkB.json.campaign.edits === 0, 'banner ad created (edits 0)', err(mkB));
|
|
const mkL = await req('POST', '/api/my/campaigns', { cookie: cA, body: { type: 'login', name: 'Orlando login', targetUrl: 'https://example.com/login-page', budget: 1000 } });
|
|
check(mkL.status === 200 && mkL.json.campaign, 'login ad created from credited purchased credits', err(mkL));
|
|
const BID = mkB.json.campaign.id, LID = mkL.json.campaign.id;
|
|
const badCreate = await req('POST', '/api/my/campaigns', { cookie: cA, body: { type: 'banner', name: 'Bad img', targetUrl: 'https://example.com/', budget: 20, size: '468x60', imageUrl: 'https://example.com/' } });
|
|
check(badCreate.status === 400 && /PNG, JPG, GIF or WebP/.test(err(badCreate)), 'create runs the same image check (an HTML page is not an image)', err(badCreate));
|
|
const list0 = await campsA();
|
|
check(list0.editFee === 100, 'GET campaigns carries the edit fee (default 100)', String(list0.editFee));
|
|
|
|
// ── refusals that never cost anything ──
|
|
const e0 = await earnA();
|
|
const badUrl = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { targetUrl: 'ftp://nope.example/x' } });
|
|
check(badUrl.status === 400 && /only http\(s\) URLs work/.test(err(badUrl)), 'bad link refused (same message as create)', err(badUrl));
|
|
const shapeUrl = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { targetUrl: 'not a url' } });
|
|
check(shapeUrl.status === 400, 'malformed link refused', err(shapeUrl));
|
|
const framed = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { targetUrl: 'https://www.google.com/' } });
|
|
check(framed.status === 400 && /blocks framing/.test(err(framed)), 'link that blocks framing refused (frame check, as create)', err(framed));
|
|
const badImg = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { imageUrl: 'https://example.com/' } });
|
|
check(badImg.status === 400 && /PNG, JPG, GIF or WebP/.test(err(badImg)), 'bad image (a web page) refused', err(badImg));
|
|
const badImg2 = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { imageUrl: 'javascript:alert(1)' } });
|
|
check(badImg2.status === 400 && /image URL starting with http/.test(err(badImg2)), 'non-http image refused with the create message', err(badImg2));
|
|
const missImg = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { imageUrl: BASE + '/uploads/aaaaaaaaaaaaaaaaaaaaaaaa.png' } });
|
|
check(missImg.status === 400 && /not on this server/.test(err(missImg)), 'an upload that does not exist refused', err(missImg));
|
|
for (const [k, v] of [['type', 'text'], ['size', '300x250'], ['budget', 999], ['geo', '1'], ['dailyCap', 20], ['endsAt', now + 9e8]]) {
|
|
const r = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { [k]: v, name: 'try ' + k } });
|
|
check(r.status === 400 && /cannot be changed/.test(err(r)), k + ' cannot be changed', err(r));
|
|
}
|
|
const same = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { type: 'banner', size: '468x60', budget: 50, name: 'Orlando banner v2' } });
|
|
check(same.status === 200, 'sending the unchanged type/size/budget alongside an edit is fine', err(same));
|
|
const BEdits1 = same.json && same.json.campaign && same.json.campaign.edits;
|
|
check(same.json && same.json.fee === 0 && BEdits1 === 1, 'first edit of the banner is free', JSON.stringify({ fee: same.json && same.json.fee, edits: BEdits1 }));
|
|
const other = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cB, body: { targetUrl: 'https://example.com/hijack' } });
|
|
check(other.status === 400 && /No such campaign/.test(err(other)), 'non-owner refused', err(other));
|
|
const anon = await req('POST', '/api/my/campaigns/' + BID + '/edit', { body: { name: 'x' } });
|
|
check(anon.status === 401, 'signed-out refused', String(anon.status));
|
|
const nothing = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { name: 'Orlando banner v2' } });
|
|
check(nothing.status === 400 && /Nothing changed/.test(err(nothing)), 'no change refused (no fee)', err(nothing));
|
|
const e1 = await earnA();
|
|
check(e1.earned === e0.earned, 'refusals and the free edit charged nothing', e0.earned + ' -> ' + e1.earned);
|
|
|
|
// ── the login ad: first edit free (link), second costs 100 ──
|
|
const l1 = await req('POST', '/api/my/campaigns/' + LID + '/edit', { cookie: cA, body: { targetUrl: 'https://example.com/fixed-login' } });
|
|
check(l1.status === 200 && l1.json.fee === 0 && l1.json.campaign.targetUrl === 'https://example.com/fixed-login', 'login ad link fixed, free', err(l1));
|
|
const lImg = await req('POST', '/api/my/campaigns/' + LID + '/edit', { cookie: cA, body: { imageUrl: imgA, name: 'Orlando login' } });
|
|
check(lImg.status === 400 && /Nothing changed/.test(err(lImg)), 'login ad has no image to edit (the page is the ad)', err(lImg));
|
|
|
|
// ── banner: second edit costs 100, third refused when short ──
|
|
const before2 = await earnA();
|
|
const up2 = await req('POST', '/api/my/upload', { cookie: cA, body: IMG.b, headers: { 'Content-Type': 'image/png' } });
|
|
const b2 = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { imageUrl: BASE + up2.json.url, targetUrl: 'https://example.com/?offer=new' } });
|
|
const after2 = await earnA();
|
|
check(b2.status === 200 && b2.json.fee === 100 && b2.json.paidFrom === 'earned', 'second edit charges 100 credits from earned', err(b2) + ' ' + JSON.stringify(b2.json && { fee: b2.json.fee, paidFrom: b2.json.paidFrom }));
|
|
check(before2.earned - after2.earned === 100, 'the pool dropped by exactly 100', before2.earned + ' -> ' + after2.earned);
|
|
const freeNow = after2.earnedAvailable;
|
|
check(freeNow < 100, 'A now has fewer than 100 free credits (' + freeNow + ')', String(freeNow));
|
|
const b3 = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { name: 'Third try' } });
|
|
const after3 = await earnA();
|
|
check(b3.status === 400 && /costs 100 credits/.test(err(b3)) && b3.json.short === true, 'third edit refused when credits are short', err(b3));
|
|
check(after3.earned === after2.earned, 'the refused edit charged nothing', after2.earned + ' -> ' + after3.earned);
|
|
const cs3 = await campsA(); const B3 = cs3.campaigns.find(c => c.id === BID);
|
|
check(B3.edits === 2 && B3.name === 'Orlando banner v2' && B3.targetUrl === 'https://example.com/?offer=new', 'refused edit left the ad and the count alone', JSON.stringify({ edits: B3.edits, name: B3.name }));
|
|
// ── history ──
|
|
const h = B3.editLog || [];
|
|
check(h.length === 2 && h[0].fields.join() === 'name' && h[0].from.name === 'Orlando banner' && h[0].to.name === 'Orlando banner v2' && h[0].fee === 0
|
|
&& h[1].fields.includes('imageUrl') && h[1].fields.includes('targetUrl') && h[1].from.targetUrl === 'https://example.com/' && h[1].fee === 100 && h[1].ts > 0, 'edit history: ts, fields, old and new values, fee', JSON.stringify(h).slice(0, 300));
|
|
// ── NAS-linked campaign with NAS off ──
|
|
const n1 = await req('POST', '/api/my/campaigns/1/edit', { cookie: cA, body: { imageUrl: imgA } });
|
|
check(n1.status === 200 && n1.json.network === null, 'NAS-linked banner edits with NAS off: no crash, network untouched', err(n1) + ' ' + JSON.stringify(n1.json && n1.json.network));
|
|
const alive = await req('GET', '/api/config');
|
|
check(alive.status === 200, 'server still up after the NAS branch', String(alive.status));
|
|
// ── admin: free, any campaign, member's count untouched ──
|
|
const ad = await req('POST', '/api/admin/campaigns/' + BID + '/edit', { headers: ADMIN, body: { name: 'Typo fixed by Marty' } });
|
|
check(ad.status === 200 && ad.json.fee === 0 && ad.json.campaign.edits === 2, 'admin edit: free, member edit count unchanged', err(ad) + ' edits=' + (ad.json && ad.json.campaign && ad.json.campaign.edits));
|
|
const adNo = await req('POST', '/api/admin/campaigns/' + BID + '/edit', { body: { name: 'x' } });
|
|
check(adNo.status === 401, 'admin route needs admin', String(adNo.status));
|
|
const ct = await req('GET', '/api/admin/content?type=ad&fresh=1&per=50', { headers: ADMIN });
|
|
const row = ct.json && ct.json.items.find(r => r.id === String(BID));
|
|
check(row && row.detail.edits === 2 && row.detail.editLog.length === 3 && row.detail.editLog[2].by === 'admin' && row.actions.some(a => a.label === 'Edit ad'), 'admin Member content shows edits, history and an Edit action', JSON.stringify(row && { edits: row.detail.edits, n: row.detail.editLog.length }));
|
|
// ── the fee setting ──
|
|
await req('PATCH', '/api/admin/site', { headers: ADMIN, body: { campaignEditFee: 0 } });
|
|
const z = await req('POST', '/api/my/campaigns/' + BID + '/edit', { cookie: cA, body: { name: 'Free while the fee is 0' } });
|
|
check(z.status === 200 && z.json.fee === 0, 'campaignEditFee 0 makes edits free', err(z));
|
|
await req('PATCH', '/api/admin/site', { headers: ADMIN, body: { campaignEditFee: 100 } });
|
|
// ── chatbot ──
|
|
const cb = await req('POST', '/api/chat', { cookie: cA, body: { message: 'How do I fix the link on my ad?' } });
|
|
check(cb.json && /press Edit/.test(cb.json.reply || ''), 'chatbot canned answer for fixing an ad link', (cb.json && (cb.json.reply || cb.json.error) || '').slice(0, 80));
|
|
|
|
// ── the Ads screen: Edit flow in the browser ──
|
|
browser = await chromium.launch();
|
|
const ctx = await browser.newContext({ viewport: { width: 1360, height: 950 } });
|
|
await ctx.addCookies(cA.split('; ').map(kv => { const i = kv.indexOf('='); return { name: kv.slice(0, i), value: kv.slice(i + 1), domain: '127.0.0.1', path: '/' }; }));
|
|
await ctx.addInitScript(() => { try { sessionStorage.setItem('ls.la', '1'); } catch (e) {} }); // skip the once-per-session login sponsor gate
|
|
page = await ctx.newPage();
|
|
page.on('pageerror', e => pageErrors.push(e.message)); page.on('console', m => { if (m.type() === 'error' && !/favicon|fonts|status of 40[014]|ERR_NAME|ERR_CONNECTION|example\.com/.test(m.text())) pageErrors.push(m.text()); });
|
|
// give A a fresh banner with a free edit, plus enough for one paid edit
|
|
const up3 = await req('POST', '/api/my/upload', { cookie: cA, body: IMG.a, headers: { 'Content-Type': 'image/png' } });
|
|
const mk2 = await req('POST', '/api/my/campaigns', { cookie: cA, body: { type: 'banner', name: 'UI banner', targetUrl: 'https://example.com/', budget: 10, size: '468x60', imageUrl: BASE + up3.json.url } });
|
|
check(mk2.status === 200, 'second banner for the UI flow', err(mk2));
|
|
const UID = mk2.json.campaign.id;
|
|
await page.goto(BASE + '/ads', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('[data-edit="' + UID + '"]', { timeout: 15000 });
|
|
await page.screenshot({ path: path.join(SHOTS, '01-ads-list-edit-buttons.png'), fullPage: true });
|
|
await page.click('[data-edit="' + UID + '"]');
|
|
await page.waitForSelector('#dlg-targetUrl', { timeout: 5000 });
|
|
check(await page.inputValue('#dlg-targetUrl') === 'https://example.com/', 'editor prefilled with the current link');
|
|
check(/free \(your one free correction\)/.test(await page.textContent('#edFee')), 'editor shows the free note', (await page.textContent('#edFee')).trim());
|
|
const pw = await page.$eval('#edPrev img', i => i.getBoundingClientRect().width).catch(() => 0);
|
|
check(Math.round(pw) === 468 + 2 || Math.round(pw) === 468, 'image preview at real size (468 px)', String(pw));
|
|
await page.fill('#dlg-targetUrl', 'https://example.com/?ui=fixed');
|
|
await page.setInputFiles('#edFile', path.join(DATA, 'b.png'));
|
|
await page.waitForFunction(() => /\/uploads\//.test(document.querySelector('#dlg-imageUrl').value), null, { timeout: 5000 });
|
|
await page.screenshot({ path: path.join(SHOTS, '02-editor-free.png') });
|
|
await page.click('#dlgOk');
|
|
await page.waitForSelector('.modal h2', { timeout: 5000 });
|
|
const conf1 = await page.textContent('.modal');
|
|
check(/This edit is free \(your one free correction\)/.test(conf1), 'confirm says the edit is free', conf1.slice(0, 120));
|
|
await page.screenshot({ path: path.join(SHOTS, '03-confirm-free.png') });
|
|
await page.click('#dlgOk');
|
|
await page.waitForFunction(id => { const b = document.querySelector('[data-edit="' + id + '"]'); return b && /credits/.test(b.title); }, UID, { timeout: 10000 });
|
|
const cu = (await campsA()).campaigns.find(c => c.id === UID);
|
|
check(cu.targetUrl === 'https://example.com/?ui=fixed' && /\/uploads\//.test(cu.imageUrl) && cu.edits === 1, 'UI edit saved link + new upload', JSON.stringify({ t: cu.targetUrl, e: cu.edits }));
|
|
// second, paid edit: give A 100 more earned credits through the admin grant path is not available here, so top the
|
|
// pool up by the promo-free route: B cannot gift, so check the fee wording and the refusal toast instead
|
|
await page.click('[data-edit="' + UID + '"]');
|
|
await page.waitForSelector('#dlg-name', { timeout: 5000 });
|
|
check(/costs 100 credits/.test(await page.textContent('#edFee')), 'editor shows the fee note on the second edit', (await page.textContent('#edFee')).trim());
|
|
await page.fill('#dlg-name', 'UI banner renamed');
|
|
await page.click('#dlgOk');
|
|
await page.waitForSelector('.modal h2', { timeout: 5000 });
|
|
const conf2 = await page.textContent('.modal');
|
|
check(/This edit costs 100 credits/.test(conf2) && /Save and pay 100/.test(conf2), 'confirm says the edit costs 100 credits', conf2.slice(0, 160));
|
|
await page.screenshot({ path: path.join(SHOTS, '04-confirm-fee.png') });
|
|
await page.click('#dlgOk');
|
|
await page.waitForSelector('#crToast.on.bad', { timeout: 8000 });
|
|
const toastTxt = await page.textContent('#crToast');
|
|
check(/costs 100 credits/.test(toastTxt), 'short on credits: clear refusal in the screen', toastTxt.slice(0, 140));
|
|
await page.screenshot({ path: path.join(SHOTS, '05-refused-short.png') });
|
|
// phone width
|
|
await page.setViewportSize({ width: 390, height: 844 }); await page.reload({ waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('[data-edit="' + UID + '"]', { timeout: 15000 });
|
|
await page.click('[data-edit="' + UID + '"]'); await page.waitForSelector('#dlg-name', { timeout: 5000 });
|
|
await page.screenshot({ path: path.join(SHOTS, '06-editor-phone.png') });
|
|
const hs = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth);
|
|
check(hs <= 1, 'no horizontal page scroll at phone width with the editor open', String(hs));
|
|
// the /tools campaign list deep link
|
|
await page.goto(BASE + '/ads#edit=' + BID, { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('#dlg-name', { timeout: 15000 });
|
|
check(/Edit ad #/.test(await page.textContent('.modal h2')), '/ads#edit=<id> opens the editor (link from the /tools list)');
|
|
check(!pageErrors.length, 'no page errors', pageErrors.slice(0, 3).join(' | '));
|
|
} catch (e) {
|
|
check(false, 'run crashed', e.stack + ' | page errors: ' + pageErrors.join(' | ')); if (page) try { await page.screenshot({ path: path.join(SHOTS, 'crash.png'), fullPage: true }); } catch (x) {}
|
|
} finally {
|
|
if (browser) await browser.close();
|
|
srv.kill();
|
|
await sleep(300);
|
|
try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {}
|
|
console.log(results.join('\n'));
|
|
console.log('\n' + (results.length - failed) + '/' + results.length + ' passed' + (failed ? ', ' + failed + ' FAILED' : ''));
|
|
fs.writeFileSync(path.join(SHOTS, 'results.txt'), results.join('\n') + '\n');
|
|
process.exit(failed ? 1 : 0);
|
|
}
|