WIP
This commit is contained in:
parent
94dc861b87
commit
1183950dad
4 changed files with 277 additions and 9 deletions
|
|
@ -32,10 +32,12 @@ function run () {
|
|||
return runner()
|
||||
}
|
||||
|
||||
const pp = require('./pp')
|
||||
function runOnce () {
|
||||
return verifySchema.valid()
|
||||
.then(() => settingsLoader.loadLatest())
|
||||
.then(settings => {
|
||||
// pp(settings)
|
||||
poller.start(settings)
|
||||
|
||||
const httpsServerOptions = {
|
||||
|
|
|
|||
1
lib/pp.js
Normal file
1
lib/pp.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
module.exports = o => console.log(require('util').inspect(o, {depth: null, colors: true}))
|
||||
|
|
@ -11,11 +11,23 @@ let settingsCache
|
|||
|
||||
function loadFixture () {
|
||||
const fixture = argv.fixture
|
||||
const machine = argv.machine
|
||||
|
||||
console.log('DEBUG22: %j', [fixture, machine])
|
||||
if (fixture && !machine) throw new Error('Missing --machine parameter for --fixture')
|
||||
|
||||
const fixturePath = fixture => path.resolve(__dirname, '..', 'test', 'fixtures', fixture + '.json')
|
||||
|
||||
return fixture
|
||||
const promise = fixture
|
||||
? pify(fs.readFile)(fixturePath(fixture)).then(JSON.parse)
|
||||
: Promise.resolve({})
|
||||
: Promise.resolve([])
|
||||
|
||||
return promise
|
||||
.then(values => _.map(v => {
|
||||
return (v.fieldLocator.fieldScope.machine === 'machine')
|
||||
? _.set('fieldLocator.fieldScope.machine', machine, v)
|
||||
: v
|
||||
}, values))
|
||||
}
|
||||
|
||||
function isEquivalentField (a, b) {
|
||||
|
|
@ -33,9 +45,9 @@ function mergeValues (a, b) {
|
|||
function load (versionId) {
|
||||
if (!versionId) throw new Error('versionId is required')
|
||||
|
||||
return Promise.all([loadConfig(versionId), loadAccounts(), loadFixture()])
|
||||
.then(([config, accounts, fixture]) => ({
|
||||
config: mergeValues(config, fixture),
|
||||
return Promise.all([loadConfig(versionId), loadAccounts()])
|
||||
.then(([config, accounts]) => ({
|
||||
config,
|
||||
accounts
|
||||
}))
|
||||
}
|
||||
|
|
@ -53,8 +65,11 @@ function loadConfig (versionId) {
|
|||
from user_config
|
||||
where id=$1 and type=$2`
|
||||
|
||||
return db.oneOrNone(sql, [versionId, 'config'])
|
||||
.then(row => row ? row.data.config : [])
|
||||
return Promise.all([db.oneOrNone(sql, [versionId, 'config']), loadFixture()])
|
||||
.then(([row, fixture]) => {
|
||||
const config = row ? row.data.config : []
|
||||
return mergeValues(config, fixture)
|
||||
})
|
||||
}
|
||||
|
||||
function loadLatestConfig () {
|
||||
|
|
@ -64,8 +79,12 @@ function loadLatestConfig () {
|
|||
order by id desc
|
||||
limit 1`
|
||||
|
||||
return db.oneOrNone(sql, ['config'])
|
||||
.then(row => row ? row.data.config : [])
|
||||
return Promise.all([db.oneOrNone(sql, ['config']), loadFixture()])
|
||||
.then(([row, fixture]) => {
|
||||
const config = row ? row.data.config : []
|
||||
require('./pp')(fixture)
|
||||
return mergeValues(config, fixture)
|
||||
})
|
||||
}
|
||||
|
||||
function loadAccounts () {
|
||||
|
|
|
|||
246
test/fixtures/two-way-btc.json
vendored
Normal file
246
test/fixtures/two-way-btc.json
vendored
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
[
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "BTC",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "cashInCommission",
|
||||
"fieldType": "percentage",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "percentage",
|
||||
"value": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "BTC",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "lowBalanceMargin",
|
||||
"fieldType": "percentage",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "percentage",
|
||||
"value": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "machineLanguages",
|
||||
"fieldType": "language",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "language",
|
||||
"value": [
|
||||
"en-US"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "cryptoCurrencies",
|
||||
"fieldType": "cryptoCurrency",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "cryptoCurrency",
|
||||
"value": [
|
||||
"BTC"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "emptyBillMargin",
|
||||
"fieldType": "integer",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "integer",
|
||||
"value": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "global"
|
||||
},
|
||||
"code": "smsVerificationEnabled",
|
||||
"fieldType": "onOff",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "onOff",
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "idVerificationEnabled",
|
||||
"fieldType": "onOff",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "onOff",
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "global"
|
||||
},
|
||||
"code": "notificationsEnabled",
|
||||
"fieldType": "onOff",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "onOff",
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "global"
|
||||
},
|
||||
"code": "notificationsEmailEnabled",
|
||||
"fieldType": "onOff",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "onOff",
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "global"
|
||||
},
|
||||
"code": "notificationsSMSEnabled",
|
||||
"fieldType": "onOff",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "onOff",
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "machineName",
|
||||
"fieldType": "string",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "string",
|
||||
"value": "test1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "cashOutEnabled",
|
||||
"fieldType": "onOff",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "onOff",
|
||||
"value": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "global"
|
||||
},
|
||||
"code": "fiatCurrency",
|
||||
"fieldType": "fiatCurrency",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "fiatCurrency",
|
||||
"value": "USD"
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "BTC",
|
||||
"machine": "global"
|
||||
},
|
||||
"code": "ticker",
|
||||
"fieldType": "account",
|
||||
"fieldClass": "ticker"
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "account",
|
||||
"value": "mock-ticker"
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "BTC",
|
||||
"machine": "global"
|
||||
},
|
||||
"code": "wallet",
|
||||
"fieldType": "account",
|
||||
"fieldClass": "wallet"
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "account",
|
||||
"value": "mock-wallet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldLocator": {
|
||||
"fieldScope": {
|
||||
"crypto": "global",
|
||||
"machine": "machine"
|
||||
},
|
||||
"code": "cashInTransactionLimit",
|
||||
"fieldType": "integer",
|
||||
"fieldClass": null
|
||||
},
|
||||
"fieldValue": {
|
||||
"fieldType": "integer",
|
||||
"value": 100
|
||||
}
|
||||
}
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue