WIP
This commit is contained in:
parent
94dc861b87
commit
1183950dad
4 changed files with 277 additions and 9 deletions
|
|
@ -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 () {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue