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

Commit

Permalink
follow interface-ipfs-core config spec
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Jun 30, 2016
1 parent ad51062 commit e000da1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 136 deletions.
18 changes: 12 additions & 6 deletions src/api/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
'use strict'

const argCommand = require('../cmd-helpers').argCommand

module.exports = (send) => {
return {
get: argCommand(send, 'config'),
get: (key, callback) => {
if (typeof key === 'function') {
callback = key
key = undefined
}

if (!key) {
return send('config/show', null, null, null, true, callback)
}

return send('config', key, null, null, callback)
},
set (key, value, opts, cb) {
if (typeof (opts) === 'function') {
cb = opts
Expand All @@ -21,9 +30,6 @@ module.exports = (send) => {

return send('config', [key, value], opts, null, cb)
},
show (cb) {
return send('config/show', null, null, null, true, cb)
},
replace (file, cb) {
return send('config/replace', null, null, file, cb)
}
Expand Down
142 changes: 12 additions & 130 deletions test/api/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,133 +2,15 @@
/* globals apiClients */
'use strict'

const expect = require('chai').expect
const isNode = require('detect-node')
const path = require('path')

describe('.config', () => {
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) => {
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
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()
})
})
})
})

it('.config.show', (done) => {
apiClients.c.config.show((err, res) => {
expect(err).to.not.exist
expect(res).to.exist
done()
})
})

it('.config.replace', (done) => {
if (!isNode) {
return done()
}

apiClients.c.config.replace(path.join(__dirname, '/../r-config.json'), (err, res) => {
expect(err).to.not.exist
expect(res).to.be.equal(null)
done()
})
})

describe('promise', () => {
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)
})
})

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', () => {
return apiClients.c.config.show()
.then((res) => {
expect(res).to.exist
})
})

it('.config.replace', () => {
if (!isNode) {
return
}

return apiClients.c.config.replace(path.join(__dirname, '/../r-config.json'))
.then((res) => {
expect(res).to.be.equal(null)
})
})
})
})
const test = require('interface-ipfs-core')

const common = {
setup: function (cb) {
cb(null, apiClients.a)
},
teardown: function (cb) {
cb()
}
}

test.config(common)

0 comments on commit e000da1

Please sign in to comment.