Refill notices: Wired Wednesday in the bonus ladder + deploy-overlap claims (Fuel Your Offers stage 1, Marty approved 2026-10-24). The bonus block now lists Five Dollar Friday AND Wired Wednesday (from their live settings: wednesdayPromo, wednesdayBonusPct 25, wednesdayMinCents 2000, Central time), and takes the member's refuel-streak line from a streakLine(owner) hook (filled in stage 2). Every send is claimed in event_marks first, so the two app copies of a deploy never both email a person. qa/refill.test.cjs (copy, settings, hook, two copies) + run.sh fuel mode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// Refill notice copy + deploy-overlap claim (refill.js) on throwaway data. Run: node qa/refill.test.cjs
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
let fails = 0, n = 0;
|
||||
async function t(name, fn) { n++; try { await fn(); console.log('ok', name); } catch (e) { fails++; console.log('FAIL', name, '::', e.message); } }
|
||||
function fresh(mod) { const p = require.resolve(path.join(ROOT, mod)); delete require.cache[p]; return require(p); }
|
||||
const now = Date.now();
|
||||
|
||||
function world(dir, cfg) {
|
||||
const W = { inbox: [], mail: [], cfg: cfg || {} };
|
||||
W.campaigns = [
|
||||
{ id: 1, owner: 'a@x.test', type: 'banner', name: 'Alpha', budget: 1000, spent: 1000, accrued: 0, imps: 5000, clicks: 40, status: 'out', created: now - 30 * 864e5 },
|
||||
{ id: 2, owner: 'b@x.test', type: 'text', name: 'Bravo', budget: 1000, spent: 850, accrued: 0, imps: 8500, clicks: 9, status: 'active', created: now - 30 * 864e5 },
|
||||
];
|
||||
W.deps = {
|
||||
dataDir: dir, siteConfig: () => W.cfg,
|
||||
ads: { adminList: async () => W.campaigns.map(c => Object.assign({}, c)), rates: () => ({ videoTiers: [] }) },
|
||||
accounts: { byEmail: async e => ({ email: e, memberId: 5 }), positions: async () => [] },
|
||||
chain: { recentEvents: () => [] },
|
||||
mailer: { hasKey: () => true, send: async (to, subject, text) => { W.mail.push({ to, subject, text }); } },
|
||||
drip: { isUnsubscribed: async () => false },
|
||||
creditsFor: async () => 300,
|
||||
message: async (to, subject, html) => { W.inbox.push({ to, subject, html }); },
|
||||
};
|
||||
return W;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await t('bonus block names Five Dollar Friday AND Wired Wednesday ($20 floor, +25%)', async () => {
|
||||
const W = world(fs.mkdtempSync(path.join(os.tmpdir(), 'iap-refill-')));
|
||||
const r = fresh('refill.js'); r.init(W.deps);
|
||||
const m = await r.compose('a@x.test', [W.campaigns[0]], 'out', 300);
|
||||
assert.ok(/Five Dollar Friday: any package from \$5 up/.test(m.text), 'friday text');
|
||||
assert.ok(/Wired Wednesday: any package from \$20 up, bought on a Wednesday \(Central time\), earns an extra 25%/.test(m.text), 'wednesday text');
|
||||
assert.ok(/<b>Wired Wednesday:<\/b>/.test(m.html), 'wednesday html');
|
||||
assert.ok(!/—/.test(m.text + m.html), 'no em dash');
|
||||
});
|
||||
await t('Wednesday follows its settings (off, other floor and pct)', async () => {
|
||||
const W = world(fs.mkdtempSync(path.join(os.tmpdir(), 'iap-refill-')), { wednesdayPromo: '0' });
|
||||
const r = fresh('refill.js'); r.init(W.deps);
|
||||
let m = await r.compose('a@x.test', [W.campaigns[0]], 'out', 300);
|
||||
assert.ok(!/Wired Wednesday/.test(m.text));
|
||||
W.cfg = { wednesdayBonusPct: '30', wednesdayMinCents: '5000', fridayPromo: '0' };
|
||||
m = await r.compose('a@x.test', [W.campaigns[0]], 'out', 300);
|
||||
assert.ok(/from \$50 up.*extra 30%/.test(m.text) && !/Five Dollar Friday/.test(m.text));
|
||||
});
|
||||
await t('streak hook line (stage 2) lands in text and html; absent hook changes nothing', async () => {
|
||||
const W = world(fs.mkdtempSync(path.join(os.tmpdir(), 'iap-refill-')));
|
||||
const r = fresh('refill.js'); r.init(Object.assign({}, W.deps, { streakLine: async e => e === 'a@x.test' ? { text: 'Refuel streak: 2 months.', html: '<b>Refuel streak:</b> 2 months.' } : null }));
|
||||
const m = await r.compose('a@x.test', [W.campaigns[0]], 'out', 300);
|
||||
assert.ok(/Refuel streak: 2 months\./.test(m.text) && /<b>Refuel streak:<\/b>/.test(m.html));
|
||||
const m2 = await r.compose('b@x.test', [W.campaigns[1]], 'low', 300);
|
||||
assert.ok(!/Refuel streak/.test(m2.text));
|
||||
});
|
||||
await t('two app copies (shared claims): each owner gets one message', async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-refill-'));
|
||||
const W = world(dir);
|
||||
const marks = fresh('marks.js'); marks.init({}); // no DB: one process-wide set stands in for event_marks
|
||||
const A = fresh('refill.js'); A.init(Object.assign({}, W.deps, { marks }));
|
||||
const B = fresh('refill.js'); B.init(Object.assign({}, W.deps, { marks }));
|
||||
await Promise.all([A.tick(), B.tick()]);
|
||||
const per = {}; for (const x of W.inbox) per[x.to] = (per[x.to] || 0) + 1;
|
||||
assert.deepStrictEqual(per, { 'a@x.test': 1, 'b@x.test': 1 }, JSON.stringify(per));
|
||||
assert.strictEqual(W.mail.length, 2);
|
||||
await Promise.all([A.tick(), B.tick()]);
|
||||
assert.strictEqual(W.inbox.length, 2, 'nothing repeats on later passes');
|
||||
});
|
||||
console.log('\n' + (n - fails) + '/' + n + ' passed');
|
||||
process.exit(fails ? 1 : 0);
|
||||
})();
|
||||
@@ -13,6 +13,7 @@
|
||||
# bash qa/run.sh gamepass-games # the REAL games' polgrant.js + PolHunter's tournament payer against a local copy (needs the sibling game repos)
|
||||
# bash qa/run.sh override # level-4 override: week math, hunt, house, dust carry, cap, balance, two concurrent payers (fake chain + signer, throwaway data)
|
||||
# bash qa/run.sh convpixel # conversion pixel: lsclk click ids on /api/ads/click, signed push to a MOCK LinkSpin, own-click self flag, Campaigns > Conversion tracking + cost per goal, LinkSpin down (local copy, throwaway data)
|
||||
# bash qa/run.sh fuel # Fuel Your Offers: refill notices, refuel streak, Refuel Kit, Engine Room (unit + two-copy tests, throwaway data)
|
||||
# Each local run boots server.js on its own port with a throwaway data dir (JSON store, no DB, no
|
||||
# mail key, devCode sign-in), so nothing touches production data. Reports land in qa/out/.
|
||||
set -u
|
||||
@@ -57,6 +58,8 @@ elif [ "$MODE" = "login-queue" ]; then
|
||||
node qa/login-queue-sql.cjs || status=1
|
||||
elif [ "$MODE" = "convpixel" ]; then
|
||||
node qa/convpixel.test.mjs || status=1
|
||||
elif [ "$MODE" = "fuel" ]; then
|
||||
for f in qa/refill.test.cjs qa/refuel*.test.cjs; do [ -f "$f" ] && { node "$f" || status=1; }; done
|
||||
elif [ "$MODE" = "override" ]; then
|
||||
node qa/override.test.cjs || status=1
|
||||
elif [ "$MODE" = "gamepass-games" ]; then
|
||||
|
||||
Reference in New Issue
Block a user