From 74255309539064ac2f14a72659aca7b39dc77dbc Mon Sep 17 00:00:00 2001 From: shuse2 Date: Sat, 18 May 2019 21:45:38 +0200 Subject: [PATCH] Fix node status unit test --- .../src/modules/http_api/controllers/node.js | 7 +++--- .../unit/modules/http_api/controllers/node.js | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/framework/src/modules/http_api/controllers/node.js b/framework/src/modules/http_api/controllers/node.js index efbcbe57b4d..9bf46262b07 100644 --- a/framework/src/modules/http_api/controllers/node.js +++ b/framework/src/modules/http_api/controllers/node.js @@ -44,6 +44,7 @@ function NodeController(scope) { components: { storage: scope.components.storage, cache: scope.components.cache, + logger: scope.components.logger, }, config: scope.config, channel: scope.channel, @@ -354,10 +355,10 @@ async function getConfirmedTransactionCount() { } return confirmed; } catch (error) { - library.logger.warn("Transaction count wasn't cached", error); + library.components.logger.warn("Transaction count wasn't cached", error); } } - const confirmed = await library.storage.entities.Transaction.count(); + const confirmed = await library.components.storage.entities.Transaction.count(); // only update cache if ready if (library.components.cache.cacheReady) { try { @@ -369,7 +370,7 @@ async function getConfirmedTransactionCount() { ); } catch (error) { // Ignore error and just put warn - library.logger.warn("Transaction count wasn't cached", error); + library.components.logger.warn("Transaction count wasn't cached", error); } } return confirmed; diff --git a/framework/test/mocha/unit/modules/http_api/controllers/node.js b/framework/test/mocha/unit/modules/http_api/controllers/node.js index 7f14261d16f..50ff4e1bf6c 100644 --- a/framework/test/mocha/unit/modules/http_api/controllers/node.js +++ b/framework/test/mocha/unit/modules/http_api/controllers/node.js @@ -21,9 +21,13 @@ const NodeController = rewire( ); describe('node/api', () => { + const confirmedTransactions = 10; + let library; let privateLibrary; let channelStub; + let cacheStub; + let loggerStub; let storageStub; let configStub; let getStatus; @@ -33,17 +37,30 @@ describe('node/api', () => { invoke: sinonSandbox.stub().resolves(), }; + loggerStub = { + warn: sinonSandbox.stub(), + }; + + cacheStub = { + cacheReady: sinonSandbox.stub(), + }; + storageStub = { entities: { Block: { get: sinonSandbox.stub().resolves([]), }, + Transaction: { + count: sinonSandbox.stub().resolves(confirmedTransactions), + }, }, }; library = { components: { storage: storageStub, + cache: cacheStub, + logger: loggerStub, }, config: configStub, channel: channelStub, @@ -106,15 +123,13 @@ describe('node/api', () => { }, loaded: true, syncing: false, - transactions: { - confirmed: 10, + unconfirmedTransactions: { unconfirmed: 0, unprocessed: 0, unsigned: 0, total: 10, }, }; - const now = Date.now(); const expectedStatus = { @@ -127,7 +142,7 @@ describe('node/api', () => { networkHeight: 456, syncing: false, transactions: { - confirmed: 10, + confirmed: confirmedTransactions, unconfirmed: 0, unprocessed: 0, unsigned: 0,