start adding test framework
This commit is contained in:
parent
d9b2e021e7
commit
94dc861b87
4 changed files with 2152 additions and 34 deletions
|
|
@ -1,15 +1,41 @@
|
|||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
const argv = require('minimist')(process.argv.slice(2))
|
||||
const pify = require('pify')
|
||||
|
||||
const db = require('./db')
|
||||
|
||||
let settingsCache
|
||||
|
||||
function loadFixture () {
|
||||
const fixture = argv.fixture
|
||||
const fixturePath = fixture => path.resolve(__dirname, '..', 'test', 'fixtures', fixture + '.json')
|
||||
|
||||
return fixture
|
||||
? pify(fs.readFile)(fixturePath(fixture)).then(JSON.parse)
|
||||
: Promise.resolve({})
|
||||
}
|
||||
|
||||
function isEquivalentField (a, b) {
|
||||
return _.isEqual(
|
||||
[a.fieldLocator.code, a.fieldLocator.fieldScope],
|
||||
[b.fieldLocator.code, b.fieldLocator.fieldScope]
|
||||
)
|
||||
}
|
||||
|
||||
// b overrides a
|
||||
function mergeValues (a, b) {
|
||||
return _.unionWith(isEquivalentField, b, a)
|
||||
}
|
||||
|
||||
function load (versionId) {
|
||||
if (!versionId) throw new Error('versionId is required')
|
||||
|
||||
return Promise.all([loadConfig(versionId), loadAccounts()])
|
||||
.then(([config, accounts]) => ({
|
||||
config,
|
||||
return Promise.all([loadConfig(versionId), loadAccounts(), loadFixture()])
|
||||
.then(([config, accounts, fixture]) => ({
|
||||
config: mergeValues(config, fixture),
|
||||
accounts
|
||||
}))
|
||||
}
|
||||
|
|
@ -67,5 +93,7 @@ module.exports = {
|
|||
loadConfig,
|
||||
load,
|
||||
loadLatest,
|
||||
save
|
||||
save,
|
||||
loadFixture,
|
||||
mergeValues
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue