up testing engine

This commit is contained in:
Tykayn 2025-04-28 00:44:55 +02:00 committed by tykayn
parent 353fa37c85
commit 44a6d309a9
2 changed files with 24 additions and 19 deletions

View file

@ -409,10 +409,10 @@ export default class MappingEngine {
if (configObject.remove_original_key) {
remove_original_key = true
}
if (configObject.ignore_if_falsy && custom_utils.falsyValues.indexOf(this.convertToBoolean(originalValue)) !== -1) {
if (configObject.ignore_if_falsy && !this.convertToBoolean(originalValue)) {
remove_original_key = true
}
if (configObject.ignore_if_truthy && custom_utils.truthyValues.indexOf(this.convertToBoolean(originalValue)) !== -1) {
if (configObject.ignore_if_truthy && this.convertToBoolean(originalValue)) {
remove_original_key = true
}
@ -576,20 +576,14 @@ export default class MappingEngine {
return convertedValue;
}
private convertToBoolean(originalValue: any) {
debugLog('convertProperty: ==========> original value', originalValue)
let convertedValue;
private convertToBoolean(originalValue: any): boolean {
if (custom_utils.truthyValues.indexOf(originalValue) !== -1) {
convertedValue = true
} else {
debugLog('convertProperty: ==========> !!! NOT in truthy values', originalValue)
return true;
}
if (custom_utils.falsyValues.indexOf(originalValue) !== -1) {
convertedValue = false
} else {
debugLog('convertProperty: ==========> !!! NOT in falsy values', originalValue)
return false;
}
return convertedValue;
return false; // valeur par défaut
}
}

View file

@ -7,6 +7,16 @@ const testingGeoJson = require('./data/testing.json')
// import { describe, expect, test } from '@jest/globals'
describe('mapping engine', () => {
test('load mapping config', () => {
let Mapping_engine = new MappingEngine(mappings.mappingSame)
expect(Mapping_engine.getConfig()).toStrictEqual(mappings.mappingSame)
})
})
describe('mapping properties with rich mapping engine', () => {
// test('do not add properties at all when there is nothing in tags of the mapping config', () => {
@ -22,14 +32,15 @@ describe('mapping properties with rich mapping engine', () => {
// expect(Object.keys(mapped_point.properties)).toStrictEqual([])
// })
// test('maps simple key to key, and keep the same value', () => {
// let Mapping_engine = new mapping_engine(mappingSame)
// let newProperties = Mapping_engine.convertProperty('equal',
// Object.keys(mappingSame.tags),
// feature_to_test,
// mappingSame.default_properties_of_point)
// let Mapping_engine = new MappingEngine(mappings.mappingSame)
// expect(newProperties).toStrictEqual({
// test('maps simple key to key, and keep the same value', () => {
// Mapping_engine.setConfig(mappings.mappingSame)
// let feature_to_test = testingGeoJson.features[0]
// let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
// expect(mapped_point.properties).toStrictEqual({
// equal: "same value"
// })
// })