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

Commit e97c567

Browse files
committed
feat(generic): make it spec compliant
1 parent ed07921 commit e97c567

File tree

9 files changed

+62
-145
lines changed

9 files changed

+62
-145
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"main": "lib/index.js",
66
"jsnext:main": "src/index.js",
77
"scripts": {
8-
"test": "gulp test",
8+
"test": "node --max_old_space_size=4096 node_modules/.bin/gulp test",
99
"test:node": "gulp test:node",
10-
"test:browser": "gulp test:browser",
10+
"test:browser": "node --max_old_space_size=4096 node_modules/.bin/gulp test:browser",
1111
"lint": "aegir-lint",
1212
"build": "gulp build",
1313
"release": "gulp release",
@@ -47,7 +47,7 @@
4747
"chai": "^3.5.0",
4848
"gulp": "^3.9.1",
4949
"hapi": "^14.1.0",
50-
"interface-ipfs-core": "^0.9.0",
50+
"interface-ipfs-core": "^0.11.0",
5151
"ipfsd-ctl": "^0.14.0",
5252
"passthrough-counter": "^1.0.0",
5353
"pre-commit": "^1.1.3",

src/api/id.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
'use strict'
22

3+
const promisify = require('promisify-es6')
4+
35
module.exports = (send) => {
4-
return function id (opts, callback) {
6+
return promisify((opts, callback) => {
57
if (typeof opts === 'function') {
68
callback = opts
79
opts = undefined
810
}
9-
return send({
11+
send({
1012
path: 'id',
1113
args: opts
12-
}, callback)
13-
}
14+
}, (err, result) => {
15+
if (err) {
16+
return callback(err)
17+
}
18+
const identity = {
19+
id: result.ID,
20+
publicKey: result.PublicKey,
21+
addresses: result.Addresses,
22+
agentVersion: result.AgentVersion,
23+
protocolVersion: result.ProtocolVersion
24+
}
25+
callback(null, identity)
26+
})
27+
})
1428
}

src/api/version.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
'use strict'
22

3+
const promisify = require('promisify-es6')
4+
35
module.exports = (send) => {
4-
return (opts, callback) => {
6+
return promisify((opts, callback) => {
57
if (typeof opts === 'function') {
68
callback = opts
79
opts = {}
810
}
911

10-
return send({
12+
send({
1113
path: 'version',
1214
qs: opts
13-
}, callback)
14-
}
15+
}, (err, result) => {
16+
if (err) {
17+
return callback(err)
18+
}
19+
const version = {
20+
version: result.Version,
21+
commit: result.Commit,
22+
repo: result.Repo
23+
}
24+
callback(null, version)
25+
})
26+
})
1527
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
const test = require('interface-ipfs-core')
6+
const FactoryClient = require('../factory/factory-client')
7+
8+
let fc
9+
10+
const common = {
11+
setup: function (callback) {
12+
fc = new FactoryClient()
13+
callback(null, fc)
14+
},
15+
teardown: function (callback) {
16+
fc.dismantle(callback)
17+
}
18+
}
19+
20+
test.generic(common)

test/interface-ipfs-core/id.spec.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

test/interface-ipfs-core/ping.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('.ping', () => {
99
apiClients.b.id((err, id) => {
1010
expect(err).to.not.exist
1111

12-
apiClients.a.ping(id.ID, (err, res) => {
12+
apiClients.a.ping(id.id, (err, res) => {
1313
expect(err).to.not.exist
1414
expect(res).to.have.a.property('Success')
1515
done()
@@ -21,7 +21,7 @@ describe('.ping', () => {
2121
it('ping another peer', () => {
2222
return apiClients.b.id()
2323
.then((id) => {
24-
return apiClients.a.ping(id.ID)
24+
return apiClients.a.ping(id.id)
2525
})
2626
.then((res) => {
2727
expect(res).to.have.a.property('Success')

test/interface-ipfs-core/version.spec.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

test/ipfs-api/constructor.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe('ipfsAPI constructor tests', () => {
1414
client.id((err, id) => {
1515
expect(err).to.not.exist
1616

17-
expect(id).to.have.a.property('ID')
18-
expect(id).to.have.a.property('PublicKey')
17+
expect(id).to.have.a.property('id')
18+
expect(id).to.have.a.property('publicKey')
1919
done()
2020
})
2121
}

test/setup/setup-ipfs-api-clients.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function connectNodes (done) {
1818
throw err
1919
}
2020
// note to self: HTTP API port !== Node port
21-
addrs[key] = id.Addresses[0]
21+
addrs[key] = id.addresses[0]
2222
cb()
2323
})
2424
}

0 commit comments

Comments
 (0)