Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

refactor: multi-wallet endpoints #956

Merged
merged 19 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ec15224
feat: add check for multi-wallet search endpoint
alexbarnsley Jan 9, 2019
3c03964
fix: start synchronizer after everything is loaded
alexbarnsley Jan 9, 2019
255ab42
feat: methods to fetch multi-wallet data
alexbarnsley Jan 9, 2019
b1df237
feat: allow updating ledger wallet data & cache
alexbarnsley Jan 9, 2019
173381c
refactor: use multi-wallet methods for ui
alexbarnsley Jan 9, 2019
84a848f
fix: don't run sync action if not found
alexbarnsley Jan 9, 2019
5bbdef5
refactor: batch reload ledger to improve speed
alexbarnsley Jan 9, 2019
7fdee95
misc: a little tidying
alexbarnsley Jan 11, 2019
a0a0039
fix: fallback to single wallet api on failure
alexbarnsley Jan 11, 2019
36de560
fix: ensure data is set before checking address
alexbarnsley Jan 11, 2019
d94b59e
refactor: remove redundant try/catch & comments
alexbarnsley Jan 11, 2019
912819a
test: dashboard transactions component
alexbarnsley Jan 11, 2019
4c6725f
test: add/fix wallet sync tests
alexbarnsley Jan 11, 2019
e55c7ea
test: improve and add missing ledger tests
alexbarnsley Jan 11, 2019
c85c36f
test: add client service tests
alexbarnsley Jan 11, 2019
74a1bf6
Merge branch 'develop' into refactor/mutli-wallet-endpoints
alexbarnsley Jan 11, 2019
6c36c80
Merge branch 'develop' into refactor/mutli-wallet-endpoints
alexbarnsley Jan 14, 2019
3cbb8eb
Merge branch 'develop' into refactor/mutli-wallet-endpoints
j-a-m-l Jan 14, 2019
3dfbe4a
Merge branch 'develop' into refactor/mutli-wallet-endpoints
alexbarnsley Jan 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions __tests__/unit/__fixtures__/store/ledger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const wallet1 = {
address: 'address 1',
publicKey: 'public key 1'
}

const wallet2 = {
address: 'address 2',
publicKey: 'public key 2'
}

const wallet3 = {
address: 'address 3',
publicKey: 'public key 3'
}

const wallet4 = {
address: 'address 4',
publicKey: 'public key 4'
}

const wallet5 = {
address: 'address 5',
publicKey: 'public key 5'
}

const wallet6 = {
address: 'address 6',
publicKey: 'public key 6'
}

const wallet7 = {
address: 'address 7',
publicKey: 'public key 7'
}

const wallet8 = {
address: 'address 8',
publicKey: 'public key 8'
}

const wallet9 = {
address: 'address 9',
publicKey: 'public key 9'
}

const wallet10 = {
address: 'address 10',
publicKey: 'public key 10'
}

export default [
wallet1,
wallet2,
wallet3,
wallet4,
wallet5,
wallet6,
wallet7,
wallet8,
wallet9,
wallet10
]

export {
wallet1,
wallet2,
wallet3,
wallet4,
wallet5,
wallet6,
wallet7,
wallet8,
wallet9,
wallet10
}
113 changes: 113 additions & 0 deletions __tests__/unit/components/Dashboard/DashboardTransactions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { shallowMount } from '@vue/test-utils'
import useI18nGlobally from '../../__utils__/i18n'
import { DashboardTransactions } from '@/components/Dashboard'

const i18n = useI18nGlobally()
let wrapper
let wallets
const transactions = [
{ id: 'tx1', timestamp: 300 * 1000 },
{ id: 'tx2', timestamp: 400 * 1000 },
{ id: 'tx3', timestamp: 200 * 1000 },
{ id: 'tx4', timestamp: 110 * 1000 },
{ id: 'tx5', timestamp: 120 * 1000 }
]
let walletTransactions
let fetchTransactionsForWallets
const loggerError = jest.fn()
const alertError = jest.fn()
const transactionByProfileId = jest.fn(() => 'profileId')
const walletByProfileId = jest.fn(() => wallets)
let mocks

beforeEach(() => {
wallets = [
{ address: 'A1', transactions: {} },
{ address: 'A2', transactions: {} },
{ address: 'A3', transactions: {} },
{ address: 'A4', transactions: {} }
]
walletTransactions = {
A1: [
transactions[0],
transactions[1]
],
A2: [
transactions[2]
],
A4: [
transactions[3],
transactions[4]
]
}
fetchTransactionsForWallets = jest.fn(() => walletTransactions)
// walletByProfileId = jest.fn(() => wallets)
mocks = {
$client: {
fetchTransactionsForWallets
},
$error: alertError,
$logger: {
error: loggerError
},
$store: {
getters: {
'transaction/byProfileId': transactionByProfileId,
'wallet/byProfileId': walletByProfileId,
'ledger/wallets': []
}
}
}
wrapper = shallowMount(DashboardTransactions, {
i18n,
mocks
})
})

describe('DashboardTransactions', () => {
it('should render modal', () => {
expect(wrapper.isVueInstance()).toBeTrue()
})

describe('fetchTransactions', () => {
it('should not run if no wallets', () => {
wallets = []
mocks.$client.fetchTransactionsForWallets = jest.fn(() => [])
wrapper = shallowMount(DashboardTransactions, {
i18n,
mocks
})

wrapper.vm.fetchTransactions()
expect(mocks.$client.fetchTransactionsForWallets).not.toHaveBeenCalled()
})
it('should fetch transactions for wallets', () => {
wrapper.vm.fetchTransactions()
expect(fetchTransactionsForWallets).toHaveBeenNthCalledWith(1, wallets.map(wallet => wallet.address))
})

it('should consolidate transactions', () => {
wrapper.vm.fetchTransactions()
expect(wrapper.vm.fetchedTransactions).toIncludeAllMembers(transactions)
})

it('should remove duplicate transactions', () => {
walletTransactions['A1'].push(transactions[0])
wrapper.vm.fetchTransactions()
expect(walletTransactions['A1'].filter(tx => tx.id === 'tx1')).toBeArrayOfSize(2)
expect(wrapper.vm.fetchedTransactions.filter(tx => tx.id === 'tx1')).toBeArrayOfSize(1)
})

it('should log error and show alert message', () => {
fetchTransactionsForWallets.mockImplementation(() => {
throw new Error('throw error')
})
wrapper.vm.fetchTransactions()
expect(loggerError).toHaveBeenCalledWith(new Error('throw error'))
expect(alertError).toHaveBeenCalledWith(i18n.t('COMMON.FAILED_FETCH', {
name: 'transactions',
msg: 'throw error'
}))
})
})
})
Loading