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

Auto set json and bool flags on config.set #221

Merged
merged 1 commit into from
Mar 2, 2016
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
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