Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e107975

Browse files
Add executions modes to activateFlowTriggerById (#252)
* Add executions modes to activateFlowTriggerById
1 parent 8fca513 commit e107975

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

‎backendless.d.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,12 @@ declare module Backendless {
612612
* @type: Function
613613
*/
614614

615+
type Execution = 'activateAny' | 'activateAll' | string
616+
615617
function activateFlow(flowName: string, initialData?: object): Promise<void>
616618
function activateFlowById(flowId: string, initialData?: object): Promise<void>
617619
function activateFlowTrigger(flowName: string, triggerName: string, data?: object): Promise<void>
618-
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, executionId?: string): Promise<void>
620+
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, execution?: Execution): Promise<void>
619621
}
620622

621623
/**

‎src/automations/index.js‎

Lines changed: 15 additions & 5 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, executionId) {
61+
async activateFlowTriggerById(flowId, triggerId, data, execution) {
6262
if (!flowId || typeof flowId !== 'string') {
6363
throw new Error('The "flowId" argument must be provided and must be a string.')
6464
}
@@ -71,14 +71,24 @@ 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.')
74+
if (execution !== undefined && (typeof execution !== 'string' || !execution)) {
75+
throw new Error(
76+
// eslint-disable-next-line
77+
'The "execution" argument must be a non-empty string and must be one of this values: "activateAny", "activateAll" or Execution ID.'
78+
)
7679
}
7780

7881
const query = {}
7982

80-
if (executionId) {
81-
query.executionId = executionId
83+
switch (execution) {
84+
case 'activateAny':
85+
query.activateAny = true
86+
break
87+
case 'activateAll':
88+
query.activateAll = true
89+
break
90+
default:
91+
query.executionId = execution
8292
}
8393

8494
return this.app.request.post({

‎test/tsd.ts‎

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

15351535
promiseObject = Backendless.Automations.activateFlow(flowName, obj);
15361536
promiseObject = Backendless.Automations.activateFlowById(flowId, obj);
15371537
promiseObject = Backendless.Automations.activateFlowTrigger(flowName, triggerName, obj);
1538-
promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj, executionId);
1538+
promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj, execution);
15391539
}
15401540

15411541
function testMessaging() {

‎test/unit/specs/automations/basic.js‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ describe('<Automations> Basic', function() {
99
const FLOW_NAME = 'FlowName'
1010
const FLOW_ID = 'FlowID'
1111
const EXECUTION_ID = 'ExecutionID'
12+
const EXECUTION_ANY = 'activateAny'
13+
const EXECUTION_ALL = 'activateAll'
1214
const TRIGGER_NAME = 'TriggerName'
1315
const TRIGGER_ID = 'TriggerID'
1416

@@ -200,10 +202,14 @@ describe('<Automations> Basic', function() {
200202
const req1 = prepareMockRequest()
201203
const req2 = prepareMockRequest()
202204
const req3 = prepareMockRequest()
205+
const req4 = prepareMockRequest()
206+
const req5 = prepareMockRequest()
203207

204208
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID)
205209
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' })
206210
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }, EXECUTION_ID)
211+
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }, EXECUTION_ANY)
212+
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' }, EXECUTION_ALL)
207213

208214
expect(req1).to.deep.include({
209215
method: 'POST',
@@ -227,6 +233,22 @@ describe('<Automations> Basic', function() {
227233
}
228234
})
229235

236+
expect(req4).to.deep.include({
237+
method: 'POST',
238+
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?activateAny=true`,
239+
body : {
240+
name: 'Nick',
241+
}
242+
})
243+
244+
expect(req5).to.deep.include({
245+
method: 'POST',
246+
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?activateAll=true`,
247+
body : {
248+
name: 'Nick',
249+
}
250+
})
251+
230252
})
231253

232254
it('fails when flow id is invalid', async () => {
@@ -276,7 +298,8 @@ describe('<Automations> Basic', function() {
276298
})
277299

278300
it('fails when execution id is invalid', async () => {
279-
const errorMsg = 'The "executionId" argument must be a non-empty string.'
301+
// eslint-disable-next-line
302+
const errorMsg = 'The "execution" argument must be a non-empty string and must be one of this values: "activateAny", "activateAll" or Execution ID.'
280303

281304
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, null)).to.eventually.be.rejectedWith(errorMsg)
282305
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, true)).to.eventually.be.rejectedWith(errorMsg)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /