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 109
/
Copy pathpublish.js
103 lines (79 loc) · 2.59 KB
/
publish.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
/* eslint-env mocha */
'use strict'
const hat = require('hat')
const { fixture } = require('./utils')
const { spawnNodeWithId } = require('../utils/spawn')
const { getDescribe, getIt, expect } = require('../utils/mocha')
module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()
describe('.name.publish', function () {
const keyName = hat()
let ipfs
let nodeId
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(60 * 1000)
common.setup((err, factory) => {
expect(err).to.not.exist()
spawnNodeWithId(factory, (err, node) => {
expect(err).to.not.exist()
ipfs = node
nodeId = node.peerId.id
ipfs.files.add(fixture.data, { pin: false }, done)
})
})
})
after((done) => common.teardown(done))
it('should publish an IPNS record with the default params', function (done) {
this.timeout(50 * 1000)
const value = fixture.cid
ipfs.name.publish(value, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.name).to.equal(nodeId)
expect(res.value).to.equal(`/ipfs/${value}`)
done()
})
})
it('should publish correctly when the file was not added but resolve is disabled', function (done) {
this.timeout(50 * 1000)
const value = 'QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU'
const options = {
resolve: false,
lifetime: '1m',
ttl: '10s',
key: 'self'
}
ipfs.name.publish(value, options, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.name).to.equal(nodeId)
expect(res.value).to.equal(`/ipfs/${value}`)
done()
})
})
it('should publish with a key received as param, instead of using the key of the node', function (done) {
this.timeout(90 * 1000)
const value = fixture.cid
const options = {
resolve: false,
lifetime: '24h',
ttl: '10s',
key: keyName
}
ipfs.key.gen(keyName, { type: 'rsa', size: 2048 }, function (err, key) {
expect(err).to.not.exist()
ipfs.name.publish(value, options, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.name).to.equal(key.id)
expect(res.value).to.equal(`/ipfs/${value}`)
done()
})
})
})
})
}