From 1b7babd5b231c3f743d104ec31ab439ef4d629ae Mon Sep 17 00:00:00 2001 From: Karl Ranna Date: Mon, 10 Sep 2018 14:10:13 +0300 Subject: [PATCH] Limit transactions list to last 100 transactions --- src/computed/transaction.js | 2 +- test/unit/computed/transaction.spec.js | 31 ++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/computed/transaction.js b/src/computed/transaction.js index cb79d4224..46b869033 100644 --- a/src/computed/transaction.js +++ b/src/computed/transaction.js @@ -28,7 +28,7 @@ const ComputedTransaction = store => { t.confirmationsLabel = t.confirmations.toString(); } }); - return all; + return all.slice(0, 100); }), }); }; diff --git a/test/unit/computed/transaction.spec.js b/test/unit/computed/transaction.spec.js index 56594dc16..82c05b60e 100644 --- a/test/unit/computed/transaction.spec.js +++ b/test/unit/computed/transaction.spec.js @@ -3,18 +3,19 @@ import ComputedTransaction from '../../../src/computed/transaction'; describe('Computed Transactions Unit Tests', () => { let store; + const bitcoinTransaction = { + id: '0', + type: 'bitcoin', + amount: 923456, + fee: 8250, + confirmations: 0, + status: 'unconfirmed', + date: new Date(), + }; beforeEach(() => { store = new Store(); - store.transactions.push({ - id: '0', - type: 'bitcoin', - amount: 923456, - fee: 8250, - confirmations: 0, - status: 'unconfirmed', - date: new Date(), - }); + store.transactions.push(bitcoinTransaction); store.payments.push({ id: '1', type: 'lightning', @@ -68,5 +69,17 @@ describe('Computed Transactions Unit Tests', () => { expect(tx.amountLabel, 'to match', /63[,.]67/); expect(tx.feeLabel, 'to match', /0[,.]57/); }); + + it('should limit transactions to last 100', () => { + store.payments = null; + store.invoices = null; + store.transactions = []; + const TRANSACTIONS_COUNT = 101; + [...Array(TRANSACTIONS_COUNT)].forEach(() => + store.transactions.push(bitcoinTransaction) + ); + ComputedTransaction(store); + expect(store.computedTransactions.length, 'to equal', 100); + }); }); });