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

Commit a9045f7

Browse files
committed
test: add test for Object.links with CBOR
1 parent 369f0d3 commit a9045f7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/object/links.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,42 @@ module.exports = (createCommon, options) => {
209209
})
210210
})
211211
})
212+
213+
it('should get links from CBOR object', (done) => {
214+
const hashes = []
215+
ipfs.add(Buffer.from('test data'), (err, res1) => {
216+
expect(err).to.not.exist()
217+
hashes.push(res1[0].hash)
218+
ipfs.add(Buffer.from('more test data'), (err, res2) => {
219+
hashes.push(res2[0].hash)
220+
expect(err).to.not.exist()
221+
const obj = {
222+
some: 'data',
223+
mylink: { '/': hashes[0] },
224+
myobj: {
225+
anotherLink: { '/': hashes[1] }
226+
}
227+
}
228+
ipfs.dag.put(obj, (err, cid) => {
229+
expect(err).to.not.exist()
230+
ipfs.object.links(cid, (err, links) => {
231+
expect(err).to.not.exist()
232+
expect(links.length).to.eql(2)
233+
234+
// TODO: js-ipfs succeeds but go returns empty strings for link name
235+
// const names = [links[0].name, links[1].name]
236+
// expect(names).includes('mylink')
237+
// expect(names).includes('myobj/anotherLink')
238+
239+
const cids = [links[0].cid.toString(), links[1].cid.toString()]
240+
expect(cids).includes(hashes[0])
241+
expect(cids).includes(hashes[1])
242+
243+
done()
244+
})
245+
})
246+
})
247+
})
248+
})
212249
})
213250
}

0 commit comments

Comments
 (0)