Files
ipfs-bch-wallet-service/test/unit/controllers/controllers.unit.js
T

67 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-07-13 12:34:51 -07:00
/*
Unit tests for controllers index.js file.
*/
// Public npm libraries
2022-09-08 08:58:39 -07:00
import sinon from 'sinon'
2021-07-13 12:34:51 -07:00
2022-09-08 08:58:39 -07:00
import Controllers from '../../../src/controllers/index.js'
2024-03-22 10:59:22 -07:00
const assert = require('chai').assert
2021-07-13 12:34:51 -07:00
2021-09-08 12:35:26 -07:00
describe('#Controllers', () => {
let uut
let sandbox
2021-07-13 12:34:51 -07:00
beforeEach(() => {
2021-09-08 12:35:26 -07:00
sandbox = sinon.createSandbox()
2021-09-08 12:35:26 -07:00
uut = new Controllers()
})
2021-07-13 12:34:51 -07:00
2021-09-08 12:35:26 -07:00
afterEach(() => sandbox.restore())
2021-07-13 12:34:51 -07:00
2021-09-08 12:35:26 -07:00
describe('#attachControllers', () => {
it('should attach the controllers', async () => {
// mock dependencies
// sandbox.stub(adapters.fullStackJwt, 'getJWT').resolves({})
// sandbox.stub(adapters.fullStackJwt, 'instanceBchjs').resolves({})
// sandbox.stub(adapters.ipfs, 'start').resolves({})
// adapters.ipfs.ipfsCoordAdapter = {
2021-09-08 12:35:26 -07:00
sandbox.stub(uut.adapters, 'start').resolves({})
2021-08-08 08:09:48 -07:00
uut.adapters.ipfs.ipfsCoordAdapter = {
2021-09-08 12:35:26 -07:00
attachRPCRouter: () => {}
}
2021-07-13 12:34:51 -07:00
// Mock the timer controllers
sandbox.stub(uut.timerControllers, 'startTimers').returns()
2021-07-13 12:34:51 -07:00
const app = {
2021-09-08 12:35:26 -07:00
use: () => {}
}
2021-07-13 12:34:51 -07:00
2021-09-08 12:35:26 -07:00
await uut.attachControllers(app)
2021-09-08 12:35:26 -07:00
assert.isOk(true, 'Not throwing an error is a success')
})
2021-07-17 10:06:29 -07:00
2021-09-08 12:35:26 -07:00
it('should catch and throw errors', async () => {
2021-07-17 10:06:29 -07:00
try {
// Force an error
2022-07-08 08:46:05 -07:00
sandbox.stub(uut, 'attachRPCControllers').throws(new Error('test error'))
2021-07-17 10:06:29 -07:00
const app = {
2021-09-08 12:35:26 -07:00
use: () => {}
}
2021-09-08 12:35:26 -07:00
await uut.attachControllers(app)
2021-09-08 12:35:26 -07:00
assert.fail('Unexpected code path')
2021-07-17 10:06:29 -07:00
} catch (err) {
// console.log('err.message: ', err.message)
2021-09-08 12:35:26 -07:00
assert.include(err.message, 'test error')
2021-07-17 10:06:29 -07:00
}
2021-09-08 12:35:26 -07:00
})
})
})