This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathname.spec.js
110 lines (96 loc) · 2.54 KB
/
name.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
const series = require('async/series')
const loadFixture = require('aegir/fixtures')
const FactoryClient = require('./ipfs-factory/client')
const testfile = isNode
? loadFixture(__dirname, '/fixtures/testfile.txt')
: loadFixture(__dirname, 'fixtures/testfile.txt')
describe('.name', () => {
let ipfs
let other
let fc
before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
series([
(cb) => {
fc.spawnNode((err, node) => {
expect(err).to.not.exist()
ipfs = node
cb()
})
},
(cb) => {
fc.spawnNode((err, node) => {
expect(err).to.not.exist()
other = node
cb()
})
},
(cb) => {
ipfs.id((err, id) => {
expect(err).to.not.exist()
const ma = id.addresses[0]
other.swarm.connect(ma, cb)
})
}
], done)
})
after((done) => fc.dismantle(done))
describe('Callback API', () => {
let name
it('add file for testing', (done) => {
const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
ipfs.files.add(testfile, (err, res) => {
expect(err).to.not.exist()
expect(res).to.have.length(1)
expect(res[0].hash).to.equal(expectedMultihash)
expect(res[0].path).to.equal(expectedMultihash)
done()
})
})
it('.name.publish', (done) => {
ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
expect(err).to.not.exist()
name = res
expect(name).to.exist()
done()
})
})
it('.name.resolve', (done) => {
ipfs.name.resolve(name.Name, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res).to.be.eql({
Path: name.Value
})
done()
})
})
})
describe('Promise API', () => {
let name
it('.name.publish', () => {
return ipfs.name.publish('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
.then((res) => {
name = res
expect(name).to.exist()
})
})
it('.name.resolve', () => {
return ipfs.name.resolve(name.Name)
.then((res) => {
expect(res).to.exist()
expect(res).to.be.eql({
Path: name.Value
})
})
})
})
})