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()
|
return runner()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pp = require('./pp')
|
||||||
function runOnce () {
|
function runOnce () {
|
||||||
return verifySchema.valid()
|
return verifySchema.valid()
|
||||||
.then(() => settingsLoader.loadLatest())
|
.then(() => settingsLoader.loadLatest())
|
||||||
.then(settings => {
|
.then(settings => {
|
||||||
|
// pp(settings)
|
||||||
poller.start(settings)
|
poller.start(settings)
|
||||||
|
|
||||||
const httpsServerOptions = {
|
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 () {
|
function loadFixture () {
|
||||||
const fixture = argv.fixture
|
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')
|
const fixturePath = fixture => path.resolve(__dirname, '..', 'test', 'fixtures', fixture + '.json')
|
||||||
|
|
||||||
return fixture
|
const promise = fixture
|
||||||
? pify(fs.readFile)(fixturePath(fixture)).then(JSON.parse)
|
? 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) {
|
function isEquivalentField (a, b) {
|
||||||
|
|
@ -33,9 +45,9 @@ function mergeValues (a, b) {
|
||||||
function load (versionId) {
|
function load (versionId) {
|
||||||
if (!versionId) throw new Error('versionId is required')
|
if (!versionId) throw new Error('versionId is required')
|
||||||
|
|
||||||
return Promise.all([loadConfig(versionId), loadAccounts(), loadFixture()])
|
return Promise.all([loadConfig(versionId), loadAccounts()])
|
||||||
.then(([config, accounts, fixture]) => ({
|
.then(([config, accounts]) => ({
|
||||||
config: mergeValues(config, fixture),
|
config,
|
||||||
accounts
|
accounts
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
@ -53,8 +65,11 @@ function loadConfig (versionId) {
|
||||||
from user_config
|
from user_config
|
||||||
where id=$1 and type=$2`
|
where id=$1 and type=$2`
|
||||||
|
|
||||||
return db.oneOrNone(sql, [versionId, 'config'])
|
return Promise.all([db.oneOrNone(sql, [versionId, 'config']), loadFixture()])
|
||||||
.then(row => row ? row.data.config : [])
|
.then(([row, fixture]) => {
|
||||||
|
const config = row ? row.data.config : []
|
||||||
|
return mergeValues(config, fixture)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadLatestConfig () {
|
function loadLatestConfig () {
|
||||||
|
|
@ -64,8 +79,12 @@ function loadLatestConfig () {
|
||||||
order by id desc
|
order by id desc
|
||||||
limit 1`
|
limit 1`
|
||||||
|
|
||||||
return db.oneOrNone(sql, ['config'])
|
return Promise.all([db.oneOrNone(sql, ['config']), loadFixture()])
|
||||||
.then(row => row ? row.data.config : [])
|
.then(([row, fixture]) => {
|
||||||
|
const config = row ? row.data.config : []
|
||||||
|
require('./pp')(fixture)
|
||||||
|
return mergeValues(config, fixture)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadAccounts () {
|
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