This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
rm-link.js
87 lines (71 loc) · 2.66 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* eslint-env mocha */
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import * as dagPB from '@ipld/dag-pb'
import { CID } from 'multiformats/cid'
import { sha256 } from 'multiformats/hashes/sha2'
import { expect } from 'aegir/chai'
import { getDescribe, getIt } from '../../utils/mocha.js'
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {object} options
*/
export function testRmLink (factory, options) {
const describe = getDescribe(options)
const it = getIt(options)
describe('.object.patch.rmLink', function () {
this.timeout(80 * 1000)
/** @type {import('ipfs-core-types').IPFS} */
let ipfs
before(async () => {
ipfs = (await factory.spawn()).api
})
after(() => factory.clean())
it('should remove a link from an existing node', async () => {
const obj1 = {
Data: uint8ArrayFromString('patch test object 1'),
Links: []
}
const obj2 = {
Data: uint8ArrayFromString('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 childBuf = dagPB.encode(child)
const childAsDAGLink = {
Name: 'my-link',
Tsize: childBuf.length,
Hash: CID.createV0(await sha256.digest(childBuf))
}
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', () => {
// @ts-expect-error invalid arg
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', () => {
// @ts-expect-error invalid arg
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'
// @ts-expect-error invalid arg
return expect(ipfs.object.patch.rmLink(root, link)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})
})
}