Skip to content

Commit 3671632

Browse files
Automations. Support executionID for activateFlowTriggerById (#251)
* Automations. Support executionID for activateFlowTriggerById
1 parent b5e99a6 commit 3671632

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

backendless.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ declare module Backendless {
615615
function activateFlow(flowName: string, initialData?: object): Promise<void>
616616
function activateFlowById(flowId: string, initialData?: object): Promise<void>
617617
function activateFlowTrigger(flowName: string, triggerName: string, data?: object): Promise<void>
618-
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object): Promise<void>
618+
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, executionId?: string): Promise<void>
619619
}
620620

621621
/**

src/automations/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default class Automations {
5858
})
5959
}
6060

61-
async activateFlowTriggerById(flowId, triggerId, data) {
61+
async activateFlowTriggerById(flowId, triggerId, data, executionId) {
6262
if (!flowId || typeof flowId !== 'string') {
6363
throw new Error('The "flowId" argument must be provided and must be a string.')
6464
}
@@ -71,9 +71,20 @@ export default class Automations {
7171
throw new Error('The "data" argument must be an object.')
7272
}
7373

74+
if (executionId !== undefined && (typeof executionId !== 'string' || !executionId)) {
75+
throw new Error('The "executionId" argument must be a non-empty string.')
76+
}
77+
78+
const query = {}
79+
80+
if (executionId) {
81+
query.executionId = executionId
82+
}
83+
7484
return this.app.request.post({
75-
url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`,
76-
data: data || {},
85+
url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`,
86+
data : data || {},
87+
query: query,
7788
})
7889
}
7990
}

test/tsd.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,12 +1529,13 @@ function testAutomations() {
15291529
const flowId: string = 'id';
15301530
const triggerName: string = 'str';
15311531
const triggerId: string = 'id';
1532+
const executionId: string = 'id';
15321533
let promiseObject: Promise<void>;
15331534

15341535
promiseObject = Backendless.Automations.activateFlow(flowName, obj);
15351536
promiseObject = Backendless.Automations.activateFlowById(flowId, obj);
15361537
promiseObject = Backendless.Automations.activateFlowTrigger(flowName, triggerName, obj);
1537-
promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj);
1538+
promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj, executionId);
15381539
}
15391540

15401541
function testMessaging() {

test/unit/specs/automations/basic.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('<Automations> Basic', function() {
88

99
const FLOW_NAME = 'FlowName'
1010
const FLOW_ID = 'FlowID'
11+
const EXECUTION_ID = 'ExecutionID'
1112
const TRIGGER_NAME = 'TriggerName'
1213
const TRIGGER_ID = 'TriggerID'
1314

@@ -198,8 +199,11 @@ describe('<Automations> Basic', function() {
198199
it('success', async () => {
199200
const req1 = prepareMockRequest()
200201
const req2 = prepareMockRequest()
202+
const req3 = prepareMockRequest()
203+
201204
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID)
202205
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' })
206+
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }, EXECUTION_ID)
203207

204208
expect(req1).to.deep.include({
205209
method: 'POST',
@@ -215,6 +219,14 @@ describe('<Automations> Basic', function() {
215219
}
216220
})
217221

222+
expect(req3).to.deep.include({
223+
method: 'POST',
224+
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?executionId=ExecutionID`,
225+
body : {
226+
name: 'Nick',
227+
}
228+
})
229+
218230
})
219231

220232
it('fails when flow id is invalid', async () => {
@@ -262,6 +274,19 @@ describe('<Automations> Basic', function() {
262274
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, [])).to.eventually.be.rejectedWith(errorMsg)
263275
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, () => ({}))).to.eventually.be.rejectedWith(errorMsg)
264276
})
277+
278+
it('fails when execution id is invalid', async () => {
279+
const errorMsg = 'The "executionId" argument must be a non-empty string.'
280+
281+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, null)).to.eventually.be.rejectedWith(errorMsg)
282+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, true)).to.eventually.be.rejectedWith(errorMsg)
283+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, false)).to.eventually.be.rejectedWith(errorMsg)
284+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, 0)).to.eventually.be.rejectedWith(errorMsg)
285+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, 123)).to.eventually.be.rejectedWith(errorMsg)
286+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, [])).to.eventually.be.rejectedWith(errorMsg)
287+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, () => ({}))).to.eventually.be.rejectedWith(errorMsg)
288+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, '')).to.eventually.be.rejectedWith(errorMsg)
289+
})
265290
})
266291

267292
})

0 commit comments

Comments
 (0)