support feed trigger update (#88)
* support feed trigger update
* update test description
diff --git a/README.md b/README.md
index afd150e..3f36dec 100644
--- a/README.md
+++ b/README.md
@@ -247,7 +247,7 @@
ow.rules.get({name: '...'})
ow.namespaces.get({name: '...'})
ow.packages.get({name: '...'})
-ow.feeds.get({name: '...'})
+ow.feeds.get({name: '...', trigger: '...'})
```
The following optional parameters are supported:
@@ -415,10 +415,11 @@
The following optional parameters are supported:
- `namespace` - set custom namespace for endpoint
-### create feeds
+### create & update feeds
```javascript
ow.feeds.create({feedName: '...', trigger: '...'})
+ow.feeds.update({feedName: '...', trigger: '...'})
```
The following optional parameters are supported:
diff --git a/lib/feeds.js b/lib/feeds.js
index f8cdc28..1ecc151 100644
--- a/lib/feeds.js
+++ b/lib/feeds.js
@@ -25,6 +25,10 @@
return this.feed('READ', options)
}
+ update (options) {
+ return this.feed('UPDATE', options)
+ }
+
feed (event, options) {
if (!this.feed_name(options)) {
throw new Error(messages.MISSING_FEED_NAME_ERROR)
diff --git a/test/integration/feeds.test.js b/test/integration/feeds.test.js
index 1ebd7b8..d2ea95c 100644
--- a/test/integration/feeds.test.js
+++ b/test/integration/feeds.test.js
@@ -23,7 +23,7 @@
const NAMESPACE = process.env.__OW_NAMESPACE
var tempTest = Utils.getInsecureFlag() ? test.skip : test;
-tempTest('create and delete a feed', t => {
+tempTest('create, get, update, and delete a feed', t => {
const errors = err => {
console.log(err)
t.fail()
@@ -42,9 +42,12 @@
t.is(get_result.response.success, true)
return feeds.delete(feed_params).then(feed_result => {
t.is(feed_result.response.success, true)
- return triggers.delete({triggerName: 'sample_feed_trigger'}).then(() => {
- t.pass()
- })
+ return feeds.update(feed_params).then(update_result => {
+ t.is(feed_result.response.success, false) // alarms does not currently support update, hence should fail
+ return triggers.delete({triggerName: 'sample_feed_trigger'}).then(() => {
+ t.pass()
+ })
+ }).catch(errors)
}).catch(errors)
}).catch(errors)
}).catch(errors)
diff --git a/test/unit/feeds.test.js b/test/unit/feeds.test.js
index d68ef6f..005f3ec 100644
--- a/test/unit/feeds.test.js
+++ b/test/unit/feeds.test.js
@@ -228,6 +228,28 @@
return feeds.get({name: feed_name, trigger: trigger_name})
})
+test('should be able to update feed', t => {
+ const feed_name = 'feed_name'
+ const api_key = 'username:password'
+ const trigger_name = '/trigger_ns/trigger_name'
+ const client = {}
+ client.options = { api_key }
+
+ const ns = '_'
+ const feeds = new Feeds(client)
+
+ client.request = (method, path, options) => {
+ t.is(method, 'POST')
+ t.is(path, `namespaces/${ns}/actions/${feed_name}`)
+ t.deepEqual(options.qs, {blocking: true})
+ t.deepEqual(options.body, {authKey: client.options.api_key, lifecycleEvent: 'UPDATE', triggerName: `${trigger_name}`})
+ }
+
+ t.plan(4)
+
+ return feeds.update({name: feed_name, trigger: trigger_name})
+})
+
test('should throw errors without trigger parameter ', t => {
const ns = '_'
const client = { options: {} }