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

Commit 011c417

Browse files
0x-r4bbitalanshaw
authored andcommitted
test(dag): ensure dag.put can be called without options (#316)
* test(dag): introduce test that ensure `dag.put` can be called without options As discussed in ipfs/js-ipfs#1415 (comment) * chore(SPEC/DAG): update DAG spec to cover optional `options` argument License: MIT Signed-off-by: Pascal Precht <[email protected]> * test: add test to ensure defaults are set License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent c47c4ce commit 011c417

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

SPEC/DAG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
##### `JavaScript` - ipfs.dag.put(dagNode, options, callback)
1616

1717
- `dagNode` - a DAG node that follows one of the supported IPLD formats.
18-
- `options` - a object that might contain the follwing values:
18+
- `options` - a object that might contain the following values:
1919
- `format` - The IPLD format multicodec.
2020
- `hashAlg` - The hash algorithm to be used over the serialized dagNode.
2121
- or
2222
- `cid` - the CID of the node passed.
23+
- or
24+
- if no `options` are given, `ipfs.dag.put()` uses the following defaults:
25+
- `format: 'dag-cbor'`
26+
- `hashAlg: 'sha2-256'`
2327
- **Note** - You should only pass the CID or the format + hashAlg pair and not both
2428
- `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
2529

js/src/dag/put.js

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const dagPB = require('ipld-dag-pb')
55
const DAGNode = dagPB.DAGNode
66
const dagCBOR = require('ipld-dag-cbor')
77
const CID = require('cids')
8+
const multihash = require('multihashes')
89
const { spawnNodeWithId } = require('../utils/spawn')
910
const { getDescribe, getIt, expect } = require('../utils/mocha')
1011

@@ -95,6 +96,19 @@ module.exports = (createCommon, options) => {
9596
})
9697
})
9798

99+
it('should not fail when calling put without options', (done) => {
100+
ipfs.dag.put(cborNode, done)
101+
})
102+
103+
it('should set defaults when calling put without options', (done) => {
104+
ipfs.dag.put(cborNode, (err, cid) => {
105+
expect(err).to.not.exist()
106+
expect(cid.codec).to.equal('dag-cbor')
107+
expect(multihash.decode(cid.multihash).name).to.equal('sha2-256')
108+
done()
109+
})
110+
})
111+
98112
it.skip('should put by passing the cid instead of format and hashAlg', (done) => {})
99113

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

0 commit comments

Comments
 (0)