Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into remove-cid-property…
Browse files Browse the repository at this point in the history
…-from-dagnodes
  • Loading branch information
achingbrain committed Nov 6, 2018
2 parents 74adf4a + 3a8fb79 commit 9d18c51
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test:browser": "aegir test --target browser",
"test:node": "aegir test --target node",
"lint": "aegir lint",
"lint-commits": "aegir lint-commits",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
Expand All @@ -17,6 +18,7 @@
"coverage-publish": "aegir coverage publish"
},
"pre-push": [
"lint-commits",
"lint",
"test"
],
Expand Down
97 changes: 97 additions & 0 deletions test/util.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* eslint-env mocha */

'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const {
DAGLink
} = require('../src')
const {
serialize,
deserialize
} = require('../src/util')

describe('util', () => {
it('should serialize an empty node', (done) => {
serialize({}, (error, result) => {
expect(error).to.not.exist()
expect(result).to.be.an.instanceof(Buffer)
expect(result).to.be.empty()
done()
})
})

it('should serialize a node with data', (done) => {
const data = Buffer.from([0, 1, 2, 3])
serialize({
data
}, (error, result) => {
expect(error).to.not.exist()
expect(result).to.be.an.instanceof(Buffer)

deserialize(result, (error, node) => {
expect(error).to.not.exist()
expect(node.data).to.deep.equal(data)

done()
})
})
})

it('should serialize a node with links', (done) => {
const links = [
new DAGLink('', 0, 'QmWDtUQj38YLW8v3q4A6LwPn4vYKEbuKWpgSm6bjKW6Xfe')
]
serialize({
links
}, (error, result) => {
expect(error).to.not.exist()
expect(result).to.be.an.instanceof(Buffer)

deserialize(result, (error, node) => {
expect(error).to.not.exist()
expect(node.links).to.deep.equal(links)

done()
})
})
})

it('should serialize a node with links as plain objects', (done) => {
const links = [{
name: '',
size: 0,
hash: 'QmWDtUQj38YLW8v3q4A6LwPn4vYKEbuKWpgSm6bjKW6Xfe'
}]
serialize({
links
}, (error, result) => {
expect(error).to.not.exist()
expect(result).to.be.an.instanceof(Buffer)

deserialize(result, (error, node) => {
expect(error).to.not.exist()
expect(node.links).to.deep.equal([
new DAGLink('', 0, 'QmWDtUQj38YLW8v3q4A6LwPn4vYKEbuKWpgSm6bjKW6Xfe')
])

done()
})
})
})

it('should ignore invalid properties when serializing', (done) => {
serialize({
foo: 'bar'
}, (error, result) => {
expect(error).to.not.exist()
expect(result).to.be.an.instanceof(Buffer)
expect(result).to.be.empty()
done()
})
})
})

0 comments on commit 9d18c51

Please sign in to comment.