One swap per banner + admin takedown (Marty 2026-11-15: "allow the member to swap it only, and they can only do it one time. Admin takes down the option to credit back or none.")

Member swap: My Banners shows "Swap image or link" on a banner that is waiting or in the loop, usable once (then "Swap used"). POST /api/my/banners/<id>/swap changes the image and/or link (or a Banner Spin to another of the member's own 125x125/250x250 spins via lsspins), same checks as a new post (checkLink, probeLink, upload/https image checks); id, place, clicks and loop progress stay. Logged on the banner (swaps: old/new image + link, time). No withdraw, removal or refund for members.

Admin takedown: /admin finds banners (#id, wallet, username), POST /api/admin/banners/<id>/takedown {reason required, credit: back|none}. The banner is hidden at once (splash loop + waiting line show a house tile in its place, /go goes home, no look/teaser/swap); its place rides out on time so nobody moves, then it ends with no cycle, no network views, no prize count. My Banners shows "Taken down" with the reason. Restore reverses a given credit (when the owner still holds one) and, if its place rode out meanwhile, records the cycle then. Admin ledger: GET /api/admin/actions (who, when, reason, credit decision).

Chatbot: CANNED 'swap' + FACTS line (KNOWLEDGE_DATE already 2026-11-15), chat-qa entry. my.js?v=4, admin.js?v=3, vbb.css?v=8.
Tests: smoke section 15 (swap once, refused twice, keeps place, bad link/image refused, spin swap, takedown credit back vs none, others keep places, ride-out without a cycle, restore, admin ledger, phone UI): 308/308 with the committed networksso.js; chatbot.test 182/182; qa:chain 49/49.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 15:18:49 -06:00
parent 666cdd9569
commit 8e6d2f9cd0
11 changed files with 409 additions and 28 deletions
+1
View File
@@ -9,6 +9,7 @@
{ "q": "Are the 150 views added to my advertising yet?", "kb": "cycle", "must": ["not switched on yet"] },
{ "q": "How do I win the weekly prize?", "kb": "leaders", "must": ["top three", "following Monday"] },
{ "q": "What are the SPIN tiles?", "kb": "spin-tiles", "must": ["never shift"] },
{ "q": "Can I change the link on my banner?", "kb": "swap", "must": ["one time", "keeps its place"] },
{ "q": "Which wallet should I use?", "kb": "wallet", "must": ["SafePal or any other crypto wallet"] },
{ "q": "Is this a pyramid scheme?", "kb": "safe", "must": ["contract", "not an income opportunity"] }
],
+133
View File
@@ -647,6 +647,139 @@ async function main() {
await browser.close();
}
// ---- 15. one swap per banner (members) + admin takedown / restore (Marty 2026-11-15) ----
console.log('15. one swap per banner + admin takedown and restore');
await sleep(1200); ENV.LOOP_SIZE = '5'; await stop(); await boot();
{
const ADM = (q, body) => anon.json(q, body, { 'x-admin-token': ADMIN });
const ids = v => v.loop.map(t => String(t.id));
const shiftOnce = async () => { const rs = await Promise.all([client(), client(), client()].map(c => visit(c))); return rs.some(x => x.shifted); };
const X = [];
for (let i = 0; i < 7; i++) { const m = await walletMember(); await m.json('/api/my'); const b = await postBanner(m, 20 + i, 'https://swap-member.com/p?i=' + i); m.bid = b.banner && b.banner.id; X.push(m); }
ok(X.every(m => m.bid), 'seven members posted a banner each', X.map(m => m.bid));
let shifted = 0; for (let i = 0; i < 3; i++) if (await shiftOnce()) shifted++;
let st = await ADM('/api/admin/status');
ok(shifted === 3 && st.loop.filled === 5 && st.queue.length >= 2, 'three shifts: loop full of 5, others waiting', { shifted, loop: st.loop.ids, q: st.queue.next });
const own = id => X.find(m => m.bid === id);
const Xa = own(st.loop.ids[2]), Xt = own(st.loop.ids[1]), Xq = own(st.queue.next[1]);
ok(!!(Xa && Xt && Xq), 'the new banners sit at loop places 1 to 3 and in the line', { loop: st.loop.ids, q: st.queue.next });
// -- the swap
let my = await Xa.json('/api/my'); let mb = my.banners.find(b => b.id === Xa.bid);
ok(mb && mb.canSwap === true && mb.swapUsed === false, 'My Banners: a banner in the loop can be swapped', mb);
const before = { place: mb.place, clicks: mb.clicks, img: mb.img, link: mb.link, progress: st.progress };
let r = await Xt.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'https://other-member.com/' }); ok(r._status === 404, 'nobody can swap another member\'s banner', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', {}); ok(r._status === 400 && /new image, a new link/.test(r.error), 'a swap with nothing new is refused', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'http://plain-http.com/' }); ok(r._status === 400 && /https/.test(r.error), 'swap: an http link is refused (same check as a new post)', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'https://bit.ly/abc' }); ok(r._status === 400 && /shortener/.test(r.error), 'swap: a shortener link is refused', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { img: 'http://swap-member.com/x.png' }); ok(r._status === 400 && /https/.test(r.error), 'swap: an http image address is refused', r);
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { img: '/u/00000000-aaaaaaaaaaaa.png' }); ok(r._status === 400, 'swap: someone else\'s (or a missing) upload is refused', r);
my = await Xa.json('/api/my'); mb = my.banners.find(b => b.id === Xa.bid);
ok(mb.canSwap === true && mb.link === before.link && mb.img === before.img, 'refused swaps change nothing and do not use up the swap', mb);
const nu = await upload(Xa, png(125, 125, 7));
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { img: nu.img, link: 'https://swapped-member.com/new' });
ok(r.ok && r.banner.id === Xa.bid && r.banner.img === nu.img && r.banner.link === 'https://swapped-member.com/new' && r.banner.state === 'loop' && r.banner.place === before.place, 'the swap changes image + link and keeps the id and the place', r);
my = await Xa.json('/api/my'); mb = my.banners.find(b => b.id === Xa.bid);
ok(mb.swapUsed === true && mb.canSwap === false && mb.swappedAt > 0 && mb.place === before.place && mb.clicks === before.clicks, 'after the swap: used, no second button, same place and clicks', mb);
st = await ADM('/api/admin/status'); ok(st.progress === before.progress && st.loop.ids[2] === Xa.bid, 'the swap leaves the bar and the loop order alone', { p: [before.progress, st.progress], loop: st.loop.ids });
let sp = await anon.json('/api/splash'); const tA = sp.loop.find(t => t.id === Xa.bid);
ok(tA && tA.img === nu.img, 'the splash shows the new image at once', tA);
r = await anon.req('/go/' + Xa.bid); ok(r.status === 302 && r.headers.get('location') === 'https://swapped-member.com/new', 'clicks go to the new link', r.headers.get('location'));
r = await Xa.json('/api/my/banners/' + Xa.bid + '/swap', { link: 'https://third-try.com/' }); ok(r._status === 400 && /already used its one swap/.test(r.error), 'a second swap is refused', r);
let ab = await ADM('/api/admin/banners?q=%23' + Xa.bid);
ok(ab.banners && ab.banners[0].swaps.length === 1 && ab.banners[0].swaps[0].old.link === before.link && ab.banners[0].swaps[0].new.link === 'https://swapped-member.com/new' && ab.banners[0].swaps[0].old.img === before.img && ab.banners[0].swaps[0].at > 0,
'the swap is logged on the banner (old + new link and image, time)', ab.banners && ab.banners[0].swaps);
// a waiting banner can swap its link only, and keeps its number in line
my = await Xq.json('/api/my'); mb = my.banners.find(b => b.id === Xq.bid); const qpos = mb.position;
r = await Xq.json('/api/my/banners/' + Xq.bid + '/swap', { link: 'https://queued-swap.com/' });
my = await Xq.json('/api/my'); mb = my.banners.find(b => b.id === Xq.bid);
ok(r.ok && mb.state === 'queued' && mb.position === qpos && mb.link === 'https://queued-swap.com/' && mb.swapUsed, 'a waiting banner swaps its link only and keeps its number in line', mb);
// a Banner Spin swaps to another of the member's own spins
const SPX = await walletMember(); await SPX.json('/api/my');
LSA.set(SPX.address, { username: 'spinswap', spins: [{ id: 41, name: 'First', code: 'qk7swp01', size: '125x125', paused: false, banners: 1 }, { id: 42, name: 'Second', code: 'qk7swp02', size: '250x250', paused: false, banners: 1 }, { id: 43, name: 'Wide', code: 'qk7swp03', size: '468x60', paused: false, banners: 1 }] });
const spb = await SPX.json('/api/my/banners', { spinId: 41 });
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { spinId: 41 }); ok(r._status === 400 && /already shows/.test(r.error), 'swap to the same Banner Spin is refused', r);
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { spinId: 43 }); ok(r._status === 400 && /125x125/.test(r.error), 'swap to a 468x60 spin is refused', r);
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { link: 'https://half-swap.com/' }); ok(r._status === 400 && /Banner Spin/.test(r.error), 'a Banner Spin cannot swap its link alone', r);
r = await SPX.json('/api/my/banners/' + spb.banner.id + '/swap', { spinId: 42 });
my = await SPX.json('/api/my'); mb = my.banners.find(b => b.id === spb.banner.id);
ok(r.ok && mb.img.includes('qk7swp02') && mb.link.includes('/c/qk7swp02') && mb.spin && mb.spin.name === 'Second' && mb.swapUsed, 'a Banner Spin swaps to another of the member\'s own spins', mb);
// -- the takedown (credit back), the place stays
st = await ADM('/api/admin/status'); const loop0 = st.loop.ids.slice(); const T = Xt.bid; const ti = loop0.indexOf(T);
let tl = await ADM('/api/admin/member-lookup?q=%23' + T); const cr0 = tl.credits;
r = await anon.json('/api/admin/banners/' + T + '/takedown', { reason: 'Broken page', credit: 'back' }); ok(r._status === 401, 'takedown needs the admin token', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { credit: 'back' }); ok(r._status === 400 && /reason is required/.test(r.error), 'takedown without a reason is refused', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'Broken landing page' }); ok(r._status === 400 && /credit/.test(r.error), 'takedown without the credit choice is refused', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'Broken landing page', credit: 'back', by: 'marty' });
ok(r.ok && r.banner.down && r.banner.down.creditBack === true && r.ownerCredits === cr0 + 1, 'takedown with credit back: the owner gets the post credit', r);
r = await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'again', credit: 'none' }); ok(r._status === 400 && /already/.test(r.error), 'a banner cannot be taken down twice', r);
sp = await anon.json('/api/splash');
ok(ids(sp)[ti] === 'h' + T && sp.loop[ti].house === true && !sp.loop.some(t => t.id === T) && !JSON.stringify(sp.loop).includes('"/go/' + T + '"'), 'the splash shows a house tile in its place, never the banner', sp.loop[ti]);
ok(JSON.stringify(ids(sp).filter((x, i) => i !== ti)) === JSON.stringify(loop0.filter((x, i) => i !== ti).map(String)), 'every other banner keeps its place', { before: loop0, after: ids(sp) });
ok(!sp.loop[ti].owner && sp.loop[ti].img === '/art/tile-house.svg', 'the house tile carries no owner, image or link of the banner', sp.loop[ti]);
r = await anon.req('/art/tile-house.svg'); ok(r.status === 200, 'the house tile image is served');
r = await anon.req('/go/' + T); ok(r.status === 302 && r.headers.get('location') === '/', 'its click relay goes home, not to the banner link', r.headers.get('location'));
my = await Xt.json('/api/my'); mb = my.banners.find(b => b.id === T);
ok(mb.state === 'down' && mb.downReason === 'Broken landing page' && mb.creditBack === true && mb.canSwap === false && my.credits === cr0 + 1, 'My Banners shows it taken down with the reason and the credit back', mb);
r = await Xt.json('/api/my/banners/' + T + '/swap', { link: 'https://sneaky-swap.com/' }); ok(r._status === 400 && /taken down/.test(r.error), 'a taken-down banner cannot be swapped', r);
r = await Xt.json('/api/my/order', { sku: 3, ref: T }); ok(r._status === 400 && /taken down/.test(r.error), 'a taken-down banner cannot get the banner look', r);
// restore: back in its place, the credit taken back
r = await ADM('/api/admin/banners/' + T + '/restore', { reason: 'page fixed, my mistake' });
ok(r.ok && r.creditReversed === true && r.ownerCredits === cr0 && !r.banner.down, 'restore: the banner is back and the credit given back is taken back', r);
sp = await anon.json('/api/splash'); ok(ids(sp)[ti] === String(T), 'restore: the banner shows in its own place again', ids(sp));
r = await ADM('/api/admin/banners/' + T + '/restore', {}); ok(r._status === 400, 'restoring a banner that is not down is refused', r);
// a waiting banner taken down with no credit: the line keeps its numbers
st = await ADM('/api/admin/status'); const q0 = st.queue.next.slice(); const Q = q0[0];
tl = await ADM('/api/admin/member-lookup?q=%23' + Q); const qc0 = tl.credits;
r = await ADM('/api/admin/banners/' + Q + '/takedown', { reason: 'Adult content', credit: 'none' });
ok(r.ok && r.banner.down.creditBack === false && r.ownerCredits === qc0, 'takedown with no credit: the owner\'s credits do not change', r);
sp = await anon.json('/api/splash');
ok(sp.queue[0].id === 'h' + Q && sp.queue.slice(1).map(t => t.id).join() === q0.slice(1, sp.queue.length).join(), 'the waiting line shows a house tile; nobody behind it moves', sp.queue.map(t => t.id));
// the back banner taken down rides out on time but never cycles or earns
st = await ADM('/api/admin/status'); const L = st.loop.nextOut; const cyc0 = st.totals.cycles; const led0 = (await ADM('/api/admin/ledger?n=2000')).entries.filter(e => e.bannerId === L).length;
r = await ADM('/api/admin/banners/' + L + '/takedown', { reason: 'Malware report', credit: 'none' }); ok(r.ok, 'the next-out banner is taken down', r);
const qBefore = st.queue.next.slice();
ok(await shiftOnce(), 'the loop shifts as usual');
st = await ADM('/api/admin/status'); ab = await ADM('/api/admin/banners?q=%23' + L);
ok(!st.loop.ids.includes(L) && ab.banners[0].state === 'ended' && st.totals.cycles === cyc0, 'its place rode out on time: state ended, no cycle counted', { state: ab.banners[0].state, cyc: [cyc0, st.totals.cycles] });
ok((await ADM('/api/admin/ledger?n=2000')).entries.filter(e => e.bannerId === L).length === led0, 'no network views recorded for it');
ok(st.loop.ids[0] === qBefore[0], 'the next waiting banner (the house tile of #' + qBefore[0] + ' too) entered at the front as usual', { loop: st.loop.ids, q: qBefore });
// restoring after it rode out records the cycle it would have had
r = await ADM('/api/admin/banners/' + L + '/restore', { reason: 'report was wrong' });
ok(r.ok && r.cycle && r.cycle.bannerId === L && r.cycle.note === 'restored' && r.banner.state === 'cycled', 'restore after it rode out: the cycle is recorded then', r);
r = await ADM('/api/admin/banners/' + Q + '/restore', {}); ok(r.ok && r.creditReversed === false && !r.banner.down, 'restore with no credit given: nothing to take back', r);
const acts = await ADM('/api/admin/actions');
const kinds = acts.actions.map(a => a.action + ':' + a.bannerId + ':' + a.credit);
ok(acts.actions.length === 6 && acts.actions.every(a => a.at > 0 && a.by && a.id) && kinds.includes('takedown:' + T + ':back') && kinds.includes('takedown:' + Q + ':none') && kinds.includes('restore:' + T + ':taken back')
&& acts.actions.find(a => a.action === 'takedown' && a.bannerId === T).reason === 'Broken landing page' && acts.actions.find(a => a.bannerId === T && a.action === 'takedown').by === 'marty',
'the admin ledger logs who, when, reason and the credit decision', acts.actions);
ab = await ADM('/api/admin/banners?q=%23' + T); ok(ab.banners[0].downs.length === 1 && ab.banners[0].downs[0].creditReversed === true, 'the banner keeps its takedown history', ab.banners[0].downs);
ab = await ADM('/api/admin/banners?q=' + Xa.address); ok(ab.banners && ab.banners.length === 1 && ab.banners[0].id === Xa.bid, 'admin finds banners by wallet', ab);
r = await ADM('/api/admin/banners?q=nobody-here-zz'); ok(r._status === 404, 'admin: no banner found answers 404');
r = await anon.req('/admin'); const ah2 = await r.text(); ok(/id="bnCard"/.test(ah2) && /id="aActions"/.test(ah2), 'the admin page has the takedown card and the admin ledger');
if (!process.env.SKIP_UI && fs.existsSync(PW)) {
const { chromium } = require(PW); const browser = await chromium.launch(); const errs = [];
const ctx = await browser.newContext({ viewport: { width: 390, height: 900 }, userAgent: 'Mozilla/5.0 (iPhone) AppleWebKit/605.1.15 Mobile Safari SmokeUI-swap' });
const pg = await ctx.newPage(); pg.on('pageerror', e => errs.push(e.message));
await ctx.addCookies([{ name: 'vbb.sid', value: Xt.jar['vbb.sid'], url: BASE }]);
await pg.goto(BASE + '/my', { waitUntil: 'domcontentloaded' }); await pg.waitForSelector('.swap-row button', { timeout: 8000 }).catch(() => {});
ok((await pg.textContent('.swap-row button').catch(() => '')) === 'Swap image or link', 'My Banners (phone): the "Swap image or link" button shows');
await pg.click('.swap-row button'); ok(await pg.isVisible('.swap-box .sw-link'), 'tapping it opens the swap form');
await pg.fill('.swap-box .sw-link', 'https://ui-swapped.com/'); await pg.click('.swap-box .sw-go');
await pg.waitForFunction(() => /Swap used/.test(document.querySelector('#mine').textContent), null, { timeout: 8000 }).catch(() => {});
ok(/Swap used/.test(await pg.textContent('#mine')) && /Swapped\. Banner #/.test(await pg.textContent('#status')), 'the swap goes through and the button turns into "Swap used"');
ok((await pg.evaluate(() => document.documentElement.scrollWidth)) <= 390, 'no sideways scroll on a phone');
await pg.screenshot({ path: path.join(OUT, 'my-swap.png'), fullPage: true });
await ADM('/api/admin/banners/' + T + '/takedown', { reason: 'Adult content', credit: 'none' });
await pg.goto(BASE + '/my', { waitUntil: 'domcontentloaded' }); await pg.waitForSelector('.pill.down', { timeout: 8000 }).catch(() => {});
ok(/Taken down/i.test(await pg.textContent('#mine')) && /Adult content/.test(await pg.textContent('#mine')), 'My Banners shows "Taken down" with the reason');
await pg.screenshot({ path: path.join(OUT, 'my-down.png'), fullPage: true });
ok(errs.length === 0, 'no page errors (swap)', errs);
await browser.close();
}
}
await stop();
console.log('\n' + pass + ' passed, ' + fail + ' failed');
fs.writeFileSync(path.join(OUT, 'smoke.txt'), new Date().toISOString() + ' ' + pass + ' passed, ' + fail + ' failed\n');