Correction d'un bug du méca sélection et les tests

pull/51/head
mama 2017-09-19 17:23:45 +02:00 committed by Laurent Bossavit
parent 216337be31
commit 09926e567e
3 changed files with 28 additions and 1 deletions

View File

@ -627,7 +627,7 @@ export let mecanismSelection = (recurse,k,v) => {
data = dataSource ? dataSource['data'] : null,
dataKey = explanation.nodeValue,
dataItems = (data && dataKey && dataSearchField) ? R.filter(item => item[dataSearchField] == dataKey, data) : null,
dataItemValues = dataItems ? R.values(dataItems) : null,
dataItemValues = (dataItems && !R.isEmpty(dataItems)) ? R.values(dataItems) : null,
// TODO - over-specific! transform the JSON instead
dataItemSubValues = dataItemValues && dataItemValues[0][dataTargetName] ? dataItemValues[0][dataTargetName]["taux"] : null,
sortedSubValues = dataItemSubValues ? R.sortBy(pair => pair[0], R.toPairs(dataItemSubValues)) : null,

View File

@ -27,6 +27,15 @@ module.exports = {
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.csv$/,
loader: 'csv-loader',
options: {
dynamicTyping: true,
header: true,
skipEmptyLines: true
}
},
{ //slow : ~ 3 seconds
test: /\.(jpe?g|png|gif|svg)$/i,
loader: 'ignore-loader'

View File

@ -258,4 +258,22 @@ describe('analyseSituation with mecanisms', function() {
expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue',0.02)
});
it('should handle failed selections', function() {
let stateSelector = (name) => ({"top . code postal":"3"})[name]
let data = {taux_versement_transport: {xyz: {codePostal:1, aot: {taux: {"2019":"1.0"}}}, abc: {codePostal:2, smt: {taux: {"2019":"2.0"}}}}}
let rawRules = [
{ espace: "top",
nom: "startHere",
formule: {"sélection": {
données: "startHere",
cherche: "code postal",
dans: "codePostal",
renvoie: "smt"
}},
données: 'taux_versement_transport'},
{espace: "top", nom: "code postal", format: "nombre"}],
rules = rawRules.map(rule => enrichRule(rule,data))
expect(analyseSituation(rules,"startHere")(stateSelector)).to.have.property('nodeValue', 0)
});
});