From c310e8d152f9270bf4495ddaabecef318ca0fe44 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Mon, 4 Nov 2024 14:15:26 +0000 Subject: [PATCH] test(step): write tests for getTriggerCommand and getActionCommand --- packages/backend/src/models/step.test.js | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/backend/src/models/step.test.js b/packages/backend/src/models/step.test.js index 5c234716..43876d4b 100644 --- a/packages/backend/src/models/step.test.js +++ b/packages/backend/src/models/step.test.js @@ -218,4 +218,50 @@ describe('Step model', () => { expect(await secondStep.getNextStep()).toStrictEqual(thirdStep); }); + + describe('getTriggerCommand', () => { + it('should return trigger comamand when app key and key are defined in trigger step', async () => { + const step = new Step(); + step.type = 'trigger'; + step.appKey = 'webhook'; + step.key = 'catchRawWebhook'; + + const findOneByKeySpy = vi.spyOn(App, 'findOneByKey'); + const triggerCommand = await step.getTriggerCommand(); + + expect(findOneByKeySpy).toHaveBeenCalledWith(step.appKey); + expect(triggerCommand.key).toBe(step.key); + }); + + it('should return null when key is not defined', async () => { + const step = new Step(); + step.type = 'trigger'; + step.appKey = 'webhook'; + + expect(await step.getTriggerCommand()).toBe(null); + }); + }); + + describe('getActionCommand', () => { + it('should return action comamand when app key and key are defined in action step', async () => { + const step = new Step(); + step.type = 'action'; + step.appKey = 'ntfy'; + step.key = 'sendMessage'; + + const findOneByKeySpy = vi.spyOn(App, 'findOneByKey'); + const actionCommand = await step.getActionCommand(); + + expect(findOneByKeySpy).toHaveBeenCalledWith(step.appKey); + expect(actionCommand.key).toBe(step.key); + }); + + it('should return null when key is not defined', async () => { + const step = new Step(); + step.type = 'action'; + step.appKey = 'ntfy'; + + expect(await step.getActionCommand()).toBe(null); + }); + }); });