diff --git a/packages/backend/src/models/step.js b/packages/backend/src/models/step.js index 85f98a1d..0e7b6105 100644 --- a/packages/backend/src/models/step.js +++ b/packages/backend/src/models/step.js @@ -93,6 +93,14 @@ class Step extends Base { return `${appConfig.baseUrl}/apps/${this.appKey}/assets/favicon.svg`; } + get isTrigger() { + return this.type === 'trigger'; + } + + get isAction() { + return this.type === 'action'; + } + async computeWebhookPath() { if (this.type === 'action') return null; @@ -135,24 +143,6 @@ class Step extends Base { return webhookUrl; } - async $afterInsert(queryContext) { - await super.$afterInsert(queryContext); - Telemetry.stepCreated(this); - } - - async $afterUpdate(opt, queryContext) { - await super.$afterUpdate(opt, queryContext); - Telemetry.stepUpdated(this); - } - - get isTrigger() { - return this.type === 'trigger'; - } - - get isAction() { - return this.type === 'action'; - } - async getApp() { if (!this.appKey) return null; @@ -367,6 +357,16 @@ class Step extends Base { return updatedStep; } + + async $afterInsert(queryContext) { + await super.$afterInsert(queryContext); + Telemetry.stepCreated(this); + } + + async $afterUpdate(opt, queryContext) { + await super.$afterUpdate(opt, queryContext); + Telemetry.stepUpdated(this); + } } export default Step; diff --git a/packages/backend/src/models/step.test.js b/packages/backend/src/models/step.test.js index 80bd5bdf..e812ca02 100644 --- a/packages/backend/src/models/step.test.js +++ b/packages/backend/src/models/step.test.js @@ -126,4 +126,43 @@ describe('Step model', () => { expect(step.iconUrl).toBe(null); }); }); + + it('isTrigger should return true when step type is trigger', () => { + const step = new Step(); + step.type = 'trigger'; + + expect(step.isTrigger).toBe(true); + }); + + it('isAction should return true when step type is action', () => { + const step = new Step(); + step.type = 'action'; + + expect(step.isAction).toBe(true); + }); + + describe.todo('computeWebhookPath'); + + describe('getWebhookUrl', () => { + it('should return absolute webhook URL when step type is trigger', async () => { + const step = new Step(); + step.type = 'trigger'; + + vi.spyOn(step, 'computeWebhookPath').mockResolvedValue('/webhook-path'); + vi.spyOn(appConfig, 'webhookUrl', 'get').mockReturnValue( + 'https://automatisch.io' + ); + + expect(await step.getWebhookUrl()).toBe( + 'https://automatisch.io/webhook-path' + ); + }); + + it('should return undefined when step type is action', async () => { + const step = new Step(); + step.type = 'action'; + + expect(await step.getWebhookUrl()).toBe(undefined); + }); + }); });