diff --git a/packages/deploy/src/stateTransform.ts b/packages/deploy/src/stateTransform.ts index 474b8a148..9ef816ce2 100644 --- a/packages/deploy/src/stateTransform.ts +++ b/packages/deploy/src/stateTransform.ts @@ -164,6 +164,9 @@ function mergeTriggers( if (specTrigger.type === 'webhook' && specTrigger.webhook_reply) { trigger.webhook_reply = specTrigger.webhook_reply; } + if (specTrigger.type === 'webhook' && specTrigger.webhook_response) { + trigger.webhook_response = specTrigger.webhook_response; + } if (specTrigger.type === 'cron') { trigger.cron_expression = specTrigger.cron_expression; @@ -202,6 +205,9 @@ function mergeTriggers( if (specTrigger!.type === 'webhook' && specTrigger!.webhook_reply) { trigger.webhook_reply = specTrigger!.webhook_reply; } + if (specTrigger!.type === 'webhook' && specTrigger!.webhook_response) { + trigger.webhook_response = specTrigger!.webhook_response; + } if (specTrigger!.type === 'cron') { trigger.cron_expression = specTrigger!.cron_expression; diff --git a/packages/deploy/src/types.ts b/packages/deploy/src/types.ts index 2cba41176..34640c486 100644 --- a/packages/deploy/src/types.ts +++ b/packages/deploy/src/types.ts @@ -38,6 +38,11 @@ export type SpecKafkaConfiguration = { connect_timeout: number; }; +export type WebhookResponse = { + error_code: number | null; + success_code: number | null; +}; + export type WebhookReply = 'before_start' | 'after_completion'; export type SpecTrigger = { @@ -45,6 +50,7 @@ export type SpecTrigger = { cron_expression?: string; cron_cursor_job?: string; webhook_reply?: WebhookReply; + webhook_response?: WebhookResponse | null; enabled?: boolean; kafka_configuration?: SpecKafkaConfiguration; }; @@ -55,6 +61,7 @@ export type StateTrigger = { cron_expression?: string; cron_cursor_job_id?: string | null; webhook_reply?: WebhookReply; + webhook_response?: WebhookResponse | null; delete?: boolean; enabled?: boolean; kafka_configuration?: StateKafkaConfiguration; diff --git a/packages/deploy/test/stateTransform.test.ts b/packages/deploy/test/stateTransform.test.ts index 4d6b91e4e..e161f44e4 100644 --- a/packages/deploy/test/stateTransform.test.ts +++ b/packages/deploy/test/stateTransform.test.ts @@ -639,6 +639,125 @@ test('toNextState omits webhook_reply on existing trigger when not specified', ( t.false('webhook_reply' in result.workflows.w.triggers.t); }); +test('toNextState sets webhook_response when specified', (t) => { + const state = { workflows: {} }; + const spec = { + name: 'my project', + workflows: { + w: { + name: 'workflow', + jobs: {}, + triggers: { + t: { + type: 'webhook', + webhook_response: { success_code: 200, error_code: 400 }, + }, + }, + edges: {}, + }, + }, + }; + + const result = mergeSpecIntoState(state, spec); + t.deepEqual(result.workflows.w.triggers.t.webhook_response, { + success_code: 200, + error_code: 400, + }); +}); + +test('toNextState omits webhook_response when not specified', (t) => { + const state = { workflows: {} }; + const spec = { + name: 'my project', + workflows: { + w: { + name: 'workflow', + jobs: {}, + triggers: { + t: { type: 'webhook' }, + }, + edges: {}, + }, + }, + }; + + const result = mergeSpecIntoState(state, spec); + t.false('webhook_response' in result.workflows.w.triggers.t); +}); + +test('toNextState sets webhook_response on existing trigger', (t) => { + const triggerId = 'aaa-bbb-ccc'; + const state = { + workflows: { + w: { + id: 'wf-1', + name: 'workflow', + jobs: {}, + triggers: { + t: { id: triggerId, type: 'webhook', enabled: true }, + }, + edges: {}, + }, + }, + }; + const spec = { + name: 'my project', + workflows: { + w: { + name: 'workflow', + jobs: {}, + triggers: { + t: { + type: 'webhook', + webhook_response: { success_code: 201, error_code: 500 }, + }, + }, + edges: {}, + }, + }, + }; + + const result = mergeSpecIntoState(state, spec); + t.is(result.workflows.w.triggers.t.id, triggerId); + t.deepEqual(result.workflows.w.triggers.t.webhook_response, { + success_code: 201, + error_code: 500, + }); +}); + +test('toNextState omits webhook_response on existing trigger when not specified', (t) => { + const triggerId = 'aaa-bbb-ccc'; + const state = { + workflows: { + w: { + id: 'wf-1', + name: 'workflow', + jobs: {}, + triggers: { + t: { id: triggerId, type: 'webhook', enabled: true }, + }, + edges: {}, + }, + }, + }; + const spec = { + name: 'my project', + workflows: { + w: { + name: 'workflow', + jobs: {}, + triggers: { + t: { type: 'webhook' }, + }, + edges: {}, + }, + }, + }; + + const result = mergeSpecIntoState(state, spec); + t.false('webhook_response' in result.workflows.w.triggers.t); +}); + test('toNextState sets cron_cursor_job_id on existing trigger', (t) => { const triggerId = 'aaa-bbb-ccc'; const jobId = 'job-uuid-111';