Skip to content

Commit 56c8bf9

Browse files
committed
Merge branch 'master' into sandrosov/API-3/Extend-API-Info-response--master
# Conflicts: # package-lock.json # package.json
2 parents 68b26aa + 6f75c0a commit 56c8bf9

File tree

5 files changed

+65
-6
lines changed

5 files changed

+65
-6
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 = 'any' | 'all' | 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): Promise<void>
620+
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, execution?: Execution): Promise<void>
619621
}
620622

621623
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "backendless",
3-
"version": "7.3.1",
3+
"version": "7.3.7",
44
"description": "Backendless JavaScript SDK for Node.js and the browser",
55
"browser": "dist/backendless.js",
66
"main": "lib/index.js",

src/automations/index.js

Lines changed: 11 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, execution) {
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,17 @@ export default class Automations {
7171
throw new Error('The "data" argument must be an object.')
7272
}
7373

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: "any", "all" or Execution ID.'
78+
)
79+
}
80+
7481
return this.app.request.post({
75-
url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`,
76-
data: data || {},
82+
url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`,
83+
data : data || {},
84+
query: { execution },
7785
})
7886
}
7987
}

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 execution: 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, execution);
15381539
}
15391540

15401541
function testMessaging() {

test/unit/specs/automations/basic.js

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

99
const FLOW_NAME = 'FlowName'
1010
const FLOW_ID = 'FlowID'
11+
const EXECUTION_ID = 'ExecutionID'
12+
const EXECUTION_ANY = 'any'
13+
const EXECUTION_ALL = 'all'
1114
const TRIGGER_NAME = 'TriggerName'
1215
const TRIGGER_ID = 'TriggerID'
1316

@@ -198,8 +201,15 @@ describe('<Automations> Basic', function() {
198201
it('success', async () => {
199202
const req1 = prepareMockRequest()
200203
const req2 = prepareMockRequest()
204+
const req3 = prepareMockRequest()
205+
const req4 = prepareMockRequest()
206+
const req5 = prepareMockRequest()
207+
201208
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID)
202209
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' })
210+
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)
203213

204214
expect(req1).to.deep.include({
205215
method: 'POST',
@@ -215,6 +225,30 @@ describe('<Automations> Basic', function() {
215225
}
216226
})
217227

228+
expect(req3).to.deep.include({
229+
method: 'POST',
230+
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?execution=ExecutionID`,
231+
body : {
232+
name: 'Nick',
233+
}
234+
})
235+
236+
expect(req4).to.deep.include({
237+
method: 'POST',
238+
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?execution=any`,
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?execution=all`,
247+
body : {
248+
name: 'Nick',
249+
}
250+
})
251+
218252
})
219253

220254
it('fails when flow id is invalid', async () => {
@@ -262,6 +296,20 @@ describe('<Automations> Basic', function() {
262296
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, [])).to.eventually.be.rejectedWith(errorMsg)
263297
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, () => ({}))).to.eventually.be.rejectedWith(errorMsg)
264298
})
299+
300+
it('fails when execution id is invalid', async () => {
301+
// eslint-disable-next-line
302+
const errorMsg = 'The "execution" argument must be a non-empty string and must be one of this values: "any", "all" or Execution ID.'
303+
304+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, null)).to.eventually.be.rejectedWith(errorMsg)
305+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, true)).to.eventually.be.rejectedWith(errorMsg)
306+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, false)).to.eventually.be.rejectedWith(errorMsg)
307+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, 0)).to.eventually.be.rejectedWith(errorMsg)
308+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, 123)).to.eventually.be.rejectedWith(errorMsg)
309+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, [])).to.eventually.be.rejectedWith(errorMsg)
310+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, () => ({}))).to.eventually.be.rejectedWith(errorMsg)
311+
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, {}, '')).to.eventually.be.rejectedWith(errorMsg)
312+
})
265313
})
266314

267315
})

0 commit comments

Comments
 (0)