diff --git a/src/adapters/wallet.adapter.js b/src/adapters/wallet.adapter.js index 1870a33..83ab010 100644 --- a/src/adapters/wallet.adapter.js +++ b/src/adapters/wallet.adapter.js @@ -20,6 +20,13 @@ class Wallet { // Bind 'this' object to all subfunctions this.instanceWalletWithoutInitialization = this.instanceWalletWithoutInitialization.bind(this) + this._instanceWallet = this._instanceWallet.bind(this) + this.openWallet = this.openWallet.bind(this) + this.instanceWallet = this.instanceWallet.bind(this) + this.incrementNextAddress = this.incrementNextAddress.bind(this) + this.getKeyPair = this.getKeyPair.bind(this) + this.optimize = this.optimize.bind(this) + this.getBalance = this.getBalance.bind(this) } // This is used for initializing the wallet, without waiting to update the wallet diff --git a/src/controllers/timer-controllers.js b/src/controllers/timer-controllers.js index 2c58279..55705cf 100644 --- a/src/controllers/timer-controllers.js +++ b/src/controllers/timer-controllers.js @@ -1,6 +1,6 @@ /* This Controller library is concerned with timer-based functions that are - kicked off periodicially. + kicked off periodically. */ import config from '../../config/index.js' @@ -45,7 +45,7 @@ class TimerControllers { stopTimers () { clearInterval(this.optimizeWalletHandle) - clearInterval(this.cleanusageHandle) + clearInterval(this.cleanUsageHandle) } // Replace this example function with your own timer handler. @@ -67,6 +67,9 @@ class TimerControllers { // Clean the usage state so that stats reflect the last 24 hours. cleanUsage () { try { + const now = new Date() + console.log(`cleanUsage() Timer Controller executing at ${now.toLocaleString()}`) + this.useCases.usage.cleanUsage() return true diff --git a/src/use-cases/usage-use-cases.js b/src/use-cases/usage-use-cases.js index 5880f58..ce32f24 100644 --- a/src/use-cases/usage-use-cases.js +++ b/src/use-cases/usage-use-cases.js @@ -36,7 +36,11 @@ class UsageUseCases { const now = new Date() const twentyFourHoursAgo = now.getTime() - (60000 * 60 * 24) + console.log('cleanUsage() now: ', now) + console.log('cleanUsage() restCalls.length before filtering: ', restCalls.length) restCalls = restCalls.filter(x => x.timestamp > twentyFourHoursAgo) + console.log('cleanUsage() restCalls.length after filtering: ', restCalls.length) + return restCalls } catch (err) { console.error('Error in usage-use-cases.js/cleanUsage()') diff --git a/test/unit/use-cases/usage.use-case.unit.js b/test/unit/use-cases/usage.use-case.unit.js index 5dac264..790832a 100644 --- a/test/unit/use-cases/usage.use-case.unit.js +++ b/test/unit/use-cases/usage.use-case.unit.js @@ -1,6 +1,5 @@ /* -Unit tests for the use-cases/usage-use-cases.js business logic library. - + Unit tests for the use-cases/usage-use-cases.js business logic library. */ // Public npm libraries @@ -58,7 +57,7 @@ describe('#usage-use-case', () => { // set older mock data restCalls.push({ - timestamp: now.getTime() - (60000 * 60 * 24), + timestamp: now.getTime() - (60000 * 60 * 48), // 48 hours ago ip: '127.0.0.1' }) @@ -88,6 +87,7 @@ describe('#usage-use-case', () => { } }) }) + describe('#getRestSummary', () => { it('should get the number of rest calls', () => { // Set mock data @@ -137,6 +137,7 @@ describe('#usage-use-case', () => { assert.equal(result[0].ip, 'localhost') assert.equal(result[0].cnt, '2') }) + it('should return a maximum of 20 values', () => { // Fill Array with 21 values for (let i = 0; i < 21; i++) { @@ -154,6 +155,7 @@ describe('#usage-use-case', () => { assert.equal(result.length, 20) }) + it('should handle error', () => { try { // Set mock data @@ -194,6 +196,7 @@ describe('#usage-use-case', () => { assert.equal(result[0].endpoint, 'GET /api/v1/users') assert.equal(result[0].cnt, '2') }) + it('should return a maximum of 20 values', () => { // Fill Array with 21 values for (let i = 0; i < 21; i++) {