From 57137fe904445d45b2a79179692079eb5be3a2f3 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Tue, 21 Jan 2025 13:10:18 +0100 Subject: [PATCH] test: Add tests for updateWebhookUrl method of step --- packages/backend/src/models/step.test.js | 41 +++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/models/step.test.js b/packages/backend/src/models/step.test.js index 37fbebca..56607201 100644 --- a/packages/backend/src/models/step.test.js +++ b/packages/backend/src/models/step.test.js @@ -369,7 +369,46 @@ describe('Step model', () => { it.todo('getSetupAndDynamicFields'); it.todo('createDynamicFields'); it.todo('createDynamicData'); - it.todo('updateWebhookUrl'); + + describe('updateWebhookUrl', () => { + it('should do nothing if step is an action', async () => { + const step = new Step(); + step.type = 'action'; + + await step.updateWebhookUrl(); + + expect(step.webhookUrl).toBeNull(); + }); + + it('should set webhookPath if step is a trigger', async () => { + const step = await createStep({ + type: 'trigger', + }); + + vi.spyOn(Step.prototype, 'computeWebhookPath').mockResolvedValue( + '/webhooks/flows/flow-id' + ); + + const newStep = await step.updateWebhookUrl(); + + expect(step.webhookPath).toBe('/webhooks/flows/flow-id'); + expect(newStep).toBe(step); + }); + + it('should return step itself after the update of webhook path', async () => { + const step = await createStep({ + type: 'trigger', + }); + + vi.spyOn(Step.prototype, 'computeWebhookPath').mockResolvedValue( + '/webhooks/flows/flow-id' + ); + + const updatedStep = await step.updateWebhookUrl(); + + expect(updatedStep).toStrictEqual(step); + }); + }); describe('delete', () => { it('should delete the step and align the positions', async () => {