diff --git a/backendless.d.ts b/backendless.d.ts index 7ccf8a0f..5c797f00 100644 --- a/backendless.d.ts +++ b/backendless.d.ts @@ -615,7 +615,7 @@ declare module Backendless { function activateFlow(flowName: string, initialData?: object): Promise function activateFlowById(flowId: string, initialData?: object): Promise function activateFlowTrigger(flowName: string, triggerName: string, data?: object): Promise - function activateFlowTriggerById(flowId: string, triggerId: string, data?: object): Promise + function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, executionId?: string): Promise } /** diff --git a/src/automations/index.js b/src/automations/index.js index 69caffb2..c4d6feb8 100644 --- a/src/automations/index.js +++ b/src/automations/index.js @@ -58,7 +58,7 @@ export default class Automations { }) } - async activateFlowTriggerById(flowId, triggerId, data) { + async activateFlowTriggerById(flowId, triggerId, data, executionId) { if (!flowId || typeof flowId !== 'string') { throw new Error('The "flowId" argument must be provided and must be a string.') } @@ -71,9 +71,20 @@ export default class Automations { throw new Error('The "data" argument must be an object.') } + if (executionId !== undefined && (typeof executionId !== 'string' || !executionId)) { + throw new Error('The "executionId" argument must be a non-empty string.') + } + + const query = {} + + if (executionId) { + query.executionId = executionId + } + return this.app.request.post({ - url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`, - data: data || {}, + url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`, + data : data || {}, + query: query, }) } } diff --git a/test/tsd.ts b/test/tsd.ts index 329282bd..5b947ea9 100644 --- a/test/tsd.ts +++ b/test/tsd.ts @@ -1529,12 +1529,13 @@ function testAutomations() { const flowId: string = 'id'; const triggerName: string = 'str'; const triggerId: string = 'id'; + const executionId: string = 'id'; let promiseObject: Promise; promiseObject = Backendless.Automations.activateFlow(flowName, obj); promiseObject = Backendless.Automations.activateFlowById(flowId, obj); promiseObject = Backendless.Automations.activateFlowTrigger(flowName, triggerName, obj); - promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj); + promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj, executionId); } function testMessaging() { diff --git a/test/unit/specs/automations/basic.js b/test/unit/specs/automations/basic.js index 7ac7e208..98d2dd4e 100644 --- a/test/unit/specs/automations/basic.js +++ b/test/unit/specs/automations/basic.js @@ -8,6 +8,7 @@ describe(' Basic', function() { const FLOW_NAME = 'FlowName' const FLOW_ID = 'FlowID' + const EXECUTION_ID = 'ExecutionID' const TRIGGER_NAME = 'TriggerName' const TRIGGER_ID = 'TriggerID' @@ -198,8 +199,11 @@ describe(' Basic', function() { it('success', async () => { const req1 = prepareMockRequest() const req2 = prepareMockRequest() + const req3 = prepareMockRequest() + await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID) await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }) + await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }, EXECUTION_ID) expect(req1).to.deep.include({ method: 'POST', @@ -215,6 +219,14 @@ describe(' Basic', function() { } }) + expect(req3).to.deep.include({ + method: 'POST', + path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?executionId=ExecutionID`, + body : { + name: 'Nick', + } + }) + }) it('fails when flow id is invalid', async () => { @@ -262,6 +274,19 @@ describe(' Basic', function() { await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, [])).to.eventually.be.rejectedWith(errorMsg) await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, () => ({}))).to.eventually.be.rejectedWith(errorMsg) }) + + it('fails when execution id is invalid', async () => { + const errorMsg = 'The "executionId" argument must be a non-empty string.' + + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, null)).to.eventually.be.rejectedWith(errorMsg) + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, true)).to.eventually.be.rejectedWith(errorMsg) + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, false)).to.eventually.be.rejectedWith(errorMsg) + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, 0)).to.eventually.be.rejectedWith(errorMsg) + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, 123)).to.eventually.be.rejectedWith(errorMsg) + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, [])).to.eventually.be.rejectedWith(errorMsg) + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, () => ({}))).to.eventually.be.rejectedWith(errorMsg) + await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, '')).to.eventually.be.rejectedWith(errorMsg) + }) }) })