From 706bdba69b930c61c5e13041dfb93e20895ef159 Mon Sep 17 00:00:00 2001 From: apanizo Date: Mon, 14 May 2018 10:43:23 +0200 Subject: [PATCH] WA-238 Adding test updating safe's daily limit redux record after executing withdrawn --- .../safe/store/test/dailyLimit.reducer.js | 51 +++++++++++++++++++ src/routes/safe/store/test/safe.spec.js | 2 + 2 files changed, 53 insertions(+) create mode 100644 src/routes/safe/store/test/dailyLimit.reducer.js diff --git a/src/routes/safe/store/test/dailyLimit.reducer.js b/src/routes/safe/store/test/dailyLimit.reducer.js new file mode 100644 index 00000000..9ee1eb5a --- /dev/null +++ b/src/routes/safe/store/test/dailyLimit.reducer.js @@ -0,0 +1,51 @@ +// @flow +import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe' +import fetchDailyLimit from '~/routes/safe/store/actions/fetchDailyLimit' +import { aNewStore } from '~/store' +import { addEtherTo } from '~/test/addEtherTo' +import { aDeployedSafe, executeWithdrawnOn } from './builder/deployedSafe.builder' + +const updateDailyLimitReducerTests = () => { + describe('Safe Actions[updateDailyLimit]', () => { + let store + beforeEach(async () => { + store = aNewStore() + }) + + it('reducer should return 0 as spentToday value from just deployed safe', async () => { + // GIVEN + const dailyLimitValue = 0.5 + const safeAddress = await aDeployedSafe(store, 0.5) + // WHEN + await store.dispatch(fetchDailyLimit(safeAddress)) + + // THEN + const safes = store.getState()[SAFE_REDUCER_ID] + const dailyLimit = safes.get(safeAddress).get('dailyLimit') + expect(dailyLimit).not.toBe(undefined) + expect(dailyLimit.value).toBe(dailyLimitValue) + expect(dailyLimit.spentToday).toBe(0) + }) + + it('reducer should return 0.1456 ETH as spentToday if the user has withdrawn 0.1456 from MAX of 0.3 ETH', async () => { + // GIVEN + const dailyLimitValue = 0.3 + const safeAddress = await aDeployedSafe(store, dailyLimitValue) + await addEtherTo(safeAddress, '0.5') + const value = 0.1456 + + // WHEN + await executeWithdrawnOn(safeAddress, value) + await store.dispatch(fetchDailyLimit(safeAddress)) + + // THEN + const safes = store.getState()[SAFE_REDUCER_ID] + const dailyLimit = safes.get(safeAddress).get('dailyLimit') + expect(dailyLimit).not.toBe(undefined) + expect(dailyLimit.value).toBe(dailyLimitValue) + expect(dailyLimit.spentToday).toBe(value) + }) + }) +} + +export default updateDailyLimitReducerTests diff --git a/src/routes/safe/store/test/safe.spec.js b/src/routes/safe/store/test/safe.spec.js index ea07c3ee..57521e6f 100644 --- a/src/routes/safe/store/test/safe.spec.js +++ b/src/routes/safe/store/test/safe.spec.js @@ -1,6 +1,7 @@ // @flow import balanceReducerTests from './balance.reducer' import safeReducerTests from './safe.reducer' +import dailyLimitReducerTests from './dailyLimit.reducer' import balanceSelectorTests from './balance.selector' import safeSelectorTests from './safe.selector' @@ -8,6 +9,7 @@ describe('Safe Test suite', () => { // ACTIONS AND REDUCERS safeReducerTests() balanceReducerTests() + dailyLimitReducerTests() // SAFE SELECTOR safeSelectorTests()