This repository was 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
/
Copy pathappend-data.js
54 lines (42 loc) · 1.54 KB
/
append-data.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
/* eslint-env mocha */
'use strict'
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
const { getDescribe, getIt, expect } = require('../../utils/mocha')
/**
* @typedef {import('ipfsd-ctl').Factory} Factory
*/
/**
* @param {Factory} factory
* @param {Object} options
*/
module.exports = (factory, options) => {
const describe = getDescribe(options)
const it = getIt(options)
describe('.object.patch.appendData', 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 append data to an existing node', async () => {
const obj = {
Data: uint8ArrayFromString('patch test object'),
Links: []
}
const nodeCid = await ipfs.object.put(obj)
const patchedNodeCid = await ipfs.object.patch.appendData(nodeCid, uint8ArrayFromString('append'))
expect(patchedNodeCid).to.not.deep.equal(nodeCid)
})
it('returns error for request without key & data', () => {
// @ts-expect-error invalid arg
return expect(ipfs.object.patch.appendData(null, null)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
})
it('returns error for request without data', () => {
const filePath = 'test/fixtures/test-data/badnode.json'
// @ts-expect-error invalid arg
return expect(ipfs.object.patch.appendData(null, filePath)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
})
})
}