csantanapr closed pull request #99: Add Code Query Parameter
URL: https://github.com/apache/incubator-openwhisk-client-js/pull/99
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 => {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to