mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
inngest went from 3 to 4 in the version sweep. 4's createFunction takes the
triggers inside its options and the handler second, and throws when handed
the old three arguments. With the Inngest provider selected, the first
defineJob threw "createFunction expected a handler function as the second
argument", so no job could be registered. The trigger now sits in the
options.
Starting a job as a step of another sent `{ ...options, timestamp }`, whose
payload was not the event's `data`, so the job it started parsed an empty
event. inngest 3's types let that through and 4's refuse it. Both ways of
starting a job now send toInngestEvent(options): the payload as `data`, the
timestamp as `ts`, as triggerJob already did. inngest.test.ts holds the
mapping; a run of defineJob against the installed inngest registers each
job with its event or cron trigger and a handler.
Co-authored-by: Hanzo Dev <[email protected]>
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
/**
|
|
* Starting a job on Inngest.
|
|
*
|
|
* A job is triggered with a name, a payload and optionally an id and a
|
|
* timestamp. Inngest starts a function from an event, and an event carries
|
|
* its payload as `data` and its time as `ts`. Both ways a job is started —
|
|
* from outside a run and as a step inside one — send the same event.
|
|
*
|
|
* Run: npx tsx --test packages/lib/__tests__/inngest.test.ts
|
|
*/
|
|
import assert from 'node:assert/strict';
|
|
import { describe, test } from 'node:test';
|
|
|
|
import { toInngestEvent } from '../jobs/client/inngest';
|
|
|
|
describe('toInngestEvent', () => {
|
|
test('carries the payload as data and the timestamp as ts', () => {
|
|
assert.deepEqual(
|
|
toInngestEvent({
|
|
id: 'run-1',
|
|
name: 'send.signing.requested.email',
|
|
payload: { envelopeId: 'envelope_1' },
|
|
timestamp: 1_760_000_000_000,
|
|
}),
|
|
{
|
|
id: 'run-1',
|
|
name: 'send.signing.requested.email',
|
|
data: { envelopeId: 'envelope_1' },
|
|
ts: 1_760_000_000_000,
|
|
},
|
|
);
|
|
});
|
|
|
|
test('leaves the id and the time to Inngest when the trigger names neither', () => {
|
|
const event = toInngestEvent({ name: 'internal.seal-document', payload: { documentId: 1 } });
|
|
|
|
assert.equal(event.id, undefined);
|
|
assert.equal(event.ts, undefined);
|
|
assert.deepEqual(event.data, { documentId: 1 });
|
|
});
|
|
});
|