Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Tests for links as hashes #3

Merged
merged 4 commits into from
Apr 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 66 additions & 21 deletions test/ipld-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,75 @@ module.exports = (repo) => {
})
})

it('resolves two linked objects', (done) => {
const file = {
name: 'world.txt',
size: 12
describe('links are hashes', () => {
const aliceName = 'Alice'
const aliceAbout = {
age: 22
}
const bob = {
name: 'Bob'
}
const dir = {
name: 'hello',
files: [
{'@link': ipld.multihash(ipld.marshal(file))}
]
const alice = {
name: {
'@link': ipld.multihash(aliceName)
},
about: {
'@link': ipld.multihash(ipld.marshal(aliceAbout))
},
friends: [{
'@link': ipld.multihash(ipld.marshal(bob))
}]
}
const mh = ipld.multihash(ipld.marshal(alice))

before((done) => {
async.series([
(cb) => ipldService.add(aliceName, cb),
(cb) => ipldService.add(aliceAbout, cb),
(cb) => ipldService.add(alice, cb),
(cb) => ipldService.add(bob, cb)
], done)
})

async.series([
(cb) => ipldService.add(file, cb),
(cb) => ipldService.add(dir, cb),
(cb) => {
const mh = ipld.multihash(ipld.marshal(dir))
resolve(ipldService, `${mh}/files/0/name`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql('world.txt')
cb()
})
}
], done)
it('resolves link to string', (done) => {
resolve(ipldService, `${mh}/name`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(aliceName)
done()
})
})

it('resolves link to object', (done) => {
resolve(ipldService, `${mh}/about`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(aliceAbout)
done()
})
})

it('resolves link to property in a different object', (done) => {
resolve(ipldService, `${mh}/about/age`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(aliceAbout.age)
done()
})
})

it('resolves link to an element in array', (done) => {
resolve(ipldService, `${mh}/friends/0`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(bob)
done()
})
})

it('resolves link to property in an element in array', (done) => {
resolve(ipldService, `${mh}/friends/0/name`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(bob.name)
done()
})
})
})
})
}