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

Commit ba4f788

Browse files
committed
test: add test for Object.links with CBOR
1 parent 50a4eda commit ba4f788

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
@@ -162,5 +162,42 @@ module.exports = (createCommon, options) => {
162162
})
163163
})
164164
})
165+
166+
it('should get links from CBOR object', (done) => {
167+
const hashes = []
168+
ipfs.add(Buffer.from('test data'), (err, res1) => {
169+
expect(err).to.not.exist()
170+
hashes.push(res1[0].hash)
171+
ipfs.add(Buffer.from('more test data'), (err, res2) => {
172+
hashes.push(res2[0].hash)
173+
expect(err).to.not.exist()
174+
const obj = {
175+
some: 'data',
176+
mylink: { '/': hashes[0] },
177+
myobj: {
178+
anotherLink: { '/': hashes[1] }
179+
}
180+
}
181+
ipfs.dag.put(obj, (err, cid) => {
182+
expect(err).to.not.exist()
183+
ipfs.object.links(cid, (err, links) => {
184+
expect(err).to.not.exist()
185+
expect(links.length).to.eql(2)
186+
187+
// TODO: js-ipfs succeeds but go returns empty strings for link name
188+
// const names = [links[0].name, links[1].name]
189+
// expect(names).includes('mylink')
190+
// expect(names).includes('myobj/anotherLink')
191+
192+
const cids = [links[0].cid.toString(), links[1].cid.toString()]
193+
expect(cids).includes(hashes[0])
194+
expect(cids).includes(hashes[1])
195+
196+
done()
197+
})
198+
})
199+
})
200+
})
201+
})
165202
})
166203
}

0 commit comments

Comments
 (0)