diff --git a/backendless.d.ts b/backendless.d.ts index 5c797f00..a7463b49 100644 --- a/backendless.d.ts +++ b/backendless.d.ts @@ -612,10 +612,12 @@ declare module Backendless { * @type: Function */ + type Execution = 'activateAny' | 'activateAll' | string + 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, executionId?: string): Promise + function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, execution?: Execution): Promise } /** diff --git a/src/automations/index.js b/src/automations/index.js index c4d6feb8..6437dff8 100644 --- a/src/automations/index.js +++ b/src/automations/index.js @@ -58,7 +58,7 @@ export default class Automations { }) } - async activateFlowTriggerById(flowId, triggerId, data, executionId) { + async activateFlowTriggerById(flowId, triggerId, data, execution) { if (!flowId || typeof flowId !== 'string') { throw new Error('The "flowId" argument must be provided and must be a string.') } @@ -71,14 +71,24 @@ 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.') + if (execution !== undefined && (typeof execution !== 'string' || !execution)) { + throw new Error( + // eslint-disable-next-line + 'The "execution" argument must be a non-empty string and must be one of this values: "activateAny", "activateAll" or Execution ID.' + ) } const query = {} - if (executionId) { - query.executionId = executionId + switch (execution) { + case 'activateAny': + query.activateAny = true + break + case 'activateAll': + query.activateAll = true + break + default: + query.executionId = execution } return this.app.request.post({ diff --git a/test/tsd.ts b/test/tsd.ts index 5b947ea9..8163224a 100644 --- a/test/tsd.ts +++ b/test/tsd.ts @@ -1529,13 +1529,13 @@ function testAutomations() { const flowId: string = 'id'; const triggerName: string = 'str'; const triggerId: string = 'id'; - const executionId: string = 'id'; + const execution: 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, executionId); + promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj, execution); } function testMessaging() { diff --git a/test/unit/specs/automations/basic.js b/test/unit/specs/automations/basic.js index 98d2dd4e..cb05d039 100644 --- a/test/unit/specs/automations/basic.js +++ b/test/unit/specs/automations/basic.js @@ -9,6 +9,8 @@ describe(' Basic', function() { const FLOW_NAME = 'FlowName' const FLOW_ID = 'FlowID' const EXECUTION_ID = 'ExecutionID' + const EXECUTION_ANY = 'activateAny' + const EXECUTION_ALL = 'activateAll' const TRIGGER_NAME = 'TriggerName' const TRIGGER_ID = 'TriggerID' @@ -200,10 +202,14 @@ describe(' Basic', function() { const req1 = prepareMockRequest() const req2 = prepareMockRequest() const req3 = prepareMockRequest() + const req4 = prepareMockRequest() + const req5 = 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) + await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }, EXECUTION_ANY) + await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }, EXECUTION_ALL) expect(req1).to.deep.include({ method: 'POST', @@ -227,6 +233,22 @@ describe(' Basic', function() { } }) + expect(req4).to.deep.include({ + method: 'POST', + path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?activateAny=true`, + body : { + name: 'Nick', + } + }) + + expect(req5).to.deep.include({ + method: 'POST', + path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?activateAll=true`, + body : { + name: 'Nick', + } + }) + }) it('fails when flow id is invalid', async () => { @@ -276,7 +298,8 @@ describe(' Basic', function() { }) it('fails when execution id is invalid', async () => { - const errorMsg = 'The "executionId" argument must be a non-empty string.' + // eslint-disable-next-line + const errorMsg = 'The "execution" argument must be a non-empty string and must be one of this values: "activateAny", "activateAll" or Execution ID.' 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)