Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
fix(rewardful): update the affiliate selected by the CLI
Rudy Celekli80883556554d
diff --git a/tests/rewardful-update-id.test.cjs b/tests/rewardful-update-id.test.cjsnew file mode 100644index 0000000..17bd52f--- /dev/null+++ b/tests/rewardful-update-id.test.cjs@@ -0,0 +1,39 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')+function run(vendor, args, fetch = true) {+ const cli = path.resolve(__dirname, `../tools/clis/${vendor}.js`)+ const source = `global.fetch = async (url, options) => {+ if (!${fetch}) throw new Error('Unexpected network request');+ return { status: 200, text: async () => JSON.stringify({ url, method: options.method, body: options.body ? JSON.parse(options.body) : null }) };+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ return spawnSync(process.execPath, ['-e', source], { encoding: 'utf8', timeout: 5000, env: {+ ...process.env, REWARDFUL_API_KEY: 'fake-key', RESEND_API_KEY: 'fake-key', POSTMARK_API_KEY: 'fake-key', BEEHIIV_API_KEY: 'fake-key', KLAVIYO_API_KEY: 'fake-key',+ } })+}+function output(result) { assert.equal(result.status, 0, result.stderr); return JSON.parse(result.stdout) }++test('positional affiliate selects the update route and payout data', () => {+ const result = output(run('rewardful', ['affiliates', 'update', 'affiliate123', '--paypal-email', '[email protected]']))+ assert.equal(result.url, 'https://api.getrewardful.com/v1/affiliates/affiliate123')+ assert.equal(result.method, 'PUT')+ assert.deepEqual(result.body, { paypal_email: '[email protected]' })+})+test('documented id flag also selects the affiliate', () => {+ const result = output(run('rewardful', ['affiliates', 'update', '--id', 'affiliate123', '--first-name', 'Zoë']))+ assert.equal(result.url.endsWith('/affiliates/affiliate123'), true)+ assert.deepEqual(result.body, { first_name: 'Zoë' })+})+test('conflicting identifiers cannot silently update another affiliate', () => {+ assert.match(output(run('rewardful', ['affiliates', 'update', 'affiliate123', '--id', 'other456', '--first-name', 'Zoë'], false)).error, /must match/)+})+test('missing identifier stops before fetching', () => {+ assert.match(output(run('rewardful', ['affiliates', 'update', '--first-name', 'Zoë'], false)).error, /Affiliate ID/)+})+test('update dry run uses the selected affiliate with masked authorization', () => {+ const result = output(run('rewardful', ['affiliates', 'update', 'affiliate123', '--first-name', 'Zoë', '--dry-run'], false))+ assert.equal(result.url.endsWith('/affiliates/affiliate123'), true)+ assert.equal(result.headers.Authorization, '***')+ assert.equal(JSON.stringify(result).includes('fake-key'), false)+})diff --git a/tools/clis/rewardful.js b/tools/clis/rewardful.jsindex dbaf01e..8970718 100755--- a/tools/clis/rewardful.js+++ b/tools/clis/rewardful.js@@ -75,12 +75,16 @@ async function main() {break}case 'update': {- if (!rest[0]) { result = { error: 'Affiliate ID required' }; break }+ const affiliateId = rest[0] || args.id+ if (!affiliateId) { result = { error: 'Affiliate ID required (positional arg or --id)' }; break }+ if (rest[0] && args.id && rest[0] !== args.id) {+ result = { error: 'Positional affiliate ID and --id must match' }; break+ }const body = {}if (args['first-name']) body.first_name = args['first-name']if (args['last-name']) body.last_name = args['last-name']if (args['paypal-email']) body.paypal_email = args['paypal-email']- result = await api('PUT', `/affiliates/${args.id}`, body)+ result = await api('PUT', `/affiliates/${affiliateId}`, body)break}default: