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'
|
2024-03-22 12:30:45 -07:00
|
|
|
import { assert } from 'chai'
|
2021-07-13 12:34:51 -07:00
|
|
|
|
2022-09-08 08:58:39 -07:00
|
|
|
import Controllers from '../../../src/controllers/index.js'
|
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-07-25 16:49:01 -07:00
|
|
|
|
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 () => {
|
2021-08-23 17:06:20 -07:00
|
|
|
// 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
|
|
|
|
2023-02-25 06:09:56 -08: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-07-31 15:55:47 -07:00
|
|
|
|
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
|
|
|
|
2021-07-31 15:55:47 -07:00
|
|
|
const app = {
|
2021-09-08 12:35:26 -07:00
|
|
|
use: () => {}
|
|
|
|
|
}
|
2021-07-31 15:55:47 -07:00
|
|
|
|
2021-09-08 12:35:26 -07:00
|
|
|
await uut.attachControllers(app)
|
2021-07-31 15:55:47 -07:00
|
|
|
|
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
|
|
|
})
|
|
|
|
|
})
|
2025-06-27 20:11:27 -04:00
|
|
|
describe('#attachRESTControllers', () => {
|
|
|
|
|
it('should attach the controllers', async () => {
|
|
|
|
|
const app = {
|
|
|
|
|
use: () => {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await uut.attachRESTControllers(app)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
describe('#initAdapters', () => {
|
|
|
|
|
it('should attach the controllers', async () => {
|
|
|
|
|
sandbox.stub(uut.adapters, 'start').resolves({})
|
|
|
|
|
await uut.initAdapters()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
describe('#initUseCases', () => {
|
|
|
|
|
it('should attach the controllers', async () => {
|
|
|
|
|
sandbox.stub(uut.useCases, 'start').resolves({})
|
|
|
|
|
await uut.initUseCases()
|
|
|
|
|
})
|
|
|
|
|
})
|
2021-09-08 12:35:26 -07:00
|
|
|
})
|