// Find a member (/lookup) end to end: the real server + the real page, index seeded, // no RPC. Start the harness first, in its own throwaway data dir (seed config only, // never the live config): // // L=/d/tmp/rmc-lookup-e2e && rm -rf $L && mkdir -p $L && echo '[]' > $L/sponsors.json // LOOKUP_SEED=qa/fixtures/lookup-index.json PORT=3405 DATA_DIR=$L ADMIN_PASSWORD=localtest node qa/harness-server.js & // LOCAL=http://127.0.0.1:3405 node qa/lookup-e2e.mjs // // The rate-limit check runs last because it uses up this IP's lookups for a minute. import { pathToFileURL } from 'node:url'; const PW = 'D:/Projects/MarketingAgent/qa-tester/node_modules/playwright'; const { chromium } = (await import(pathToFileURL(PW + '/index.js').href)).default; const B = process.env.LOCAL || 'http://127.0.0.1:3405'; const ok = [], bad = []; const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || !extra ? '' : ' -> ' + extra)); }; let ipN = Math.floor(Math.random() * 150 + 20); const freshIp = () => ({ 'x-forwarded-for': '203.0.113.' + (ipN++) }); // each context its own IP, so the 12/min limiter only bites in its own test const XFF = freshIp(); const api = async (q, h = XFF) => { const r = await fetch(B + '/api/public/lookup?q=' + encodeURIComponent(q), { headers: h }); return { s: r.status, j: await r.json().catch(() => ({})) }; }; // --- API let r = await api('7230'); t('API: #7230 found', r.s === 200 && r.j.found && r.j.id === 7230, JSON.stringify(r)); t('API: only chain fields come back', Object.keys(r.j).sort().join(',') === 'account,directCount,found,id,joinedAt,level,levelName,source,sponsorId,tier,tierName', Object.keys(r.j).join(',')); r = await api('0x7c7D9F0F11bbc66a700245795c374971BfBed3c2'); t('API: wallet resolves to #7230', r.s === 200 && r.j.id === 7230); r = await api('21'); t('API: #21 never leaks an email from the index', r.s === 200 && !JSON.stringify(r.j).includes('example.com')); r = await api('banana'); t('API: free text is a 400 with a clear message', r.s === 400 && /member ID/.test(r.j.error || '')); r = await api('0x123'); t('API: short wallet is a 400', r.s === 400); r = await api('99999'); t('API: unknown id is found:false', r.s === 200 && r.j.found === false); // --- page const browser = await chromium.launch(); for (const mobile of [false, true]) { const tag = mobile ? '[phone] ' : ''; const ctx = await browser.newContext(mobile ? { viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, extraHTTPHeaders: freshIp() } : { viewport: { width: 1280, height: 900 }, extraHTTPHeaders: freshIp() }); await ctx.addInitScript(() => { const g = Storage.prototype.getItem; Storage.prototype.getItem = function (k) { if (/^rmc-promo-/.test(k)) return 'seen'; if (/^rmc-announce-/.test(k)) return 'done'; return g.call(this, k); }; }); const page = await ctx.newPage(); const csp = []; page.on('console', m => { if (/Refused to|Content Security Policy/i.test(m.text())) csp.push(m.text()); }); page.on('pageerror', e => csp.push('pageerror: ' + e.message)); const resp = await page.goto(B + '/lookup', { waitUntil: 'networkidle' }); t(tag + '/lookup is 200', resp.status() === 200); await page.fill('#lkQ', '0x7c7D9F0F11bbc66a700245795c374971BfBed3c2'); await page.click('#lkGo'); await page.waitForSelector('#lkRes:not(.hidden)', { timeout: 8000 }); t(tag + 'wallet search shows #7230', (await page.textContent('#rId')) === '#7230'); t(tag + 'wallet is shortened', (await page.textContent('#rWallet')) === '0x7c7d...d3c2', await page.textContent('#rWallet')); t(tag + 'full wallet on hover', (await page.getAttribute('#rWallet', 'title')) === '0x7c7d9f0f11bbc66a700245795c374971bfbed3c2'); t(tag + 'level + tier', /Scintilla/.test(await page.textContent('#rLevel')) && (await page.textContent('#rTier')) === 'Premium'); t(tag + 'join date shown', /2025/.test(await page.textContent('#rJoined')), await page.textContent('#rJoined')); t(tag + 'direct referrals', (await page.textContent('#rDirects')) === '1'); t(tag + 'building badge', /1\/2/.test(await page.textContent('#rQual'))); t(tag + 'Polygonscan link', (await page.getAttribute('#rScan', 'href')) === 'https://polygonscan.com/address/0x7c7d9f0f11bbc66a700245795c374971bfbed3c2'); t(tag + 'URL carries the query', /\/lookup\?q=0x7c7D/i.test(page.url())); await page.click('#rSponsor button'); await page.waitForFunction(() => document.getElementById('rId').textContent === '#21', null, { timeout: 8000 }); t(tag + 'clicking the sponsor looks up #21', true); t(tag + '#21 shows Qualified', (await page.textContent('#rQual')) === 'Qualified'); t(tag + '#21 sponsor is #1', (await page.textContent('#rSponsor')) === '#1'); await page.goBack(); await page.waitForFunction(() => document.getElementById('rId').textContent === '#7230', null, { timeout: 8000 }); t(tag + 'Back returns to #7230', true); await page.fill('#lkQ', 'not a wallet'); await page.click('#lkGo'); t(tag + 'bad input shows an inline error', /does not look right/.test(await page.textContent('#lkMsg'))); await page.fill('#lkQ', '99999'); await page.click('#lkGo'); await page.waitForFunction(() => /no member #99999/.test(document.getElementById('lkMsg').textContent), null, { timeout: 8000 }); t(tag + 'unknown id says so and hides the card', await page.isHidden('#lkRes')); const body = await page.textContent('body'); t(tag + 'no email anywhere on the page', !/@example\.com/.test(body)); t(tag + 'no InstantAdPay/LinkSpin mention', !/InstantAdPay|LinkSpin|Downline Banners|Viral Banner/i.test(body)); const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1); t(tag + 'no horizontal scroll', !overflow); t(tag + 'no CSP refusals or page errors', csp.length === 0, csp.join(' | ')); await ctx.close(); } // deep link { const ctx = await browser.newContext({ extraHTTPHeaders: freshIp() }); const page = await ctx.newPage(); await page.goto(B + '/lookup?q=21', { waitUntil: 'networkidle' }); await page.waitForSelector('#lkRes:not(.hidden)', { timeout: 8000 }); t('deep link /lookup?q=21 opens #21', (await page.textContent('#rId')) === '#21'); const f = await (await fetch(B + '/find')).status; t('/find alias is 200', f === 200); const foot = await (await fetch(B + '/contract')).text(); t('footer on other pages links /lookup', foot.includes('href="/lookup"')); await ctx.close(); } await browser.close(); // --- rate limit (last) const H = { 'x-forwarded-for': '198.51.100.77' }; let codes = []; for (let i = 0; i < 14; i++) codes.push((await api('21', H)).s); t('rate limit: 12 per minute then 429', codes.slice(0, 12).every(c => c === 200) && codes[12] === 429 && codes[13] === 429, codes.join(',')); console.log(ok.map(x => 'ok ' + x).join('\n')); if (bad.length) { console.log(bad.map(x => 'FAIL ' + x).join('\n')); process.exit(1); } console.log(`\n${ok.length} passed`);