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 01537c4  Allow update to action without requiring a code artifact. 
(#195)
01537c4 is described below

commit 01537c44c8210ee28c414bff5b3bf897ce7db449
Author: rodric rabbah <[email protected]>
AuthorDate: Mon Jan 20 10:40:42 2020 -0500

    Allow update to action without requiring a code artifact. (#195)
    
    * Allow update to action without requiring a code artifact.
    * Add overwrite test
---
 README.md                 |  2 +-
 lib/actions.js            |  6 ++++--
 lib/main.d.ts             |  2 +-
 test/unit/actions.test.js | 16 ++++++++++++++++
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index b43de7d..683016b 100644
--- a/README.md
+++ b/README.md
@@ -653,7 +653,7 @@ var openwhisk = require('openwhisk');
 ### unit tests
 
 ```bash
-$ npm test:unit
+$ npm run test:unit
 ```
 
 ### integration tests
diff --git a/lib/actions.js b/lib/actions.js
index e874bb2..b1aa876 100644
--- a/lib/actions.js
+++ b/lib/actions.js
@@ -91,10 +91,11 @@ class Actions extends Resources {
   }
 
   actionBody (options) {
+    const isUpdate = options && options.overwrite === true
     const isCodeAction = options.hasOwnProperty('action')
     const isSequenceAction = options.hasOwnProperty('sequence')
 
-    if (!isCodeAction && !isSequenceAction) {
+    if (!isCodeAction && !isSequenceAction && !isUpdate) {
       throw new Error(messages.MISSING_ACTION_OR_SEQ_BODY_ERROR)
     }
 
@@ -109,7 +110,8 @@ class Actions extends Resources {
     }
 
     const body = isCodeAction
-      ? this.actionBodyWithCode(options) : this.actionBodyWithSequence(options)
+      ? this.actionBodyWithCode(options)
+      : isSequenceAction ? this.actionBodyWithSequence(options) : {}
 
     if (typeof options.params === 'object') {
       body.parameters = Object.keys(options.params).map(key => ({ key, value: 
options.params[key] }))
diff --git a/lib/main.d.ts b/lib/main.d.ts
index 1585546..e2fb0ba 100644
--- a/lib/main.d.ts
+++ b/lib/main.d.ts
@@ -62,7 +62,7 @@ declare namespace openwhisk {
         invoke<In extends Dict, Out extends Dict>(options: { name: string; 
namespace?: string; blocking?: boolean; params?: In; result?: boolean; }): 
Promise<{ activationId: string }>;
         create(options: { name: string; namespace?: string; action: (string | 
Buffer | Action); kind?: Kind; overwrite?: boolean; params?: Dict; 
annotations?: Dict; limits?: Limits; version?: string; }): Promise<Action>;
         //create(options: { name: string; namespace?: string; action: (string 
| Buffer | Action); kind?: Kind; overwrite?: boolean; params?: Dict; version?: 
string; }[]): Promise<Action[]>;
-        update(options: { name: string; namespace?: string; action: (string | 
Buffer | Action); kind?: Kind; params?: Dict; annotations?: Dict; limits?: 
Limits; version?: string; }): Promise<Action>;
+        update(options: { name: string; namespace?: string; action?: (string | 
Buffer | Action); kind?: Kind; params?: Dict; annotations?: Dict; limits?: 
Limits; version?: string; }): Promise<Action>;
         //update(options: ({ name: string; namespace?: string; action: (string 
| Buffer | Action); kind?: Kind; params?: Dict; version?: string; })[]): 
Promise<Action[]>;
         delete(options: string): Promise<Action>;
         delete(options: { name: string; namespace?: string; }): 
Promise<Action>;
diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js
index 9377cae..a1f2f60 100644
--- a/test/unit/actions.test.js
+++ b/test/unit/actions.test.js
@@ -419,6 +419,22 @@ test('create a new action with annotations', t => {
   return actions.create({ name: '12345', action, annotations })
 })
 
+test('update a action with no parameters', t => {
+  t.plan(4)
+  const ns = '_'
+  const client = {}
+  const actions = new Actions(client)
+
+  client.request = (method, path, options) => {
+    t.is(method, 'PUT')
+    t.is(path, `namespaces/${ns}/actions/12345`)
+    t.deepEqual(options.qs, { overwrite: true })
+    t.deepEqual(options.body, { })
+  }
+
+  return actions.create({ name: '12345', overwrite: true })
+})
+
 test('create a new action with limits', t => {
   t.plan(4)
   const ns = '_'

Reply via email to