mirror of
https://github.com/Permissionless-Software-Foundation/psf-bch-api.git
synced 2026-09-21 16:52:00 -07:00
108 lines
3.3 KiB
JavaScript
108 lines
3.3 KiB
JavaScript
/*
|
|
Unit tests for RESTControllers index.
|
|
*/
|
|
|
|
import { assert } from 'chai'
|
|
import sinon from 'sinon'
|
|
|
|
import RESTControllers from '../../../src/controllers/rest-api/index.js'
|
|
import BlockchainRouter from '../../../src/controllers/rest-api/full-node/blockchain/index.js'
|
|
import ControlRouter from '../../../src/controllers/rest-api/full-node/control/index.js'
|
|
import DSProofRouter from '../../../src/controllers/rest-api/full-node/dsproof/index.js'
|
|
import MiningRouter from '../../../src/controllers/rest-api/full-node/mining/index.js'
|
|
|
|
describe('#controllers/rest-api/index.js', () => {
|
|
let sandbox
|
|
let mockAdapters
|
|
let mockUseCases
|
|
|
|
const createBlockchainUseCaseStubs = () => ({
|
|
getBestBlockHash: () => {},
|
|
getBlockchainInfo: () => {},
|
|
getBlockCount: () => {},
|
|
getBlockHeader: () => {},
|
|
getBlockHeaders: () => {},
|
|
getChainTips: () => {},
|
|
getDifficulty: () => {},
|
|
getMempoolEntry: () => {},
|
|
getMempoolEntries: () => {},
|
|
getMempoolAncestors: () => {},
|
|
getMempoolInfo: () => {},
|
|
getRawMempool: () => {},
|
|
getTxOut: () => {},
|
|
getTxOutProof: () => {},
|
|
getTxOutProofs: () => {},
|
|
verifyTxOutProof: () => {},
|
|
verifyTxOutProofs: () => {},
|
|
getBlock: () => {},
|
|
getBlockHash: () => {}
|
|
})
|
|
|
|
beforeEach(() => {
|
|
sandbox = sinon.createSandbox()
|
|
mockAdapters = {
|
|
fullNode: {
|
|
validateArraySize: sandbox.stub().returns(true)
|
|
}
|
|
}
|
|
mockUseCases = {
|
|
blockchain: createBlockchainUseCaseStubs(),
|
|
control: {
|
|
getNetworkInfo: () => {}
|
|
},
|
|
dsproof: {
|
|
getDSProof: () => {}
|
|
},
|
|
mining: {
|
|
getMiningInfo: () => {},
|
|
getNetworkHashPS: () => {}
|
|
}
|
|
}
|
|
})
|
|
|
|
afterEach(() => {
|
|
sandbox.restore()
|
|
})
|
|
|
|
describe('#constructor()', () => {
|
|
it('should require adapters instance', () => {
|
|
assert.throws(() => {
|
|
// eslint-disable-next-line no-new
|
|
new RESTControllers({ useCases: mockUseCases })
|
|
}, /Adapters library required/)
|
|
})
|
|
|
|
it('should require useCases instance', () => {
|
|
assert.throws(() => {
|
|
// eslint-disable-next-line no-new
|
|
new RESTControllers({ adapters: mockAdapters })
|
|
}, /Use Cases library required/)
|
|
})
|
|
})
|
|
|
|
describe('#attachRESTControllers()', () => {
|
|
it('should instantiate routers and attach to app', () => {
|
|
const blockchainAttachStub = sandbox.stub(BlockchainRouter.prototype, 'attach')
|
|
const controlAttachStub = sandbox.stub(ControlRouter.prototype, 'attach')
|
|
const dsproofAttachStub = sandbox.stub(DSProofRouter.prototype, 'attach')
|
|
const miningAttachStub = sandbox.stub(MiningRouter.prototype, 'attach')
|
|
const restControllers = new RESTControllers({
|
|
adapters: mockAdapters,
|
|
useCases: mockUseCases
|
|
})
|
|
const app = {}
|
|
|
|
restControllers.attachRESTControllers(app)
|
|
|
|
assert.isTrue(blockchainAttachStub.calledOnce)
|
|
assert.equal(blockchainAttachStub.getCall(0).args[0], app)
|
|
assert.isTrue(controlAttachStub.calledOnce)
|
|
assert.equal(controlAttachStub.getCall(0).args[0], app)
|
|
assert.isTrue(dsproofAttachStub.calledOnce)
|
|
assert.equal(dsproofAttachStub.getCall(0).args[0], app)
|
|
assert.isTrue(miningAttachStub.calledOnce)
|
|
assert.equal(miningAttachStub.getCall(0).args[0], app)
|
|
})
|
|
})
|
|
})
|