Engine Room (Fuel Your Offers stage 4, Marty approved 2026-10-24): a new Members tab (engineNav, pane-engine) on InstantAdPay, shown only while refuelStreak is on, unlocked by the first counted refuel and greyed with one move "Refuel to start your engine" before. engine.js (the same file ships in LinkSpin): facts() gathers one site's member facts (credits free + in campaigns, recent campaigns, clicks this week and last week from click_sources via coach.clicksSince, free login slots; on LinkSpin also goals this month from the conversion pixel counted from the Central-time 1st, and the Banner Spin / spin link / page / testing parts), build() turns both sites' facts + the streak into three plain dials (fuel left vs this cycle's refuel credits incl. bonus with days left at the recent burn; clicks this week against last week with clicks per 1,000 credits; goals this month vs a member-set goal stored with the streak, refuel.setGoal), the streak panel, warning lights (ads at 80%, ads out, refuel day coming, login slot open), six part lights (fuel, banner spin, spin link, page, testing, conversion tracking: green / amber / grey with setup links) and one next move from simple ordered rules (refuel window, relaunch, Pit Stop top-up, top up the winner, tracking, Banner Spin, test A/B, cut the loser, keep running). LinkSpin facts arrive through signed /api/partner/engine (cached a minute; LinkSpin down = unknown, never zero); InstantAdPay answers the same call for LinkSpin's panel with its facts + the streak. Member /api/my/engine, /api/my/engine/goal; partner op refuel/goal. engine-room.js (same file both sites): plain SVG dials with aria labels, works at 390 px, colour only for warnings. Chatbot CANNED + FACTS cover the Engine Room. my.js?v=20261024er (PANES + engine), engine-room.js?v=20261024er. qa/refuel-engine.test.cjs 10 checks (switch, locked, each dial, lights, parts, next-move order, facts on stubbed LinkSpin incl. Central month start, goal storage).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
// Engine Room (engine.js, the same file ships in LinkSpin): build() rules, facts() on stubbed sites, the member goal.
|
||||
// Run: node qa/refuel-engine.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, '..');
|
||||
const E = require(path.join(ROOT, 'engine.js'));
|
||||
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.stack.split('\n').slice(0, 2).join(' | ')); } }
|
||||
const NOW = Date.UTC(2026, 10, 15, 18); const DAY = 864e5;
|
||||
const rf = o => Object.assign({ on: true, started: true, active: true, streak: 2, best: 2, refuelDayLabel: 'Wed, Dec 2', graceLabel: 'Mon, Dec 7', daysToRefuel: 17, windowOpen: false,
|
||||
cycle: { month: 2, both: true, iap: { refueled: true, credits: 2000, pct: 20, bonus: 400 }, linkspin: { refueled: true, credits: 2500, pct: 20, bonus: 500 } },
|
||||
next: { month: 2, secondEngine: 20 }, pitStop: { pct: 10, iap: true, linkspin: true }, freeMiss: { available: true }, minUsd: { iap: 20, linkspin: 25 } }, o || {});
|
||||
const camp = o => Object.assign({ id: 1, name: 'A', type: 'banner', status: 'active', budget: 1000, delivered: 300, clicks: 30, created: NOW - 10 * DAY }, o);
|
||||
const iap = o => Object.assign({ site: 'iap', ok: true, credits: { available: 1000, inCampaigns: 700 }, campaigns: [camp({})], clicksWeek: 40, loginFree: 0 }, o || {});
|
||||
const green = { state: 'green', note: 'ok' };
|
||||
const ls = o => Object.assign({ site: 'linkspin', ok: true, credits: { available: 2000, inCampaigns: 0 }, campaigns: [], clicksWeek: 10, loginFree: 0, goalsCount: 1, goalsMonth: 6, conv30: 9,
|
||||
parts: { bannerSpin: green, spinLink: green, page: green, testing: green } }, o || {});
|
||||
const B = o => E.build(Object.assign({ now: NOW, refuel: rf(), iap: iap(), ls: ls(), goal: 20 }, o || {}));
|
||||
|
||||
(async () => {
|
||||
await t('switch off: nothing', async () => { assert.deepStrictEqual(E.build({ refuel: { on: false } }), { on: false }); });
|
||||
await t('locked until the first counted refuel: greyed, one move "Refuel to start your engine"', async () => {
|
||||
const d = B({ refuel: rf({ started: false, active: false, cycle: null, streak: 0 }) });
|
||||
assert.ok(d.locked); assert.strictEqual(d.next.key, 'start'); assert.strictEqual(d.next.label, 'Refuel to start your engine');
|
||||
});
|
||||
await t('fuel dial: credits free + in campaigns on both sites vs this cycle\'s refuel (with bonus), days left at the burn', async () => {
|
||||
const d = B();
|
||||
assert.strictEqual(d.fuel.left, 3700); assert.strictEqual(d.fuel.refuelCredits, 5400); assert.strictEqual(d.fuel.pct, 69);
|
||||
assert.strictEqual(d.fuel.burnPerDay, 30); assert.strictEqual(d.fuel.daysLeft, 123);
|
||||
});
|
||||
await t('clicks dial: this week on both sites, and per 1,000 credits on recent campaigns', async () => {
|
||||
const d = B({ iap: iap({ clicksPrevWeek: 30 }), ls: ls({ clicksPrevWeek: 20, campaigns: [camp({ id: 9, delivered: 700, clicks: 5 })] }) });
|
||||
assert.strictEqual(d.clicks.week, 50); assert.strictEqual(d.clicks.per1000, 35); assert.strictEqual(d.clicks.prevWeek, 50); assert.strictEqual(d.clicks.pct, 50, 'same as last week = half way');
|
||||
});
|
||||
await t('goals dial: conversions this month vs the member goal; LinkSpin down = unknown, never zero', async () => {
|
||||
assert.deepStrictEqual([B().goals.month, B().goals.target, B().goals.pct], [6, 20, 30]);
|
||||
const d = B({ ls: null }); assert.strictEqual(d.goals.month, null); assert.strictEqual(d.parts[5].note, 'LinkSpin did not answer'); assert.deepStrictEqual(d.sites, { iap: true, linkspin: false });
|
||||
});
|
||||
await t('warning lights: 80%, out, refuel day coming, login slot open', async () => {
|
||||
const d = B({ refuel: rf({ daysToRefuel: 4 }), iap: iap({ loginFree: 2, campaigns: [camp({ delivered: 850 }), camp({ id: 2, status: 'out', delivered: 1000 })] }) });
|
||||
assert.deepStrictEqual(d.warnings.map(w => [w.key, w.on]), [['low', true], ['out', true], ['refuel', true], ['login', true]]);
|
||||
const q = B(); assert.ok(q.warnings.every(w => !w.on));
|
||||
});
|
||||
await t('six part lights: green / amber / grey with setup links', async () => {
|
||||
const d = B({ ls: ls({ goalsCount: 1, conv30: 0, parts: { bannerSpin: { state: 'grey', note: 'not set up' }, spinLink: green, page: { state: 'amber', note: 'draft only' }, testing: green } }) });
|
||||
assert.deepStrictEqual(d.parts.map(p => p.label), ['Fuel', 'Banner spin', 'Spin link', 'Page', 'Testing', 'Conversion tracking']);
|
||||
assert.deepStrictEqual(d.parts.map(p => p.state), ['green', 'grey', 'green', 'amber', 'green', 'amber']);
|
||||
assert.strictEqual(d.parts[5].note, 'no conversions tracked yet'); assert.ok(/linkspin\.app\/links/.test(d.parts[1].link));
|
||||
assert.strictEqual(B({ iap: iap({ campaigns: [] }), ls: ls({ campaigns: [] }) }).parts[0].state, 'grey');
|
||||
});
|
||||
await t('next move, in order of what matters most', async () => {
|
||||
assert.strictEqual(B({ refuel: rf({ windowOpen: true, next: { month: 3, single: 20, both: 30 } }) }).next.key, 'refuel');
|
||||
assert.strictEqual(B({ iap: iap({ campaigns: [camp({ status: 'out', delivered: 1000 })] }) }).next.key, 'relaunch');
|
||||
assert.strictEqual(B({ iap: iap({ credits: { available: 20, inCampaigns: 0 }, campaigns: [camp({ delivered: 900, created: NOW - 2 * DAY })] }), ls: ls({ credits: { available: 0, inCampaigns: 0 } }) }).next.key, 'pitstop');
|
||||
assert.strictEqual(B({ iap: iap({ campaigns: [camp({ delivered: 850, created: NOW - 29 * DAY })] }) }).next.key, 'topup');
|
||||
assert.strictEqual(B({ ls: ls({ goalsCount: 0 }) }).next.key, 'tracking');
|
||||
assert.strictEqual(B({ ls: ls({ parts: { bannerSpin: { state: 'grey', note: '' }, spinLink: green, page: green, testing: green } }) }).next.key, 'bannerspin');
|
||||
assert.strictEqual(B({ ls: ls({ parts: { bannerSpin: green, spinLink: green, page: green, testing: { state: 'amber', note: '' } } }) }).next.key, 'testing');
|
||||
const cut = B({ iap: iap({ campaigns: [camp({ id: 1, name: 'Good', delivered: 400, clicks: 40 }), camp({ id: 2, name: 'Weak', delivered: 400, clicks: 4 })] }) });
|
||||
assert.strictEqual(cut.next.key, 'cut'); assert.ok(/"Weak"/.test(cut.next.why));
|
||||
assert.strictEqual(B().next.key, 'cruise');
|
||||
for (const d of [B(), cut]) assert.ok(!/—/.test(JSON.stringify(d)));
|
||||
});
|
||||
await t('facts(): LinkSpin parts and the goals dial count from the Central-time 1st', async () => {
|
||||
const own = 'o@x.test'; const ts = Date.UTC(2026, 10, 1, 4, 30); // 11:30 PM CT Oct 31 = Nov 1 in UTC
|
||||
const conv = [{ owner: own, ts, self: false }, { owner: own, ts: Date.UTC(2026, 10, 3), self: false }, { owner: own, ts: Date.UTC(2026, 10, 4), self: true }];
|
||||
const d = { site: 'linkspin', now: NOW,
|
||||
adminMember: { view: async () => ({ credits: { available: 500, inCampaigns: 250 } }) },
|
||||
ads: { listCampaigns: async () => [{ id: 1, name: 'x', type: 'banner', status: 'active', budget: 1000, spent: 500, clicks: 9, created: NOW - DAY }, { id: 2, house: true, status: 'active', spent: 1 }], loginSlots: async () => ({ free: 1 }) },
|
||||
coach: { clicksSince: async (ids, since) => (assert.deepStrictEqual(ids, [1]), since === NOW - 7 * DAY ? 4 : since === NOW - 14 * DAY ? 10 : -1) },
|
||||
convtrack: { goalsOf: () => [{ px: 'p' }], countSince: (o, since) => conv.filter(c => c.owner === o && c.ts >= since && !c.self).length },
|
||||
bannerspin: { list: async () => [{ paused: false, imps30: 120, banners: [{ active: true, imps30: 80 }, { active: true, imps30: 40 }] }] },
|
||||
rotator: { list: async () => [{ paused: false, hits7: 0, destinations: [{ active: true, hits7: 0 }] }] },
|
||||
pages: { list: async () => [{ status: 'draft', views: 0 }] } };
|
||||
const f = await E.facts(d, own);
|
||||
assert.deepStrictEqual(f.credits, { available: 500, inCampaigns: 250 }); assert.strictEqual(f.campaigns.length, 1); assert.strictEqual(f.clicksWeek, 4); assert.strictEqual(f.clicksPrevWeek, 6); assert.strictEqual(f.loginFree, 1);
|
||||
assert.strictEqual(f.goalsMonth, 1, 'Oct 31 11:30 PM CT is October'); assert.strictEqual(f.conv30, 2);
|
||||
assert.deepStrictEqual([f.parts.bannerSpin.state, f.parts.spinLink.state, f.parts.page.state, f.parts.testing.state], ['green', 'amber', 'amber', 'green']);
|
||||
});
|
||||
await t('the member goal lives with the streak (InstantAdPay); switch off refuses', async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-eng-')); const cfg = { refuelStreak: '1' };
|
||||
const marks = require(path.join(ROOT, 'marks.js'));
|
||||
const R = require(path.join(ROOT, 'refuel.js')); R.init({ dataDir: dir, db: require(path.join(ROOT, 'db.js')), marks, siteConfig: () => cfg, accounts: {}, ads: {}, message: async () => {} });
|
||||
assert.deepStrictEqual(await R.setGoal('g@x.test', 25), { ok: true, goal: 25 });
|
||||
assert.strictEqual((await R.view('g@x.test')).goal, 25);
|
||||
cfg.refuelStreak = '0'; assert.ok((await R.setGoal('g@x.test', 5)).error);
|
||||
});
|
||||
console.log('\n' + (n - fails) + '/' + n + ' passed');
|
||||
process.exit(fails ? 1 : 0);
|
||||
})();
|
||||
Reference in New Issue
Block a user