testing all conditionnal conversions
This commit is contained in:
parent
c7629c6c04
commit
728d01ba74
@ -63,15 +63,59 @@ export const mappingBoolean: MappingConfigType = {
|
|||||||
source: {},
|
source: {},
|
||||||
filters: {},
|
filters: {},
|
||||||
}
|
}
|
||||||
// export const mappingIgnore: MappingConfigType = {
|
export const mappingTruthy: MappingConfigType = {
|
||||||
// config_name: 'testing config',
|
|
||||||
// config_author: 'tykayn <contact@cipherbliss.com>',
|
config_name: 'testing config mappingTruthy',
|
||||||
// default_properties_of_point: {
|
config_author: 'tykayn <contact@cipherbliss.com>',
|
||||||
// 'amenity': 'charging_station'
|
default_properties_of_point: {},
|
||||||
// },
|
tags: {
|
||||||
// tags: {
|
consolidated_is_lon_lat_correct: {
|
||||||
// nom_amenageur: {
|
truthy_value: "succès",
|
||||||
// ignore_this_data: true,
|
},
|
||||||
// }
|
},
|
||||||
// }
|
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: {},
|
||||||
|
}
|
@ -257,6 +257,9 @@ export default class {
|
|||||||
if (configObject.ignore_if_falsy && this.falsyValues.indexOf(originalValue) !== -1) {
|
if (configObject.ignore_if_falsy && this.falsyValues.indexOf(originalValue) !== -1) {
|
||||||
remove_original_key = true
|
remove_original_key = true
|
||||||
}
|
}
|
||||||
|
if (configObject.ignore_if_truthy && this.truthyValues.indexOf(originalValue) !== -1) {
|
||||||
|
remove_original_key = true
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* config pour une clé
|
* config pour une clé
|
||||||
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
|
* nous pouvons renseigner une string ou un objet décrivant les transformations à réaliser
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
import mapping_engine from '../mappings/engine.ts'
|
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')
|
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([])
|
expect(Object.keys(mapped_point.properties)).toStrictEqual([])
|
||||||
|
|
||||||
})
|
})
|
||||||
// test('maps simple key to key, and keep the same value', () => {
|
test('maps simple key to key, and keep the same value', () => {
|
||||||
// let Mapping_engine = new mapping_engine(mappingSame)
|
let Mapping_engine = new mapping_engine(mappingSame)
|
||||||
// let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
let newProperties = Mapping_engine.convertProperty('equal',
|
||||||
// console.log('mapped_point', mapped_point)
|
Object.keys(mappingSame.tags),
|
||||||
// expect(mapped_point.properties).toBe({
|
feature_to_test,
|
||||||
// equal : "same value"
|
mappingSame.default_properties_of_point )
|
||||||
// })
|
|
||||||
// })
|
expect(newProperties).toStrictEqual({
|
||||||
|
equal : "same value"
|
||||||
|
})
|
||||||
|
})
|
||||||
test('retrieve config name in mapping engine', () => {
|
test('retrieve config name in mapping engine', () => {
|
||||||
let Mapping_engine = new mapping_engine(mappingRemoveAll)
|
let Mapping_engine = new mapping_engine(mappingRemoveAll)
|
||||||
expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingRemoveAll')
|
expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingRemoveAll')
|
||||||
@ -39,15 +48,32 @@ describe('mapping properties with rich mapping engine', () => {
|
|||||||
name : "Bob"
|
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 value', () => { })
|
||||||
// test('conditional transform', () => { })
|
// 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', () => {
|
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 Mapping_engine = new mapping_engine(mappingBoolean)
|
||||||
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||||
expect(mapped_point.properties).toStrictEqual({ consolidated_is_lon_lat_correct: 'yes' })
|
expect(mapped_point.properties).toStrictEqual({ consolidated_is_lon_lat_correct: 'yes' })
|
||||||
|
|
||||||
})
|
})
|
||||||
test('conditional phone transform', () => {
|
test('conditional phone transform', () => {
|
||||||
let Mapping_engine = new mapping_engine(mappingPhone)
|
let Mapping_engine = new mapping_engine(mappingPhone)
|
||||||
|
Loading…
Reference in New Issue
Block a user