Skip to content

Commit

Permalink
Automations. Support executionID for activateFlowTriggerById (#251)
Browse files Browse the repository at this point in the history
* Automations. Support executionID for activateFlowTriggerById
  • Loading branch information
viktor-liablin authored Jun 5, 2024
1 parent b5e99a6 commit 3671632
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backendless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ declare module Backendless {
function activateFlow(flowName: string, initialData?: object): Promise<void>
function activateFlowById(flowId: string, initialData?: object): Promise<void>
function activateFlowTrigger(flowName: string, triggerName: string, data?: object): Promise<void>
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object): Promise<void>
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, executionId?: string): Promise<void>
}

/**
Expand Down
17 changes: 14 additions & 3 deletions src/automations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
}
Expand All @@ -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,
})
}
}
3 changes: 2 additions & 1 deletion test/tsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;

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() {
Expand Down
25 changes: 25 additions & 0 deletions test/unit/specs/automations/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('<Automations> Basic', function() {

const FLOW_NAME = 'FlowName'
const FLOW_ID = 'FlowID'
const EXECUTION_ID = 'ExecutionID'
const TRIGGER_NAME = 'TriggerName'
const TRIGGER_ID = 'TriggerID'

Expand Down Expand Up @@ -198,8 +199,11 @@ describe('<Automations> 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',
Expand All @@ -215,6 +219,14 @@ describe('<Automations> 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 () => {
Expand Down Expand Up @@ -262,6 +274,19 @@ describe('<Automations> 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)
})
})

})

0 comments on commit 3671632

Please sign in to comment.