add real booleans in truthy and falsy values
This commit is contained in:
parent
d136015f5e
commit
c3d6004b18
@ -49,6 +49,20 @@ export const mappingPhone: MappingConfigType = {
|
||||
source: {},
|
||||
filters: {},
|
||||
}
|
||||
export const mappingBoolean: MappingConfigType = {
|
||||
|
||||
config_name: 'testing config mappingBoolean',
|
||||
config_author: 'tykayn <contact@cipherbliss.com>',
|
||||
default_properties_of_point: {},
|
||||
tags: {
|
||||
consolidated_is_lon_lat_correct: {
|
||||
convert_to_boolean_value: true,
|
||||
},
|
||||
},
|
||||
add_not_mapped_tags_too: false,
|
||||
source: {},
|
||||
filters: {},
|
||||
}
|
||||
// export const mappingIgnore: MappingConfigType = {
|
||||
// config_name: 'testing config',
|
||||
// config_author: 'tykayn <contact@cipherbliss.com>',
|
||||
|
@ -16,7 +16,8 @@
|
||||
"telephone_operateur": "0123456789",
|
||||
"equal": "same value",
|
||||
"consolidated_commune": "S\u00e9r\u00e9zin-du-Rh\u00f4ne",
|
||||
"consolidated_is_lon_lat_correct": true
|
||||
"consolidated_is_lon_lat_correct": true,
|
||||
"consolidated_city": false
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -10,7 +10,9 @@ const MappingTest: MappingConfigType = {
|
||||
config_author: 'tykayn <contact@cipherbliss.com>',
|
||||
default_properties_of_point: {},
|
||||
tags: {
|
||||
nom_amenageur : 'name'
|
||||
consolidated_is_lon_lat_correct: {
|
||||
convert_to_boolean_value: true,
|
||||
},
|
||||
},
|
||||
add_not_mapped_tags_too: false,
|
||||
source: {},
|
||||
|
@ -57,8 +57,8 @@ export default class {
|
||||
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
||||
}
|
||||
|
||||
truthyValues = ['true', 'True', 'TRUE', '1', 'yes', 1]
|
||||
falsyValues = ['false', 'False', 'FALSE', '0', 'no', 0]
|
||||
truthyValues = [true, 'true', 'True', 'TRUE', '1', 'yes', 1]
|
||||
falsyValues = [false, 'false', 'False', 'FALSE', '0', 'no', 0]
|
||||
|
||||
/**
|
||||
* reduce number of features
|
||||
@ -235,9 +235,13 @@ export default class {
|
||||
debugLog('convertProperty: ==========> original value', originalValue)
|
||||
if (this.truthyValues.indexOf(originalValue) !== -1) {
|
||||
convertedValue = 'yes'
|
||||
} else {
|
||||
debugLog('convertProperty: ==========> !!! NOT in truthy values', originalValue)
|
||||
}
|
||||
if (this.falsyValues.indexOf(originalValue) !== -1) {
|
||||
convertedValue = 'no'
|
||||
} else {
|
||||
debugLog('convertProperty: ==========> !!! NOT in falsy values', originalValue)
|
||||
}
|
||||
} else {
|
||||
debugLog('convertProperty: is NOT having boolean_value_conversion', mappingValueObject)
|
||||
@ -327,8 +331,8 @@ export default class {
|
||||
debugLog(' =============== remove_original_key', newKey, remove_original_key)
|
||||
if (!remove_original_key && newKey && convertedValue && !configObject.ignore_this_data) {
|
||||
|
||||
debugLog('convertProperty: added')
|
||||
newProperties[newKey] = convertedValue.trim()
|
||||
debugLog('convertProperty: added', newKey, convertedValue)
|
||||
newProperties[newKey] = (`${convertedValue}`).trim()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -11,7 +11,7 @@
|
||||
]
|
||||
},
|
||||
"properties": {
|
||||
"name": "Bob"
|
||||
"consolidated_is_lon_lat_correct": "yes"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -1,11 +1,8 @@
|
||||
import mapping_engine from '../mappings/engine.ts'
|
||||
import { mappingRemoveAll, mappingSame, mappingPhone, mappingName } from '../data_other/testing/mappings_to_test'
|
||||
import MappingConfigType, {BoundingBoxCoordinatesType, FeatureCollection} from "../mappings/mapping-config.type";
|
||||
import { mappingPhone, mappingRemoveAll , mappingBoolean} from '../data_other/testing/mappings_to_test'
|
||||
|
||||
const testingGeoJson = require('../data_other/testing/testing.json')
|
||||
|
||||
|
||||
|
||||
// import { describe, expect, test } from '@jest/globals'
|
||||
|
||||
describe('mapping properties with rich mapping engine', () => {
|
||||
@ -13,7 +10,7 @@ describe('mapping properties with rich mapping engine', () => {
|
||||
// test('do not add properties at all when there is nothing in tags of the mapping config', () => {
|
||||
//
|
||||
// })
|
||||
let feature_to_test = testingGeoJson.features[0];
|
||||
let feature_to_test = testingGeoJson.features[0]
|
||||
test('remove all properties when mapping says so', () => {
|
||||
let Mapping_engine = new mapping_engine(mappingRemoveAll)
|
||||
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
@ -33,24 +30,29 @@ describe('mapping properties with rich mapping engine', () => {
|
||||
let Mapping_engine = new mapping_engine(mappingRemoveAll)
|
||||
expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingRemoveAll')
|
||||
})
|
||||
test('maps nom_amenageur to name, and keep the same value', () => {
|
||||
let Mapping_engine = new mapping_engine(mappingName)
|
||||
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingName')
|
||||
expect(mapped_point).toBe({
|
||||
name : "Bob"
|
||||
})
|
||||
})
|
||||
// test('maps nom_amenageur to name, and keep the same value', () => {
|
||||
// let Mapping_engine = new mapping_engine(mappingName)
|
||||
// let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
// expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingName')
|
||||
// expect(mapped_point.properties).toBe({
|
||||
// name : "Bob"
|
||||
// })
|
||||
// })
|
||||
// test('ignore one value', () => { })
|
||||
// test('conditional value', () => { })
|
||||
// test('conditional transform', () => { })
|
||||
// test('conditional truthy transform', () => { })
|
||||
// test('conditional falsy transform', () => { })
|
||||
// test('conditional phone transform', () => {
|
||||
// let Mapping_engine = new mapping_engine(mappingPhone)
|
||||
// let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
// expect(mapped_point.properties).toBe({phone:'+33123456789'})
|
||||
// })
|
||||
test('conditional falsy 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)
|
||||
let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
expect(mapped_point.properties).toStrictEqual({ phone: '+33123456789' })
|
||||
})
|
||||
})
|
||||
|
||||
xdescribe('filters points', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user