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

Change API for activateFlowTriggerById #253

Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -612,7 +612,7 @@ declare module Backendless {
* @type: Function
*/

type Execution = 'activateAny' | 'activateAll' | string
type Execution = 'any' | 'all' | string

function activateFlow(flowName: string, initialData?: object): Promise<void>
function activateFlowById(flowId: string, initialData?: object): Promise<void>
Expand Down
17 changes: 2 additions & 15 deletions src/automations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,14 @@ export default class Automations {
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 Execution ID.'
'The "execution" argument must be a non-empty string and must be one of this values: "any", "all" or Execution ID.'
)
}

const query = {}

switch (execution) {
case 'activateAny':
query.activateAny = true
break
case 'activateAll':
query.activateAll = true
break
default:
query.executionId = execution
}

return this.app.request.post({
url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`,
data : data || {},
query: query,
query: { execution },
})
}
}
12 changes: 6 additions & 6 deletions test/unit/specs/automations/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +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 EXECUTION_ANY = 'any'
const EXECUTION_ALL = 'all'
const TRIGGER_NAME = 'TriggerName'
const TRIGGER_ID = 'TriggerID'

Expand Down Expand Up @@ -227,23 +227,23 @@ describe('<Automations> Basic', function() {

expect(req3).to.deep.include({
method: 'POST',
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?executionId=ExecutionID`,
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?execution=ExecutionID`,
body : {
name: 'Nick',
}
})

expect(req4).to.deep.include({
method: 'POST',
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?activateAny=true`,
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?execution=any`,
body : {
name: 'Nick',
}
})

expect(req5).to.deep.include({
method: 'POST',
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?activateAll=true`,
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate?execution=all`,
body : {
name: 'Nick',
}
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('<Automations> Basic', function() {

it('fails when execution id is invalid', async () => {
// 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 Execution ID.'
const errorMsg = 'The "execution" argument must be a non-empty string and must be one of this values: "any", "all" or Execution ID.'

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