master-zapier-plan-draft/packages/verae-activate/test/add_numbers.test.js
George Lambert b814501441 Milestone 1: Add Numbers Zapier app, /v1/add, developer setup guide
packages/verae-activate is pushable with zapier-platform 19.1.0: local
Add Numbers (number1+number2=sum) needs no hosted API. zapier-platform
validate is clean (0 warnings). zappier POST /v1/add is a free metered
endpoint for the optional hosted path.

Tests: verae-activate 7/7, zappier 176/176, verae-zapier 5/5, middleware
gate 1 11/11. Morning steps: docs/04-activate/SETUP-ZAPIER-DEVELOPER.md

Learned: perform runs on Zapier cloud so arithmetic needs no public URL;
CLI and zapier-platform-core majors must match; do not mix zapier-sdk.
2026-09-09 02:41:34 -04:00

84 lines
2.9 KiB
JavaScript

/**
* Activate-now tests: Add Numbers local + hosted paths.
*/
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const App = require('../index');
const addNumbers = require('../creates/add_numbers');
const authentication = require('../authentication');
describe('verae-activate app', () => {
it('exports Add Numbers create and custom auth', () => {
assert.equal(authentication.type, 'custom');
assert.ok(App.creates.add_numbers);
assert.equal(addNumbers.key, 'add_numbers');
assert.ok(addNumbers.operation.inputFields.some((f) => f.key === 'number1'));
assert.ok(addNumbers.operation.inputFields.some((f) => f.key === 'number2'));
});
it('adds two numbers locally with no API', async () => {
const z = { request: async () => { throw new Error('should not HTTP'); } };
const result = await addNumbers.operation.perform(z, {
inputData: { number1: 2, number2: 3 },
authData: {},
});
assert.deepEqual(result, { number1: 2, number2: 3, sum: 5, mode: 'local' });
});
it('coerces numeric strings', async () => {
const result = await addNumbers.operation.perform({}, {
inputData: { number1: '10.5', number2: '-0.5' },
authData: {},
});
assert.equal(result.sum, 10);
assert.equal(result.mode, 'local');
});
it('rejects non-finite number1', async () => {
await assert.rejects(
() => addNumbers.operation.perform({}, { inputData: { number1: 'x', number2: 1 }, authData: {} }),
/number1 must be a finite number/,
);
});
it('POSTs to hosted /v1/add when api_base and api_key are set', async () => {
const calls = [];
const z = {
request: async (opts) => {
calls.push(opts);
return { data: { number1: 1, number2: 4, sum: 5, quote: { totalCents: 0 } } };
},
};
const result = await addNumbers.operation.perform(z, {
inputData: { number1: 1, number2: 4 },
authData: { api_base: 'https://edge.example.com/', api_key: 'key-ada' },
});
assert.equal(calls[0].method, 'POST');
assert.equal(calls[0].url, 'https://edge.example.com/v1/add');
assert.equal(calls[0].headers['x-api-key'], 'key-ada');
assert.deepEqual(calls[0].body, { number1: 1, number2: 4 });
assert.equal(result.mode, 'hosted');
assert.equal(result.sum, 5);
});
it('auth test is local when fields empty', async () => {
const out = await authentication.test({ request: async () => ({ data: {} }) }, { authData: {} });
assert.equal(out.ok, true);
assert.equal(out.mode, 'local');
});
it('auth test hits /v1/status when hosted', async () => {
const z = {
request: async (opts) => {
assert.equal(opts.url, 'https://edge.example.com/v1/status');
return { data: { status: 'ok' } };
},
};
const out = await authentication.test(z, {
authData: { api_base: 'https://edge.example.com', api_key: 'k' },
});
assert.equal(out.mode, 'hosted');
});
});