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

Add object.patch to the API #103

Merged
merged 2 commits into from
Nov 4, 2015
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
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ function IpfsAPI (host_or_multiaddr, port) {
},
data: argCommand('object/data'),
stat: argCommand('object/stat'),
links: argCommand('object/links')
links: argCommand('object/links'),
patch: function (file, opts, cb) {
return requestAPI('object/patch', [file].concat(opts), null, null, cb)
}
}

self.swarm = {
Expand Down
41 changes: 37 additions & 4 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ describe('IPFS Node.js API wrapper tests', function () {
})

describe('.object', function () {
var testObject =
Buffer(JSON.stringify({Data: 'testdata', Links: []}))
var testObjectHash =
'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD'
var testObject = Buffer(JSON.stringify({Data: 'testdata', Links: []}))
var testObjectHash = 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD'
var testPatchObject = Buffer(JSON.stringify({Data: 'new test data'}))
var testPatchObjectHash = 'QmWJDtdQWQSajQPx1UVAGWKaSGrHVWdjnrNhbooHP7LuF2'

it('object.put', function (done) {
apiClients['a'].object.put(testObject, 'json', function (err, res) {
Expand Down Expand Up @@ -448,6 +448,39 @@ describe('IPFS Node.js API wrapper tests', function () {
done()
})
})

it('object.patch', function (done) {
this.timeout(10000)
apiClients['a'].object.put(testPatchObject, 'json', function (err, res) {
if (err) {
throw err
}
apiClients['a'].object.patch(testObjectHash, ['add-link', 'next', testPatchObjectHash], function (err, res) {
if (err) {
throw err
}
var o = JSON.parse(res)
assert.deepEqual(o, {
Hash: 'QmZFdJ3CQsY4kkyQtjoUo8oAzsEs5BNguxBhp8sjQMpgkd',
Links: null
})
apiClients['a'].object.get(o.Hash, function (err, res) {
if (err) {
throw err
}
assert.deepEqual(JSON.parse(res), {
Data: 'testdata',
Links: [{
Name: 'next',
Hash: 'QmWJDtdQWQSajQPx1UVAGWKaSGrHVWdjnrNhbooHP7LuF2',
Size: 15
}]
})
done()
})
})
})
})
})

describe('.swarm', function () {
Expand Down