Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
Merge pull request #221 from xicombd/config-set-flags
Browse files Browse the repository at this point in the history
Auto set json and bool flags on config.set
  • Loading branch information
daviddias committed Mar 2, 2016
2 parents 2150be5 + 094a640 commit 796f15a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/api/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ module.exports = (send) => {
cb = opts
opts = {}
}

if (typeof (value) === 'object') {
value = JSON.stringify(value)
opts = { json: true }
} else if (typeof (value) === 'boolean') {
value = value.toString()
opts = { bool: true }
}

return send('config', [key, value], opts, null, cb)
},
show (cb) {
Expand Down
94 changes: 76 additions & 18 deletions test/api/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,46 @@
const path = require('path')

describe('.config', () => {
it('.config.{set, get}', (done) => {
const confKey = 'arbitraryKey'
const confVal = 'arbitraryVal'
describe('.config.{set, get}', () => {
it('string', (done) => {
const confKey = 'arbitraryKey'
const confVal = 'arbitraryVal'

apiClients['a'].config.set(confKey, confVal, (err, res) => {
expect(err).to.not.exist
apiClients['a'].config.get(confKey, (err, res) => {
apiClients['a'].config.set(confKey, confVal, (err, res) => {
expect(err).to.not.exist
apiClients['a'].config.get(confKey, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Value', confVal)
done()
})
})
})

it('bool', (done) => {
const confKey = 'otherKey'
const confVal = true

apiClients['a'].config.set(confKey, confVal, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Value', confVal)
done()
apiClients['a'].config.get(confKey, (err, res) => {
expect(err).to.not.exist
expect(res.Value).to.deep.equal(confVal)
done()
})
})
})

it('json', (done) => {
const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin'
const confVal = ['http://example.io']

apiClients['a'].config.set(confKey, confVal, (err, res) => {
expect(err).to.not.exist
apiClients['a'].config.get(confKey, (err, res) => {
expect(err).to.not.exist
expect(res.Value).to.deep.equal(confVal)
done()
})
})
})
})
Expand All @@ -38,17 +68,45 @@ describe('.config', () => {
})

describe('promise', () => {
it('.config.{set, get}', () => {
const confKey = 'arbitraryKey'
const confVal = 'arbitraryVal'
describe('.config.{set, get}', () => {
it('string', () => {
const confKey = 'arbitraryKey'
const confVal = 'arbitraryVal'

return apiClients['a'].config.set(confKey, confVal)
.then((res) => {
return apiClients['a'].config.get(confKey)
})
.then((res) => {
expect(res).to.have.a.property('Value', confVal)
})
return apiClients['a'].config.set(confKey, confVal)
.then((res) => {
return apiClients['a'].config.get(confKey)
})
.then((res) => {
expect(res).to.have.a.property('Value', confVal)
})
})

it('bool', () => {
const confKey = 'otherKey'
const confVal = true

return apiClients['a'].config.set(confKey, confVal)
.then((res) => {
return apiClients['a'].config.get(confKey)
})
.then((res) => {
expect(res.Value).to.deep.equal(confVal)
})
})

it('json', () => {
const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin'
const confVal = ['http://example.com']

return apiClients['a'].config.set(confKey, confVal)
.then((res) => {
return apiClients['a'].config.get(confKey)
})
.then((res) => {
expect(res.Value).to.deep.equal(confVal)
})
})
})

it('.config.show', () => {
Expand Down

0 comments on commit 796f15a

Please sign in to comment.