This is an automated email from the ASF dual-hosted git repository.

csantanapr pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-js.git


The following commit(s) were added to refs/heads/master by this push:
     new 9dfcd1a  Add Code Query Parameter (#99)
9dfcd1a is described below

commit 9dfcd1a9e9eac1f826e2c99721fd28913210743a
Author: James Dubee <jwdu...@us.ibm.com>
AuthorDate: Tue Mar 13 22:52:51 2018 -0400

    Add Code Query Parameter (#99)
---
 README.md                        | 10 +++-------
 lib/actions.js                   |  7 +++++++
 test/integration/actions.test.js | 32 ++++++++++++++++++++++++++++++++
 test/unit/actions.test.js        | 21 ++++++++++++++++++++-
 4 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index 8d6af41..0009c8e 100644
--- a/README.md
+++ b/README.md
@@ -249,15 +249,11 @@ ow.packages.get({name: '...'})
 ow.feeds.get({name: '...', trigger: '...'})
 ```
 
-The following optional parameters are supported:
+The following optional parameters are supported for all resource retrievals:
 - `namespace` - set custom namespace for endpoint
 
-This method also supports passing the `name` property directly without 
wrapping within an object.
-
-```javascript
-const name = "actionName"
-ow.actions.get(name)
-```
+Optional parameters for action resource retrievals are shown below:
+- `code` - set to `true` or `false` depending on whether action code should be 
included or excluded respectively
 
 If you pass in an array for the first parameter, the `get` call will be 
executed for each array item. The function returns a Promise which resolves 
with the results when all operations have finished.
 
diff --git a/lib/actions.js b/lib/actions.js
index 87ca22c..87d190b 100644
--- a/lib/actions.js
+++ b/lib/actions.js
@@ -21,6 +21,13 @@ class Actions extends Resources {
     return super.list(options)
   }
 
+  get (options) {
+    options = options || {}
+    options.qs = this.qs(options, ['code'])
+
+    return this.operation_with_id('GET', options)
+  }
+
   invoke (options) {
     options = options || {}
     if (options.blocking && options.result) {
diff --git a/test/integration/actions.test.js b/test/integration/actions.test.js
index d61bd94..86b92f0 100644
--- a/test/integration/actions.test.js
+++ b/test/integration/actions.test.js
@@ -137,6 +137,38 @@ test('create, get and delete with parameters an action', t 
=> {
   }).catch(errors)
 })
 
+test('get an action with and without its code', t => {
+  const errors = err => {
+    console.log(err)
+    t.fail()
+  }
+
+  const actions = new Actions(new Client(options))
+  return actions.create({actionName: 'random_action_get_test', action: 
'function main() {return {payload:"testing"}}'}).then(result => {
+    t.is(result.name, 'random_action_get_test')
+    t.is(result.namespace, NAMESPACE)
+    t.is(result.exec.kind, 'nodejs:6')
+    t.is(result.exec.code, 'function main() {return {payload:"testing"}}')
+    return actions.get({actionName: 'random_action_get_test', code: 
false}).then(action_result => {
+      t.is(action_result.name, 'random_action_get_test')
+      t.is(action_result.namespace, NAMESPACE)
+      t.is(action_result.exec.code, undefined)
+      return actions.get({actionName: 'random_action_get_test', code: 
true}).then(action_result => {
+        t.is(action_result.name, 'random_action_get_test')
+        t.is(action_result.namespace, NAMESPACE)
+        t.is(action_result.exec.code, 'function main() {return 
{payload:"testing"}}')
+        return actions.get({actionName: 
'random_action_get_test'}).then(action_result => {
+          t.is(action_result.name, 'random_action_get_test')
+          t.is(action_result.namespace, NAMESPACE)
+          t.is(action_result.exec.code, 'function main() {return 
{payload:"testing"}}')
+          t.pass()
+          return actions.delete({actionName: 
'random_action_get_test'}).catch(errors)
+        }).catch(errors)
+      }).catch(errors)
+    }).catch(errors)
+  }).catch(errors)
+})
+
 test('invoke action with fully-qualified name', t => {
   const errors = err => {
     console.log(err)
diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js
index fd16af1..1a5ec1c 100644
--- a/test/unit/actions.test.js
+++ b/test/unit/actions.test.js
@@ -49,6 +49,25 @@ test('should retrieve action from identifier', t => {
   return actions.get({name: '12345'})
 })
 
+
+test('should retrieve action from identifier with code query parameter', t => {
+  t.plan(3)
+  const ns = '_'
+  const client = {}
+  const actions = new Actions(client)
+  const code = {
+    code: false
+  }
+
+  client.request = (method, path, options) => {
+    t.is(method, 'GET')
+    t.is(path, `namespaces/${ns}/actions/12345`)
+    t.deepEqual(options.qs, code)
+  }
+
+  return actions.get({name: '12345', code: false})
+})
+
 test('should retrieve action from string identifier', t => {
   t.plan(2)
   const ns = '_'
@@ -60,7 +79,7 @@ test('should retrieve action from string identifier', t => {
     t.is(path, `namespaces/${ns}/actions/12345`)
   }
 
-  return actions.get('12345')
+  return actions.get({name: '12345'})
 })
 
 test('should delete action from identifier', t => {

-- 
To stop receiving notification emails like this one, please contact
csantan...@apache.org.

Reply via email to