fb083b7085
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
2.1 KiB
JavaScript
24 lines
2.1 KiB
JavaScript
// GET /api/admin/member-extra (2026-11-14): the network hub's member lookup reads opt-out, tank and hold state here. Read-only.
|
|
// Runs against LOCAL (bash qa/run.sh member starts it). Admin = Bearer localtest.
|
|
const B = process.env.LOCAL || 'http://127.0.0.1:8796';
|
|
let pass = 0, fail = 0; const ok = (c, m, x) => { if (c) pass++; else { fail++; console.log('[bug] member-extra ' + m + (x ? ' :: ' + x : '')); } };
|
|
const email = 'mx' + Date.now() + '@example.com'; const ip = '198.51.100.' + (20 + Math.floor(Math.random() * 200));
|
|
const H = { 'Content-Type': 'application/json', 'X-Forwarded-For': ip, 'User-Agent': 'Mozilla/5.0 MemberExtraQA' };
|
|
const post = (p, b) => fetch(B + p, { method: 'POST', headers: H, body: JSON.stringify(b) }).then(r => r.json().catch(() => ({})));
|
|
const get = (q, auth) => fetch(B + '/api/admin/member-extra?email=' + encodeURIComponent(q), { headers: auth ? { Authorization: 'Bearer ' + auth } : {} });
|
|
try {
|
|
ok((await get(email)).status === 401, 'no admin header is refused');
|
|
ok((await get(email, 'wrong')).status === 401, 'a wrong admin password is refused');
|
|
ok((await get(email, 'localtest')).status === 404, 'an unknown email is 404');
|
|
const st = await post('/api/auth/email/start', { email, fts: Date.now() - 8000, fage: 8000 });
|
|
if (st.devCode) await post('/api/auth/email/verify', { email, code: st.devCode });
|
|
const r = await get(email, 'localtest'); const j = await r.json().catch(() => null);
|
|
ok(r.status === 200 && j, 'a known account answers', r.status);
|
|
ok(j && j.tank && typeof j.tank.inTank === 'boolean', 'tank.inTank is a boolean', JSON.stringify(j));
|
|
ok(j && 'optedOut' in j, 'optedOut is present');
|
|
const w = await fetch(B + '/api/admin/member-extra?email=' + encodeURIComponent(email), { method: 'POST', headers: { Authorization: 'Bearer localtest' } });
|
|
ok(w.status !== 200 || !(await w.text()).includes('optedOut'), 'POST is not a route (read-only)');
|
|
} catch (e) { fail++; console.log('[bug] member-extra crashed :: ' + e.message); }
|
|
console.log('member-extra: ' + pass + ' passed, ' + fail + ' failed');
|
|
process.exit(fail ? 1 : 0);
|