Fix issue with string identifier for operations.
diff --git a/README.md b/README.md
index d5181a9..897da38 100644
--- a/README.md
+++ b/README.md
@@ -325,13 +325,6 @@
The following optional parameters are supported:
- `namespace` - set custom namespace for endpoint
-This method also supports passing the `name` property directly without wrapping within an object.
-
-```
-const name = "actionName"
-ow.actions.create(name)
-```
-
If you pass in an array for the first parameter, the `create` call will be executed for each array item. The function returns a Promise which resolves with the results when all operations have finished.
```
@@ -473,4 +466,4 @@
```
npm run-script test-integration
-```
\ No newline at end of file
+```
diff --git a/lib/actions.js b/lib/actions.js
index 9bb1384..1e6ff4f 100644
--- a/lib/actions.js
+++ b/lib/actions.js
@@ -8,6 +8,7 @@
super(client)
this.resource = 'actions'
this.identifiers.push('actionName')
+ this.qs_options.invoke = ['blocking']
}
list (options) {
@@ -17,14 +18,6 @@
return super.list(options)
}
- invoke (options) {
- options = options || {}
- options.qs = this.qs(options, ['blocking'])
- options.body = this.payload(options)
-
- return super.invoke(options)
- }
-
create (options) {
options.qs = this.qs(options, ['overwrite'])
options.body = this.action_body(options)
diff --git a/lib/resources.js b/lib/resources.js
index fb7898f..3c4555f 100644
--- a/lib/resources.js
+++ b/lib/resources.js
@@ -7,6 +7,7 @@
constructor (client) {
super(client)
this.identifiers = ['name']
+ this.qs_options = {}
}
list (options) {
@@ -18,6 +19,11 @@
}
invoke (options) {
+ options = options || {}
+ if (typeof options === 'object' && !Array.isArray(options)) {
+ options.qs = this.qs(options, this.qs_options.invoke || [])
+ options.body = this.payload(options)
+ }
return this.operation_with_id('POST', options)
}
diff --git a/lib/rules.js b/lib/rules.js
index dbeb3ed..da38332 100644
--- a/lib/rules.js
+++ b/lib/rules.js
@@ -45,13 +45,13 @@
enable (options) {
options = options || {}
- options.body = { status: 'active' }
+ options.params = { status: 'active' }
return super.invoke(options)
}
disable (options) {
options = options || {}
- options.body = { status: 'inactive' }
+ options.params = { status: 'inactive' }
return super.invoke(options)
}
diff --git a/lib/triggers.js b/lib/triggers.js
index b518f6b..555ee57 100644
--- a/lib/triggers.js
+++ b/lib/triggers.js
@@ -16,13 +16,6 @@
return super.list(options)
}
- invoke (options) {
- options = options || {}
- options.body = this.payload(options)
-
- return super.invoke(options)
- }
-
create (options) {
options.qs = this.qs(options, ['overwrite'])
options.body = options.trigger || {}
diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js
index 40a86a6..86d3302 100644
--- a/test/unit/actions.test.js
+++ b/test/unit/actions.test.js
@@ -20,7 +20,6 @@
test('should list all actions with parameters', t => {
t.plan(3)
- const ns = '_'
const client = {}
const actions = new Actions(client)
@@ -47,6 +46,20 @@
return actions.get({name: '12345'})
})
+test('should retrieve action from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = {}
+ const actions = new Actions(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'GET')
+ t.is(path, `namespaces/${ns}/actions/12345`)
+ }
+
+ return actions.get('12345')
+})
+
test('should delete action from identifier', t => {
t.plan(2)
const ns = '_'
@@ -75,6 +88,20 @@
return actions.get({actionName: '12345'})
})
+test('should delete action from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = {}
+ const actions = new Actions(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'DELETE')
+ t.is(path, `namespaces/${ns}/actions/12345`)
+ }
+
+ return actions.delete('12345')
+})
+
test('should invoke action', t => {
t.plan(4)
const ns = '_'
@@ -91,9 +118,22 @@
return actions.invoke({name: '12345'})
})
+test('should invoke action from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = {}
+ const actions = new Actions(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'POST')
+ t.is(path, `namespaces/${ns}/actions/12345`)
+ }
+
+ return actions.invoke('12345')
+})
+
test('should invoke fully qualified action', t => {
t.plan(4)
- const ns = '_'
const client = {}
const actions = new Actions(client)
@@ -109,7 +149,6 @@
test('should invoke fully qualified action with package', t => {
t.plan(4)
- const ns = '_'
const client = {}
const actions = new Actions(client)
diff --git a/test/unit/rules.test.js b/test/unit/rules.test.js
index b1a9499..8ba9501 100644
--- a/test/unit/rules.test.js
+++ b/test/unit/rules.test.js
@@ -60,6 +60,20 @@
return rules.get({ruleName: '12345'})
})
+test('should retrieve rule from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = { options: {} }
+ const rules = new Rules(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'GET')
+ t.is(path, `namespaces/${ns}/rules/12345`)
+ }
+
+ return rules.get('12345')
+})
+
test('should delete rule from identifier', t => {
t.plan(2)
const ns = '_'
@@ -74,6 +88,20 @@
return rules.delete({name: '12345'})
})
+test('should delete rule from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = { options: {} }
+ const rules = new Rules(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'DELETE')
+ t.is(path, `namespaces/${ns}/rules/12345`)
+ }
+
+ return rules.delete('12345')
+})
+
test('should throw error trying to invoke rule', t => {
const rules = new Rules()
return t.throws(() => rules.invoke(), /Operation \(invoke\) not supported/)
diff --git a/test/unit/triggers.test.js b/test/unit/triggers.test.js
index ba0cfc6..944c873 100644
--- a/test/unit/triggers.test.js
+++ b/test/unit/triggers.test.js
@@ -47,6 +47,20 @@
return triggers.get({name: '12345'})
})
+test('should retrieve trigger from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = {}
+ const triggers = new Triggers(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'GET')
+ t.is(path, `namespaces/${ns}/triggers/12345`)
+ }
+
+ return triggers.get('12345')
+})
+
test('should delete trigger from identifier', t => {
t.plan(2)
const ns = '_'
@@ -61,6 +75,20 @@
return triggers.delete({name: '12345'})
})
+test('should delete trigger from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = {}
+ const triggers = new Triggers(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'DELETE')
+ t.is(path, `namespaces/${ns}/triggers/12345`)
+ }
+
+ return triggers.delete('12345')
+})
+
test('should retrieve triggerName from identifier', t => {
t.plan(2)
const ns = '_'
@@ -90,6 +118,20 @@
return triggers.invoke({name: '12345'})
})
+test('should invoke trigger from string identifier', t => {
+ t.plan(2)
+ const ns = '_'
+ const client = {}
+ const triggers = new Triggers(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'POST')
+ t.is(path, `namespaces/${ns}/triggers/12345`)
+ }
+
+ return triggers.invoke('12345')
+})
+
test('should invoke fully qualified trigger', t => {
t.plan(3)
const ns = '_'