Filter only mock options when in dev mode (#206)
* Filter only mock options when in dev mode * Filter only in production mode * Refactor filter to separate function, add unit tests * Check for mock codes in test
This commit is contained in:
parent
d97a33565f
commit
599c865f37
2 changed files with 43 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
const devMode = require('minimist')(process.argv.slice(2)).dev
|
||||||
|
|
||||||
const currencies = require('../../currencies.json')
|
const currencies = require('../../currencies.json')
|
||||||
const languageRec = require('../../languages.json')
|
const languageRec = require('../../languages.json')
|
||||||
|
|
@ -153,6 +154,12 @@ const supportedLanguages = languageRec.supported
|
||||||
const languages = supportedLanguages.map(mapLanguage).filter(r => r)
|
const languages = supportedLanguages.map(mapLanguage).filter(r => r)
|
||||||
const ALL_CRYPTOS = ['BTC', 'ETH', 'LTC', 'DASH', 'ZEC', 'BCH']
|
const ALL_CRYPTOS = ['BTC', 'ETH', 'LTC', 'DASH', 'ZEC', 'BCH']
|
||||||
|
|
||||||
|
const filterAccounts = (data, isDevMode) => {
|
||||||
|
const notAllowed = ['mock-ticker', 'mock-wallet', 'mock-exchange', 'mock-sms', 'mock-id-verify', 'mock-zero-conf']
|
||||||
|
const filterOut = o => _.includes(o.code, notAllowed)
|
||||||
|
return isDevMode ? data : {...data, accounts: _.filter(a => !filterOut(a), data.accounts)}
|
||||||
|
}
|
||||||
|
|
||||||
function fetchData () {
|
function fetchData () {
|
||||||
return machineLoader.getMachineNames()
|
return machineLoader.getMachineNames()
|
||||||
.then(machineList => ({
|
.then(machineList => ({
|
||||||
|
|
@ -200,6 +207,9 @@ function fetchData () {
|
||||||
],
|
],
|
||||||
machines: machineList.map(machine => ({machine: machine.deviceId, display: machine.name}))
|
machines: machineList.map(machine => ({machine: machine.deviceId, display: machine.name}))
|
||||||
}))
|
}))
|
||||||
|
.then((data) => {
|
||||||
|
return filterAccounts(data, devMode)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveConfigGroup (results) {
|
function saveConfigGroup (results) {
|
||||||
|
|
@ -213,5 +223,6 @@ module.exports = {
|
||||||
fetchConfigGroup,
|
fetchConfigGroup,
|
||||||
saveConfigGroup,
|
saveConfigGroup,
|
||||||
validateCurrentConfig,
|
validateCurrentConfig,
|
||||||
fetchConfig
|
fetchConfig,
|
||||||
|
filterAccounts
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
test/unit/filter-config-accounts.js
Normal file
31
test/unit/filter-config-accounts.js
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
import _ from 'lodash/fp'
|
||||||
|
import test from 'ava'
|
||||||
|
|
||||||
|
import { filterAccounts } from '../../lib/admin/config'
|
||||||
|
|
||||||
|
const ALL_CRYPTOS = ['BTC', 'ETH', 'LTC', 'DASH', 'ZEC', 'BCH']
|
||||||
|
const data = {
|
||||||
|
accounts: [
|
||||||
|
{code: 'mock-ticker', display: 'Mock ticker', class: 'ticker', cryptos: ALL_CRYPTOS},
|
||||||
|
{code: 'bitcoind', display: 'bitcoind', class: 'wallet', cryptos: ['BTC']},
|
||||||
|
{code: 'quadrigacx', display: 'QuadrigaCX', class: 'exchange', cryptos: ['BTC', 'ETH', 'LTC', 'BCH']},
|
||||||
|
{code: 'mock-wallet', display: 'Mock (Caution!)', class: 'wallet', cryptos: ALL_CRYPTOS}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
test('Do not filter accounts in dev mode', t => {
|
||||||
|
t.plan(3)
|
||||||
|
const devMode = true
|
||||||
|
const filteredData = filterAccounts(data, devMode)
|
||||||
|
t.is(filteredData.accounts.length, 4)
|
||||||
|
t.true(_.some(['code', 'mock-wallet'], filteredData.accounts))
|
||||||
|
t.true(_.some(['code', 'mock-ticker'], filteredData.accounts))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Filter accounts in production', t => {
|
||||||
|
t.plan(3)
|
||||||
|
const filteredData = filterAccounts(data)
|
||||||
|
t.false(_.some(['code', 'mock-wallet'], filteredData.accounts))
|
||||||
|
t.false(_.some(['code', 'mock-ticker'], filteredData.accounts))
|
||||||
|
t.is(filteredData.accounts.length, 2)
|
||||||
|
})
|
||||||
Loading…
Add table
Add a link
Reference in a new issue