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

test(dag): ensure dag.put can be called without options #316

Merged
merged 3 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion SPEC/DAG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
##### `JavaScript` - ipfs.dag.put(dagNode, options, callback)

- `dagNode` - a DAG node that follows one of the supported IPLD formats.
- `options` - a object that might contain the follwing values:
- `options` - a object that might contain the following values:
- `format` - The IPLD format multicodec.
- `hashAlg` - The hash algorithm to be used over the serialized dagNode.
- or
- `cid` - the CID of the node passed.
- or
- if no `options` are given, `ipfs.dag.put()` uses the following defaults:
- `format: 'dag-cbor'`
- `hashAlg: 'sha2-256'`
- **Note** - You should only pass the CID or the format + hashAlg pair and not both
- `callback` must follow `function (err, cid) {}` signature, where `err` is an error if the operation was not successful and CID is the CID generated through the process or the one that was passed

Expand Down
14 changes: 14 additions & 0 deletions js/src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const dagPB = require('ipld-dag-pb')
const DAGNode = dagPB.DAGNode
const dagCBOR = require('ipld-dag-cbor')
const CID = require('cids')
const multihash = require('multihashes')
const { spawnNodeWithId } = require('../utils/spawn')
const { getDescribe, getIt, expect } = require('../utils/mocha')

Expand Down Expand Up @@ -113,6 +114,19 @@ module.exports = (createCommon, options) => {
})
})

it('should not fail when calling put without options', (done) => {
ipfs.dag.put(cborNode, done)
})

it('should set defaults when calling put without options', (done) => {
ipfs.dag.put(cborNode, (err, cid) => {
expect(err).to.not.exist()
expect(cid.codec).to.equal('dag-cbor')
expect(multihash.decode(cid.multihash).name).to.equal('sha2-256')
done()
})
})

it.skip('should put by passing the cid instead of format and hashAlg', (done) => {})

// TODO it.skip('Promises support', (done) => {})
Expand Down