You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2018/01/12 18:51:04 UTC

[incubator-openwhisk-client-js] branch master updated: Sugar namespsace get. (#95)

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 370fc7c  Sugar namespsace get. (#95)
370fc7c is described below

commit 370fc7c16b1cffa96936cdccc440919ceecaddf5
Author: rodric rabbah <ro...@gmail.com>
AuthorDate: Fri Jan 12 13:51:01 2018 -0500

    Sugar namespsace get. (#95)
---
 README.md                    |  1 -
 lib/namespaces.js            | 23 +++++++++--------------
 test/unit/namespaces.test.js | 43 +++++++------------------------------------
 3 files changed, 16 insertions(+), 51 deletions(-)

diff --git a/README.md b/README.md
index 3f36dec..81cdbb2 100644
--- a/README.md
+++ b/README.md
@@ -245,7 +245,6 @@ ow.actions.get({name: '...'})
 ow.activations.get({name: '...'})
 ow.triggers.get({name: '...'})
 ow.rules.get({name: '...'})
-ow.namespaces.get({name: '...'})
 ow.packages.get({name: '...'})
 ow.feeds.get({name: '...', trigger: '...'})
 ```
diff --git a/lib/namespaces.js b/lib/namespaces.js
index b07fa96..e9d8a81 100644
--- a/lib/namespaces.js
+++ b/lib/namespaces.js
@@ -7,22 +7,17 @@ const BaseOperation = require('./base_operation')
 
 class Namespaces extends BaseOperation {
   list () {
-    return this.client.request('GET', `namespaces`)
+    return this.client.request('GET', 'namespaces')
   }
 
-  get (options) {
-    if (typeof options === 'string') {
-      return this.client.request('GET', `namespaces/${options}`)
-    }
-
-    options = options || {}
-    const id = options.name || options.namespace
-
-    if (!id) {
-      throw new Error('Missing mandatory parameter: id or namespace.')
-    }
-
-    return this.client.request('GET', `namespaces/${id}`)
+  get () {
+    let actions = this.client.request('GET', 'namespaces/_/actions')
+    let packages = this.client.request('GET', 'namespaces/_/packages')
+    let triggers = this.client.request('GET', 'namespaces/_/triggers')
+    let rules = this.client.request('GET', 'namespaces/_/rules')
+    return Promise
+      .all([actions, packages, triggers, rules])
+      .then(([actions, packages, triggers, rules]) => ({actions, packages, triggers, rules}))
   }
 }
 
diff --git a/test/unit/namespaces.test.js b/test/unit/namespaces.test.js
index 1c7b03e..5a31673 100644
--- a/test/unit/namespaces.test.js
+++ b/test/unit/namespaces.test.js
@@ -18,46 +18,17 @@ test('should list all namespaces', t => {
   return namespaces.list()
 })
 
-test('should retrieve namespace using id', t => {
-  t.plan(2)
+test('should retrieve namespace entities', t => {
+  t.plan(16)
   const client = {}
-  const id = 'custom_ns'
   client.request = (method, path, options) => {
     t.is(method, 'GET')
-    t.is(path, `namespaces/${id}`)
+    let parts = path.split('/')
+    t.is(parts[0], 'namespaces')
+    t.is(parts[1], '_')
+    t.is(["actions", "triggers", "rules", "packages"].indexOf(parts[2]) > -1, true)
   }
 
   const namespaces = new Namespaces(client)
-  return namespaces.get({name: id})
-})
-
-test('should retrieve namespace using string id', t => {
-  t.plan(2)
-  const client = {}
-  const id = 'custom_ns'
-  client.request = (method, path, options) => {
-    t.is(method, 'GET')
-    t.is(path, `namespaces/${id}`)
-  }
-
-  const namespaces = new Namespaces(client)
-  return namespaces.get(id)
-})
-
-test('should retrieve namespace using namespace', t => {
-  t.plan(2)
-  const client = {}
-  const id = 'custom_ns'
-  client.request = (method, path, options) => {
-    t.is(method, 'GET')
-    t.is(path, `namespaces/${id}`)
-  }
-
-  const namespaces = new Namespaces(client)
-  return namespaces.get({namespace: id})
-})
-
-test('should throw error for missing namespace id', t => {
-  const namespaces = new Namespaces()
-  return t.throws(() => { namespaces.get() }, /Missing mandatory parameter/)
+  return namespaces.get()
 })

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].