Files
ipfs-bch-wallet-service/test/unit/adapters/ipfs-coord.adapter.unit.js
T

97 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-07-13 12:34:51 -07:00
/*
Unit tests for the IPFS Adapter.
*/
const assert = require('chai').assert
const sinon = require('sinon')
const IPFSCoordAdapter = require('../../../src/adapters/ipfs/ipfs-coord')
const IPFSMock = require('../mocks/ipfs-mock')
const IPFSCoordMock = require('../mocks/ipfs-coord-mock')
describe('#IPFS', () => {
let uut
let sandbox
beforeEach(() => {
const ipfs = IPFSMock.create()
2021-07-16 18:51:38 -07:00
const bchjs = {}
uut = new IPFSCoordAdapter({ ipfs, bchjs })
2021-07-13 12:34:51 -07:00
sandbox = sinon.createSandbox()
})
afterEach(() => sandbox.restore())
describe('#constructor', () => {
it('should throw an error if ipfs instance is not included', () => {
try {
uut = new IPFSCoordAdapter()
assert.fail('Unexpected code path')
} catch (err) {
assert.include(
err.message,
'Instance of IPFS must be passed when instantiating ipfs-coord.'
2021-07-16 18:51:38 -07:00
)
}
})
it('should throw an error if bchjs instance is not included', () => {
try {
const ipfs = IPFSMock.create()
uut = new IPFSCoordAdapter({ ipfs })
assert.fail('Unexpected code path')
} catch (err) {
assert.include(
err.message,
'Instance of bch-js must be passed when instantiating ipfs-coord.'
2021-07-13 12:34:51 -07:00
)
}
})
})
describe('#start', () => {
it('should return a promise that resolves into an instance of IPFS.', async () => {
// Mock dependencies.
uut.IpfsCoord = IPFSCoordMock
const result = await uut.start()
// console.log('result: ', result)
assert.equal(result, true)
})
})
describe('#attachRPCRouter', () => {
it('should attached a router output', async () => {
// Mock dependencies
uut.ipfsCoord = {
privateLog: {},
ipfs: {
orbitdb: {
privateLog: {}
}
}
}
const router = console.log
uut.attachRPCRouter(router)
})
it('should throw an error if ipfs-coord has not been instantiated', () => {
try {
const router = console.log
uut.attachRPCRouter(router)
assert.fail('Unexpected code path')
} catch (err) {
assert.include(err.message, 'Cannot read property')
}
})
})
})