Skip to content

Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.

2.2 KB
Raw Blame
const {test}=require('node:test');const assert=require('node:assert/strict');const {spawnSync}=require('node:child_process');const path=require('node:path');const cli=path.resolve(__dirname,'../../tools/clis/resend.js')
const resources=['emails','domains','broadcasts','segments','templates','api-keys']
function run(args,network=true){const script=`global.fetch=async(url,options)=>{if(!${network})throw new Error('Unexpected network');return{status:200,text:async()=>JSON.stringify({url,method:options.method,has_more:false,data:[]})}};process.argv=['node',${JSON.stringify(cli)},...${JSON.stringify(args)}];require(${JSON.stringify(cli)})`;return spawnSync(process.execPath,['-e',script],{encoding:'utf8',timeout:5000,env:{RESEND_API_KEY:'fixture-key',PATH:process.env.PATH}})}
function result(r){assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)}
test('all supported collection commands can reach subsequent and previous pages',()=>{for(const resource of resources){for(const direction of ['after','before']){const r=result(run([resource,'list','--'+direction,'cursor/+id','--limit','100']));const u=new URL(r.url);assert.equal(u.searchParams.get(direction),'cursor/+id');assert.equal(u.searchParams.get('limit'),'100');assert.equal(r.method,'GET')}}})
test('default requests retain omitted pagination and preserve provider response',()=>{for(const resource of resources){const r=result(run([resource,'list']));assert.equal(new URL(r.url).search,'');assert.equal(r.has_more,false);assert.deepEqual(r.data,[])}})
test('ambiguous cursors and malformed limits are rejected before fetch',()=>{for(const resource of resources){for(const options of [['--after','a','--before','b'],['--after'],['--before',''],['--limit'],['--limit','0'],['--limit','101'],['--limit','1.5']]){const r=run([resource,'list',...options],false);assert.equal(r.status,1,resource+' '+options);assert.doesNotMatch(r.stderr,/Unexpected network/)}}})
test('dry runs show cursor encoding and redact authentication',()=>{const r=result(run(['emails','list','--after','cursor/+id','--dry-run'],false));assert.equal(new URL(r.url).searchParams.get('after'),'cursor/+id');assert.equal(JSON.stringify(r).includes('fixture-key'),false)})