This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathrm-link.js
72 lines (57 loc) · 2.17 KB
/
rm-link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* eslint-env mocha */
'use strict'
const { getDescribe, getIt, expect } = require('../../utils/mocha')
const { asDAGLink } = require('../utils')
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
* @param {Factory} common
* @param {Object} options
*/
module.exports = (common, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.object.patch.rmLink', function () {
this.timeout(80 * 1000)
let ipfs
before(async () => {
ipfs = (await common.spawn()).api
})
after(() => common.clean())
it('should remove a link from an existing node', async () => {
const obj1 = {
Data: Buffer.from('patch test object 1'),
Links: []
}
const obj2 = {
Data: Buffer.from('patch test object 2'),
Links: []
}
const nodeCid = await ipfs.object.put(obj1)
const childCid = await ipfs.object.put(obj2)
const child = await ipfs.object.get(childCid)
const childAsDAGLink = await asDAGLink(child, 'my-link')
const parentCid = await ipfs.object.patch.addLink(nodeCid, childAsDAGLink)
const withoutChildCid = await ipfs.object.patch.rmLink(parentCid, childAsDAGLink)
expect(withoutChildCid).to.not.deep.equal(parentCid)
expect(withoutChildCid).to.deep.equal(nodeCid)
/* TODO: revisit this assertions.
const node = await ipfs.object.patch.rmLink(testNodeWithLinkMultihash, testLinkPlainObject)
expect(node.multihash).to.not.deep.equal(testNodeWithLinkMultihash)
*/
})
it('returns error for request without arguments', () => {
return expect(ipfs.object.patch.rmLink(null, null)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
it('returns error for request only one invalid argument', () => {
return expect(ipfs.object.patch.rmLink('invalid', null)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
it('returns error for request with invalid first argument', () => {
const root = ''
const link = 'foo'
return expect(ipfs.object.patch.rmLink(root, link)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
})
}