testing all conditionnal conversions

This commit is contained in:
Tykayn 2023-08-18 12:22:07 +02:00 committed by tykayn
parent c7629c6c04
commit 728d01ba74
3 changed files with 97 additions and 24 deletions

View File

@ -63,15 +63,59 @@ export const mappingBoolean: MappingConfigType = {
source: {},
filters: {},
}
// export const mappingIgnore: MappingConfigType = {
// config_name: 'testing config',
// config_author: 'tykayn <contact@cipherbliss.com>',
// default_properties_of_point: {
// 'amenity': 'charging_station'
// },
// tags: {
// nom_amenageur: {
// ignore_this_data: true,
// }
// }
// }
export const mappingTruthy: MappingConfigType = {
config_name: 'testing config mappingTruthy',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_is_lon_lat_correct: {
truthy_value: "succès",
},
},
add_not_mapped_tags_too: false,
source: {},
filters: {},
}
export const mappingFalsy: MappingConfigType = {
config_name: 'testing config mappingFalsy',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_city: {
falsy_value: "pas ouf succès",
},
},
add_not_mapped_tags_too: false,
source: {},
filters: {},
}
export const mappingIgnoreFalsy: MappingConfigType = {
config_name: 'testing config mappingIgnore',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_city: {
ignore_if_falsy: true,
},
},
add_not_mapped_tags_too: false,
source: {},
filters: {},
}
export const mappingIgnoreTruthy: MappingConfigType = {
config_name: 'testing config mappingIgnore',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_is_lon_lat_correct: {
ignore_if_truthy: true,
},
},
add_not_mapped_tags_too: false,
source: {},
filters: {},
}

View File

@ -257,6 +257,9 @@ export default class {
if (configObject.ignore_if_falsy && this.falsyValues.indexOf(originalValue) !== -1) {
remove_original_key = true
}
if (configObject.ignore_if_truthy && this.truthyValues.indexOf(originalValue) !== -1) {
remove_original_key = true
}
/**
* config pour une clé
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser

View File

@ -1,5 +1,11 @@
import mapping_engine from '../mappings/engine.ts'
import { mappingPhone, mappingRemoveAll, mappingBoolean, mappingName } from '../data_other/testing/mappings_to_test'
import {
mappingPhone,
mappingRemoveAll,
mappingBoolean,
mappingName,
mappingSame, mappingTruthy, mappingFalsy, mappingIgnoreFalsy, mappingIgnoreTruthy
} from '../data_other/testing/mappings_to_test'
const testingGeoJson = require('../data_other/testing/testing.json')
@ -18,14 +24,17 @@ 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 mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
// console.log('mapped_point', mapped_point)
// expect(mapped_point.properties).toBe({
// equal : "same value"
// })
// })
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 )
expect(newProperties).toStrictEqual({
equal : "same value"
})
})
test('retrieve config name in mapping engine', () => {
let Mapping_engine = new mapping_engine(mappingRemoveAll)
expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingRemoveAll')
@ -39,15 +48,32 @@ describe('mapping properties with rich mapping engine', () => {
name : "Bob"
})
})
// test('ignore one value', () => { })
test('ignore one value if it is truthy', () => {
let Mapping_engine = new mapping_engine(mappingIgnoreTruthy)
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({})
})
test('ignore one value if it is falsy', () => {
let Mapping_engine = new mapping_engine(mappingIgnoreFalsy)
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({})
})
// test('conditional value', () => { })
// test('conditional transform', () => { })
// test('conditional truthy transform', () => { })
test('conditional truthy transform', () => {
let Mapping_engine = new mapping_engine(mappingTruthy)
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ consolidated_is_lon_lat_correct: 'succès' })
})
test('conditional falsy transform', () => {
let Mapping_engine = new mapping_engine(mappingFalsy)
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ consolidated_city: 'pas ouf succès' })
})
test('conditional boolean transform', () => {
let Mapping_engine = new mapping_engine(mappingBoolean)
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ consolidated_is_lon_lat_correct: 'yes' })
})
test('conditional phone transform', () => {
let Mapping_engine = new mapping_engine(mappingPhone)