Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sugar namespsace get. #95

Merged
merged 2 commits into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '...'})
```
Expand Down
23 changes: 9 additions & 14 deletions lib/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}))
}
}

Expand Down
43 changes: 7 additions & 36 deletions test/unit/namespaces.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})