Skip to content

Commit

Permalink
Merge branch 'master' into sandrosov/BKNDLSS-34660/JS]API-for-delete-…
Browse files Browse the repository at this point in the history
…PUB_SUB-channels
  • Loading branch information
macbookpro committed Feb 21, 2024
2 parents 20074ca + ee5fe0a commit 4157786
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 7 deletions.
12 changes: 11 additions & 1 deletion backendless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@ 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>
}

/**
Expand Down Expand Up @@ -1353,6 +1355,7 @@ declare module Backendless {
removeUpsertListeners(): Backendless.EventHandler;

removeUpsertListener<T = object>(callback: (obj: T) => void): Backendless.EventHandler;
removeUpsertListener<T = object>(whereClause: string, callback: (obj: T) => void): Backendless.EventHandler;

addCreateListener<T = object>(whereClause: string, callback: (obj: T) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
addCreateListener<T = object>(whereClause: string, callback: (obj: T) => void): Backendless.EventHandler;
Expand Down Expand Up @@ -1386,17 +1389,24 @@ declare module Backendless {

addBulkUpsertListener(callback: (list: string[]) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
addBulkUpsertListener(callback: (list: string[]) => void): Backendless.EventHandler;
addBulkUpsertListener(whereClause: string, callback: (list: string[]) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
addBulkUpsertListener(whereClause: string, callback: (list: string[]) => void): Backendless.EventHandler;

removeBulkUpsertListener(callback: (list: string[]) => void): Backendless.EventHandler;

removeBulkUpsertListener(whereClause: string, callback: (list: string[]) => void): Backendless.EventHandler;
removeBulkUpsertListeners(whereClause: string): Backendless.EventHandler;
removeBulkUpsertListeners(): Backendless.EventHandler;

addBulkCreateListener(callback: (list: string[]) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
addBulkCreateListener(callback: (list: string[]) => void): Backendless.EventHandler;
addBulkCreateListener(whereClause: string, callback: (list: string[]) => void): Backendless.EventHandler;
addBulkCreateListener(whereClause: string, callback: (list: string[]) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;

removeBulkCreateListener(whereClause: string, callback: (list: string[]) => void): Backendless.EventHandler;
removeBulkCreateListener(callback: (list: string[]) => void): Backendless.EventHandler;

removeBulkCreateListeners(): Backendless.EventHandler;
removeBulkCreateListeners(whereClause: string): Backendless.EventHandler;

addBulkUpdateListener(whereClause: string, callback: (obj: RTBulkChangesSubscriptionResult) => void, onError: (error: RTSubscriptionError) => void): Backendless.EventHandler;
addBulkUpdateListener(whereClause: string, callback: (obj: RTBulkChangesSubscriptionResult) => void): Backendless.EventHandler;
Expand Down
38 changes: 36 additions & 2 deletions src/automations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Automations {
}

if (initialData !== undefined && !Utils.isObject(initialData)) {
throw new Error('The "initialData" argument must be an object with an arbitrary structure.')
throw new Error('The "initialData" argument must be an object.')
}

return this.app.request.post({
Expand All @@ -23,6 +23,21 @@ export default class Automations {
})
}

async activateFlowById(flowId, initialData) {
if (!flowId || typeof flowId !== 'string') {
throw new Error('The "flowId" argument must be provided and must be a string.')
}

if (initialData !== undefined && !Utils.isObject(initialData)) {
throw new Error('The "initialData" argument must be an object.')
}

return this.app.request.post({
url : `${this.app.urls.automationFlow()}/${flowId}/activate`,
data: initialData || {}
})
}

async activateFlowTrigger(flowName, triggerName, data) {
if (!flowName || typeof flowName !== 'string') {
throw new Error('The "flowName" argument must be provided and must be a string.')
Expand All @@ -33,7 +48,7 @@ export default class Automations {
}

if (data !== undefined && !Utils.isObject(data)) {
throw new Error('The "data" argument must be an object with an arbitrary structure.')
throw new Error('The "data" argument must be an object.')
}

return this.app.request.post({
Expand All @@ -42,4 +57,23 @@ export default class Automations {
data : data || {},
})
}

async activateFlowTriggerById(flowId, triggerId, data) {
if (!flowId || typeof flowId !== 'string') {
throw new Error('The "flowId" argument must be provided and must be a string.')
}

if (!triggerId || typeof triggerId !== 'string') {
throw new Error('The "triggerId" argument must be provided and must be a string.')
}

if (data !== undefined && !Utils.isObject(data)) {
throw new Error('The "data" argument must be an object.')
}

return this.app.request.post({
url : `${this.app.urls.automationFlow()}/${flowId}/trigger/${triggerId}/activate`,
data: data || {},
})
}
}
9 changes: 9 additions & 0 deletions test/tsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,11 +1526,15 @@ function testAutomations() {
type TestObjType = { [x: string]: number }
const obj: TestObjType = {x: 1, y: 2};
const flowName: string = 'str';
const flowId: string = 'id';
const triggerName: string = 'str';
const triggerId: 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);
}

function testMessaging() {
Expand Down Expand Up @@ -1989,6 +1993,7 @@ function RTData() {
.removeUpsertListeners()
.removeUpsertListener<Person>((obj: Person) => undefined)
.removeUpsertListener<Person>((obj: { foo: string }) => undefined)
.removeUpsertListener('whereClause', (obj: { foo: string }) => undefined)


eventHandler
Expand Down Expand Up @@ -2064,9 +2069,13 @@ function RTData() {
eventHandler
.addBulkUpsertListener((list: string[]) => undefined, (error: Backendless.RTSubscriptionError) => undefined)
.addBulkUpsertListener((list: string[]) => undefined)
.addBulkUpsertListener('whereClause', (list: string[]) => undefined)
.addBulkUpsertListener('whereClause', (list: string[]) => undefined, (error: Backendless.RTSubscriptionError) => undefined)

eventHandler
.removeBulkUpsertListener((list: string[]) => undefined)
.removeBulkUpsertListener('whereClause', (list: string[]) => undefined)
.removeBulkUpsertListeners('whereClause')
.removeBulkUpsertListeners()

eventHandler
Expand Down
134 changes: 130 additions & 4 deletions test/unit/specs/automations/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ describe('<Automations> Basic', function() {
forTest(this)

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

describe('activate flow by name', function() {
it('success', async () => {
Expand Down Expand Up @@ -54,7 +56,7 @@ describe('<Automations> Basic', function() {
})

it('fails when initial data is invalid', async () => {
const errorMsg = 'The "initialData" argument must be an object with an arbitrary structure.'
const errorMsg = 'The "initialData" argument must be an object.'

await expect(Backendless.Automations.activateFlow(FLOW_NAME, null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlow(FLOW_NAME, true)).to.eventually.be.rejectedWith(errorMsg)
Expand All @@ -68,6 +70,60 @@ describe('<Automations> Basic', function() {
})
})

describe('activate flow by id', function() {
it('success', async () => {
const req1 = prepareMockRequest()
const req2 = prepareMockRequest()
await Backendless.Automations.activateFlowById(FLOW_ID)
await Backendless.Automations.activateFlowById(FLOW_ID, { name: 'Nick' })

expect(req1).to.deep.include({
method: 'POST',
path : `${APP_PATH}/automation/flow/${FLOW_ID}/activate`,
body : {}
})

expect(req2).to.deep.include({
method: 'POST',
path : `${APP_PATH}/automation/flow/${FLOW_ID}/activate`,
body : {
name: 'Nick',
}
})

})

it('fails when flow id is invalid', async () => {
const errorMsg = 'The "flowId" argument must be provided and must be a string.'

await expect(Backendless.Automations.activateFlowById()).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(undefined)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(true)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(false)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(0)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(123)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById('')).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById({})).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById([])).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(() => ({}))).to.eventually.be.rejectedWith(errorMsg)
})

it('fails when initial data is invalid', async () => {
const errorMsg = 'The "initialData" argument must be an object.'

await expect(Backendless.Automations.activateFlowById(FLOW_ID, null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, true)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, false)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, 0)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, 123)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, 'asd')).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, '')).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, [])).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowById(FLOW_ID, () => ({}))).to.eventually.be.rejectedWith(errorMsg)
})
})

describe('activate flow trigger', function() {
it('success', async () => {
const req1 = prepareMockRequest()
Expand Down Expand Up @@ -110,9 +166,9 @@ describe('<Automations> Basic', function() {
it('fails when trigger name is invalid', async () => {
const errorMsg = 'The "triggerName" argument must be provided and must be a string.'

await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, )).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME,)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, undefined)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME,null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, true)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, false)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, 0)).to.eventually.be.rejectedWith(errorMsg)
Expand All @@ -124,7 +180,7 @@ describe('<Automations> Basic', function() {
})

it('fails when data is invalid', async () => {
const errorMsg = 'The "data" argument must be an object with an arbitrary structure.'
const errorMsg = 'The "data" argument must be an object.'

await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, TRIGGER_NAME, null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTrigger(FLOW_NAME, TRIGGER_NAME, true)).to.eventually.be.rejectedWith(errorMsg)
Expand All @@ -138,4 +194,74 @@ describe('<Automations> Basic', function() {
})
})

describe('activate flow trigger by id', function() {
it('success', async () => {
const req1 = prepareMockRequest()
const req2 = prepareMockRequest()
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID)
await Backendless.Automations.activateFlowTriggerById(FLOW_ID, TRIGGER_ID, { name: 'Nick' })

expect(req1).to.deep.include({
method: 'POST',
path : `${APP_PATH}/automation/flow/${ FLOW_ID }/trigger/${ TRIGGER_ID }/activate`,
body : {},
})

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

})

it('fails when flow id is invalid', async () => {
const errorMsg = 'The "flowId" argument must be provided and must be a string.'

await expect(Backendless.Automations.activateFlowTriggerById()).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(undefined)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(true)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(false)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(0)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(123)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById('')).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById({})).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById([])).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(() => ({}))).to.eventually.be.rejectedWith(errorMsg)
})

it('fails when trigger id is invalid', async () => {
const errorMsg = 'The "triggerId" argument must be provided and must be a string.'

await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID,)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, undefined)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, null)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, true)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, false)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, 0)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, 123)).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, '')).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, {})).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, [])).to.eventually.be.rejectedWith(errorMsg)
await expect(Backendless.Automations.activateFlowTriggerById(FLOW_ID, () => ({}))).to.eventually.be.rejectedWith(errorMsg)
})

it('fails when data is invalid', async () => {
const errorMsg = 'The "data" argument must be an object.'

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, 'asd')).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 4157786

Please sign in to comment.