diff --git a/data_other/testing/mappings_to_test.ts b/data_other/testing/mappings_to_test.ts index e4d5627..164319a 100644 --- a/data_other/testing/mappings_to_test.ts +++ b/data_other/testing/mappings_to_test.ts @@ -49,6 +49,20 @@ export const mappingPhone: MappingConfigType = { source: {}, filters: {}, } +export const mappingBoolean: MappingConfigType = { + + config_name: 'testing config mappingBoolean', + config_author: 'tykayn ', + 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 ', diff --git a/data_other/testing/testing.json b/data_other/testing/testing.json index fd99ec8..5a791c4 100644 --- a/data_other/testing/testing.json +++ b/data_other/testing/testing.json @@ -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 } } ] diff --git a/mappings/converters/configTest.ts b/mappings/converters/configTest.ts index 5a3bf04..beeed49 100644 --- a/mappings/converters/configTest.ts +++ b/mappings/converters/configTest.ts @@ -10,7 +10,9 @@ const MappingTest: MappingConfigType = { config_author: 'tykayn ', 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: {}, diff --git a/mappings/engine.ts b/mappings/engine.ts index 3a875b5..0a85680 100644 --- a/mappings/engine.ts +++ b/mappings/engine.ts @@ -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) @@ -245,7 +249,7 @@ export default class { if (configObject.convert_to_phone) { console.log('originalValue', originalValue.substring(1)) let temp = `${'' + originalValue.substring(1)}` - convertedValue = `+33 ${temp}`; + convertedValue = `+33${temp}`; } if (configObject.remove_original_key) { remove_original_key = true @@ -327,11 +331,11 @@ 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{ + } else { debugLog('!!!!!! property not found in mappingKeys: ', pointKeyName) } } diff --git a/output/my_converted_data_set.json b/output/my_converted_data_set.json index 149f6ab..3249233 100644 --- a/output/my_converted_data_set.json +++ b/output/my_converted_data_set.json @@ -11,7 +11,7 @@ ] }, "properties": { - "name": "Bob" + "consolidated_is_lon_lat_correct": "yes" } } ] diff --git a/tests/main.test.js b/tests/main.test.js index 1669206..12217ab 100644 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -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', () => {