diff --git a/src/miscellaneous/resolve.js b/src/miscellaneous/resolve.js index 50864bae..e613ef07 100644 --- a/src/miscellaneous/resolve.js +++ b/src/miscellaneous/resolve.js @@ -88,17 +88,41 @@ module.exports = (createCommon, options) => { }) }) - it('should not resolve an IPFS path non-link', (done) => { + it('should resolve up to the last node', (done) => { const content = { path: { to: { file: hat() } } } const options = { format: 'dag-cbor', hashAlg: 'sha2-256' } ipfs.dag.put(content, options, (err, cid) => { expect(err).to.not.exist() - const path = `/ipfs/${cid.toBaseEncodedString()}/path/to/file` - ipfs.resolve(path, (err, path) => { - expect(err).to.exist() - expect(err.message).to.equal('found non-link at given path') + const path = `/ipfs/${cid}/path/to/file` + ipfs.resolve(path, (err, resolved) => { + expect(err).to.not.exist() + expect(resolved).to.equal(path) + done() + }) + }) + }) + + it('should resolve up to the last node across multiple nodes', (done) => { + const options = { format: 'dag-cbor', hashAlg: 'sha2-256' } + + waterfall([ + cb => { + const content = { node: { with: { file: hat() } } } + ipfs.dag.put(content, options, cb) + }, + (childCid, cb) => { + const content = { path: { to: childCid } } + ipfs.dag.put(content, options, (err, parentCid) => cb(err, { childCid, parentCid })) + } + ], (err, res) => { + expect(err).to.not.exist() + + const path = `/ipfs/${res.parentCid}/path/to/node/with/file` + ipfs.resolve(path, (err, resolved) => { + expect(err).to.not.exist() + expect(resolved).to.equal(`/ipfs/${res.childCid}/node/with/file`) done() }) })