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