Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add executions modes to activateFlowTriggerById #252

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, executionId?: string): Promise<void>
function activateFlowTriggerById(flowId: string, triggerId: string, data?: object, execution?: string): Promise<void>
stanislav-grin marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
20 changes: 15 additions & 5 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, 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.')
}
Expand All @@ -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 executionId.'
stanislav-grin marked this conversation as resolved.
Show resolved Hide resolved
)
}

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({
Expand Down
4 changes: 2 additions & 2 deletions test/tsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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, executionId);
promiseObject = Backendless.Automations.activateFlowTriggerById(flowId, triggerId, obj, execution);
}

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

Expand Down Expand Up @@ -200,10 +202,14 @@ describe('<Automations> 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',
Expand All @@ -227,6 +233,22 @@ describe('<Automations> 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 () => {
Expand Down Expand Up @@ -276,7 +298,8 @@ describe('<Automations> 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 executionId.'

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)
Expand Down
Loading