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

Adding more tests on single object resolve #2

Merged
merged 1 commit into from
Apr 8, 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
71 changes: 63 additions & 8 deletions test/ipld-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,75 @@ module.exports = (repo) => {
})

describe('resolve', () => {
it('resolves inside a single object', (done) => {
describe('inside a single object', (done) => {
const node = {
hello: {
world: 11,
some: 12
string: 'hello',
number: 42,
object: {
title: 'world'
},
numbers: [0, 1, 2],
objects: [{
title: 'test'
}],
multiple: {
levels: {
down: 'all good!'
}
}
}
const mh = ipld.multihash(ipld.marshal(node))
ipldService.add(node, (err) => {
expect(err).to.not.exist

resolve(ipldService, `${mh}/hello/world`, (err, res) => {
before((done) => {
ipldService.add(node, done)
})

it('resolves direct leaves of type string', (done) => {
resolve(ipldService, `${mh}/string`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql('hello')
done()
})
})

it('resolves direct leaves of type number', (done) => {
resolve(ipldService, `${mh}/number`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(42)
done()
})
})

it('resolves direct leaves of type object', (done) => {
resolve(ipldService, `${mh}/object`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql({
title: 'world'
})
done()
})
})

it('resolves subpaths', (done) => {
resolve(ipldService, `${mh}/multiple/levels/down`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql('all good!')
done()
})
})

it('resolves arrays of primitives', (done) => {
resolve(ipldService, `${mh}/numbers/1`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(1)
done()
})
})

it('resolves arrays of objects', (done) => {
resolve(ipldService, `${mh}/objects/0/title`, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql(11)
expect(res).to.be.eql('test')
done()
})
})
Expand Down