import { createMockContext } from '@ekanos/sdk/testing';
const ctx = createMockContext({
integration: { slug: 'acme-payments' },
storageSchemas: myStorage,
egress: integration.egress,
storage: {
account: {
settings: { merchantId: 'mrc_4820193' },
},
},
secrets: {
account: {
acme_api_key: 'acme_test_9f2c41ab', // Writable
},
admin: {
platform_key: 'not-writable', // Throws on write
},
},
fetchHandlers: [
{
match: 'https://api.acme.example', // String matches URLs that start with it
respond: () => Response.json({ payments: [] }),
},
{
match: /^https:\/\/api\.acme\.example\/v[0-9]+\/.*/, // RegExp tested against full URL
respond: (request) => Response.json({ url: request.url }), // receives a Request
},
],
});
const result = await integration.tools[0].run(ctx, {});
// Handlers are tried in order and the first match wins. An allowed call
// that matches nothing resolves 200 {}.
// Query what happened
expect(ctx.fetchCalls).toHaveLength(1); // { url, init?, denied }[]
expect(ctx.logs.at(-1)?.level).toBe('info'); // { level, context, message }[]
expect(ctx.dumpStorage().account).toMatchObject({/* … */});