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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3cba34e  Handle a blocking/result response that is demoted to async. 
(#199)
3cba34e is described below

commit 3cba34ec0199f6efd5c60e0e1db2e77771900840
Author: rodric rabbah <[email protected]>
AuthorDate: Mon Jan 20 10:38:49 2020 -0500

    Handle a blocking/result response that is demoted to async. (#199)
    
    * If blocking/result response was demoted to async, complete the promise 
with a rejection.
    * Add test case.
---
 lib/actions.js            |  6 +++++-
 test/unit/actions.test.js | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/actions.js b/lib/actions.js
index 059e112..e874bb2 100644
--- a/lib/actions.js
+++ b/lib/actions.js
@@ -45,7 +45,11 @@ class Actions extends Resources {
   invoke (options) {
     options = options || {}
     if (options.blocking && options.result) {
-      return super.invoke(options).then(result => result.response.result)
+      return super.invoke(options).then(result => {
+        if (result.response) {
+          return result.response.result
+        } else return Promise.reject(result)
+      })
     }
 
     return super.invoke(options)
diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js
index c52d580..9377cae 100644
--- a/test/unit/actions.test.js
+++ b/test/unit/actions.test.js
@@ -246,6 +246,25 @@ test('should invoke action to retrieve result', t => {
   })
 })
 
+test('should invoke action to retrieve result but request is demoted to 
async', t => {
+  t.plan(4)
+  const ns = '_'
+  const client = {}
+  const actions = new Actions(client)
+  const result = { activationId: '123456' }
+
+  client.request = (method, path, options) => {
+    t.is(method, 'POST')
+    t.is(path, `namespaces/${ns}/actions/12345`)
+    t.deepEqual(options.qs, { blocking: true })
+    return Promise.resolve(result)
+  }
+
+  return actions.invoke({ name: '12345', result: true, blocking: true 
}).catch(_result => {
+    t.deepEqual(_result, result)
+  })
+})
+
 test('should invoke action to retrieve result without blocking', t => {
   t.plan(4)
   const ns = '_'

Reply via email to