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

Commit 75cbc5e

Browse files
authored
Get tests passing with pin core changes (#63) (#160)
* Get tests passing with pin core changes (#63) * chore: fix linting
1 parent dd2aed0 commit 75cbc5e

File tree

1 file changed

+70
-51
lines changed

1 file changed

+70
-51
lines changed

src/pin.js

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const expect = chai.expect
99
chai.use(dirtyChai)
1010
const loadFixture = require('aegir/fixtures')
1111

12-
const testfile = loadFixture(__dirname, '../test/fixtures/testfile.txt', 'interface-ipfs-core')
12+
const testFile = loadFixture(__dirname, '../test/fixtures/testfile.txt', 'interface-ipfs-core')
13+
const testHash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
1314

1415
module.exports = (common) => {
1516
describe('.pin', function () {
@@ -28,14 +29,11 @@ module.exports = (common) => {
2829
})
2930

3031
function populate () {
31-
const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
32-
33-
ipfs.files.add(testfile, (err, res) => {
32+
ipfs.files.add(testFile, (err, res) => {
3433
expect(err).to.not.exist()
35-
3634
expect(res).to.have.length(1)
37-
expect(res[0].hash).to.equal(expectedMultihash)
38-
expect(res[0].path).to.equal(expectedMultihash)
35+
expect(res[0].hash).to.equal(testHash)
36+
expect(res[0].path).to.equal(testHash)
3937
done()
4038
})
4139
}
@@ -47,109 +45,130 @@ module.exports = (common) => {
4745

4846
describe('callback API', () => {
4947
// 1st, because ipfs.files.add pins automatically
50-
it('.rm', (done) => {
51-
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
52-
53-
ipfs.pin.rm(hash, { recursive: true }, (err, pinset) => {
48+
it('.ls type recursive', (done) => {
49+
ipfs.pin.ls({ type: 'recursive' }, (err, pinset) => {
5450
expect(err).to.not.exist()
55-
expect(pinset).to.exist()
56-
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
57-
expect(err).to.not.exist()
58-
expect(pinset).to.be.empty()
59-
done()
51+
expect(pinset).to.deep.include({
52+
hash: testHash,
53+
type: 'recursive'
6054
})
55+
done()
6156
})
6257
})
6358

64-
it('.add', (done) => {
65-
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
66-
67-
ipfs.pin.add(hash, { recursive: false }, (err, pinset) => {
59+
it.skip('.ls type indirect', (done) => {
60+
ipfs.pin.ls({ type: 'indirect' }, (err, pinset) => {
6861
expect(err).to.not.exist()
69-
expect(pinset[0]).to.be.equal(hash)
62+
// because the pinned file has no links
63+
expect(pinset).to.be.empty()
7064
done()
7165
})
7266
})
7367

74-
it('.ls', (done) => {
75-
ipfs.pin.ls((err, pinset) => {
68+
it('.rm', (done) => {
69+
ipfs.pin.rm(testHash, { recursive: true }, (err, pinset) => {
7670
expect(err).to.not.exist()
77-
expect(pinset).to.not.be.empty()
78-
done()
71+
expect(pinset).to.deep.equal([{
72+
hash: testHash
73+
}])
74+
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
75+
expect(err).to.not.exist()
76+
expect(pinset).to.not.deep.include({
77+
hash: testHash,
78+
type: 'recursive'
79+
})
80+
done()
81+
})
7982
})
8083
})
8184

82-
it('.ls type direct', (done) => {
83-
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
85+
it('.add', (done) => {
86+
ipfs.pin.add(testHash, { recursive: false }, (err, pinset) => {
8487
expect(err).to.not.exist()
85-
expect(pinset).to.not.be.empty()
88+
expect(pinset).to.deep.equal([{
89+
hash: testHash
90+
}])
8691
done()
8792
})
8893
})
8994

90-
it('.ls type indirect', (done) => {
91-
ipfs.pin.ls({ type: 'indirect' }, (err, pinset) => {
95+
it('.ls', (done) => {
96+
ipfs.pin.ls((err, pinset) => {
9297
expect(err).to.not.exist()
9398
expect(pinset).to.not.be.empty()
99+
expect(pinset).to.deep.include({
100+
hash: testHash,
101+
type: 'direct'
102+
})
94103
done()
95104
})
96105
})
97106

98-
it('.ls type recursive', (done) => {
99-
ipfs.pin.ls({ type: 'recursive' }, (err, pinset) => {
107+
it('.ls type direct', (done) => {
108+
ipfs.pin.ls({ type: 'direct' }, (err, pinset) => {
100109
expect(err).to.not.exist()
101-
expect(pinset).to.not.be.empty()
110+
expect(pinset).to.deep.include({
111+
hash: testHash,
112+
type: 'direct'
113+
})
102114
done()
103115
})
104116
})
105117

106118
it('.ls for a specific hash', (done) => {
107-
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
108-
109-
ipfs.pin.ls(hash, (err, pinset) => {
119+
ipfs.pin.ls(testHash, (err, pinset) => {
110120
expect(err).to.not.exist()
111-
expect(pinset).to.exist()
121+
expect(pinset).to.deep.equal([{
122+
hash: testHash,
123+
type: 'direct'
124+
}])
112125
done()
113126
})
114127
})
115128
})
116129

117130
describe('promise API', () => {
118131
it('.add', () => {
119-
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
120-
121-
return ipfs.pin.add(hash, { recursive: false })
132+
return ipfs.pin.add(testHash, { recursive: false })
122133
.then((pinset) => {
123-
expect(pinset[0]).to.be.equal(hash)
134+
expect(pinset).to.deep.equal([{
135+
hash: testHash
136+
}])
124137
})
125138
})
126139

127140
it('.ls', () => {
128141
return ipfs.pin.ls()
129142
.then((pinset) => {
130-
expect(pinset).to.exist()
131-
expect(pinset).to.not.be.empty()
143+
expect(pinset).to.deep.include({
144+
hash: testHash,
145+
type: 'direct'
146+
})
132147
})
133148
})
134149

135150
it('.ls hash', () => {
136-
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
137-
138-
return ipfs.pin.ls(hash)
151+
return ipfs.pin.ls(testHash)
139152
.then((pinset) => {
140-
expect(pinset).to.exist()
153+
expect(pinset).to.deep.equal([{
154+
hash: testHash,
155+
type: 'direct'
156+
}])
141157
})
142158
})
143159

144160
it('.rm', () => {
145-
const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
146-
147-
return ipfs.pin.rm(hash, { recursive: false })
161+
return ipfs.pin.rm(testHash, { recursive: false })
148162
.then((pinset) => {
163+
expect(pinset).to.deep.equal([{
164+
hash: testHash
165+
}])
149166
return ipfs.pin.ls({ type: 'direct' })
150167
})
151168
.then((pinset) => {
152-
expect(pinset).to.be.empty()
169+
expect(pinset).to.not.deep.include({
170+
hash: testHash
171+
})
153172
})
154173
})
155174
})

0 commit comments

Comments
 (0)