Got existing unit tests passing

This commit is contained in:
Chris Troutner
2021-11-26 13:17:16 -08:00
parent ab5aa94353
commit 52ca71ec16
9 changed files with 28 additions and 13 deletions
+1 -1
View File
@@ -178,7 +178,7 @@ class IpfsCoordAdapter {
// It passes the data on to the REST API library by emitting an event.
peerInputHandler (data) {
try {
console.log('peerInputHandler triggered with this data: ', data)
// console.log('peerInputHandler triggered with this data: ', data)
this.eventEmitter.emit('rpcData', data)
} catch (err) {
+3 -2
View File
@@ -62,6 +62,7 @@ class JSONRPC {
// Attempt to parse the incoming data as a JSON RPC string.
const parsedData = _this.jsonrpc.parse(str)
// wlogger.debug(`parsedData: ${JSON.stringify(parsedData, null, 2)}`)
// console.log(`parsedData; ${JSON.stringify(parsedData, null, 2)}`)
// Exit quietly if the incoming string is an invalid JSON RPC string.
if (parsedData.type === 'invalid') {
@@ -71,7 +72,7 @@ class JSONRPC {
// Check for duplicate entries with same 'id' value.
const alreadyProcessed = _this._checkIfAlreadyProcessed(parsedData)
console.log(`alreadyProcessed: ${alreadyProcessed}`)
// console.log(`alreadyProcessed: ${alreadyProcessed}`)
if (alreadyProcessed) {
return false
} else {
@@ -93,7 +94,7 @@ class JSONRPC {
// Log the incoming JSON RPC command.
wlogger.info(
`JSON RPC received from ${from}, ID: ${parsedData.payload.id}, type: ${parsedData.type}, method: ${parsedData.payload.method}`
`JSON RPC received from ${from}, ID: ${parsedData.payload.id}, type: ${parsedData.type}`
)
}
+3 -3
View File
@@ -80,7 +80,7 @@ class BchUseCases {
// Get the BCH balance for an array of addresses.
async getBalances (addrs) {
try {
console.log('addrs: ', addrs)
// console.log('addrs: ', addrs)
// Throw an error if this IPFS node has not yet made a connection to a
// wallet service provider.
@@ -100,7 +100,7 @@ class BchUseCases {
// Generate a JSON RPC command.
const cmd = this.jsonrpc.request(rpcId, 'bch', rpcData)
const cmdStr = JSON.stringify(cmd)
console.log('cmdStr: ', cmdStr)
// console.log('cmdStr: ', cmdStr)
// Send the RPC command to selected wallet service.
const thisNode = this.adapters.ipfs.ipfsCoordAdapter.ipfsCoord.thisNode
@@ -137,7 +137,7 @@ class BchUseCases {
// Loop that waits for a response from the service provider.
do {
console.log(`this.rpcDataQueue.length: ${this.rpcDataQueue.length}`)
// console.log(`this.rpcDataQueue.length: ${this.rpcDataQueue.length}`)
for (let i = 0; i < this.rpcDataQueue.length; i++) {
const rawData = this.rpcDataQueue[i]
// console.log(`rawData: ${JSON.stringify(rawData, null, 2)}`)
+3 -2
View File
@@ -13,7 +13,8 @@ const context = {}
const UserController = require('../../../src/controllers/rest-api/users/controller')
const Adapters = require('../../../src/adapters')
const adapters = new Adapters()
const EventEmitter = require('events')
const adapters = new Adapters({ eventEmitter: new EventEmitter() })
const UseCases = require('../../../src/use-cases/')
let uut
let sandbox
@@ -50,7 +51,7 @@ describe('Users', () => {
})
beforeEach(() => {
const useCases = new UseCases({ adapters })
const useCases = new UseCases({ adapters, eventEmitter: new EventEmitter() })
uut = new UserController({ adapters, useCases })
sandbox = sinon.createSandbox()
@@ -8,6 +8,7 @@ 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')
const EventEmitter = require('events')
describe('#IPFS', () => {
let uut
@@ -15,7 +16,7 @@ describe('#IPFS', () => {
beforeEach(() => {
const ipfs = IPFSMock.create()
uut = new IPFSCoordAdapter({ ipfs })
uut = new IPFSCoordAdapter({ ipfs, eventEmitter: new EventEmitter() })
sandbox = sinon.createSandbox()
})
@@ -8,13 +8,14 @@ const sinon = require('sinon')
const IPFSLib = require('../../../src/adapters/ipfs')
const IPFSMock = require('../mocks/ipfs-mock')
const IPFSCoordMock = require('../mocks/ipfs-coord-mock')
const EventEmitter = require('events')
describe('#IPFS-adapter-index', () => {
let uut
let sandbox
beforeEach(() => {
uut = new IPFSLib()
uut = new IPFSLib({ eventEmitter: new EventEmitter() })
sandbox = sinon.createSandbox()
})
+10 -1
View File
@@ -74,10 +74,17 @@ describe('#JSON RPC', () => {
})
it('should return default response if routing is not possible', async () => {
// Force desired code path
// sandbox
// .stub(uut.adapters.ipfs.ipfsCoordAdapter, 'peerInputHandler')
// .returns()
// uut.adapters.ipfs.ipfsCoordAdapter.peer
const id = uid()
const json = jsonrpc.request(id, 'unknownMethod', {})
const str = JSON.stringify(json)
// console.log(`str: ${str}`)
const result = await uut.router(str, 'peerA')
// console.log('result: ', result)
@@ -204,7 +211,9 @@ describe('#JSON RPC', () => {
// Force the RPC type to be 'success', to indicate an RPC that was
// processed internal to ipfs-coord.
sandbox.stub(uut.jsonrpc, 'parse').returns({
payload: {},
payload: {
id: 'metrics5323'
},
type: 'success'
})
+2 -1
View File
@@ -13,7 +13,8 @@ const ipfs = {
sendPrivateMessage: () => {}
}
}
}
},
peerInputHandler: () => {}
}
}
+2 -1
View File
@@ -5,6 +5,7 @@
// Public npm libraries
const assert = require('chai').assert
const sinon = require('sinon')
const EventEmitter = require('events')
// Local support libraries
// const testUtils = require('../../utils/test-utils')
@@ -25,7 +26,7 @@ describe('#use-cases', () => {
beforeEach(() => {
sandbox = sinon.createSandbox()
uut = new UseCases({ adapters })
uut = new UseCases({ adapters, eventEmitter: new EventEmitter() })
})
afterEach(() => sandbox.restore())