From 728d01ba74ec3d2e73a912034f4e3227aba33e1e Mon Sep 17 00:00:00 2001 From: Tykayn Date: Fri, 18 Aug 2023 12:22:07 +0200 Subject: [PATCH] testing all conditionnal conversions --- data_other/testing/mappings_to_test.ts | 68 +++++++++++++++++++++----- mappings/engine.ts | 3 ++ tests/main.test.js | 50 ++++++++++++++----- 3 files changed, 97 insertions(+), 24 deletions(-) diff --git a/data_other/testing/mappings_to_test.ts b/data_other/testing/mappings_to_test.ts index 164319a..e38fe60 100644 --- a/data_other/testing/mappings_to_test.ts +++ b/data_other/testing/mappings_to_test.ts @@ -63,15 +63,59 @@ export const mappingBoolean: MappingConfigType = { source: {}, filters: {}, } -// export const mappingIgnore: MappingConfigType = { -// config_name: 'testing config', -// config_author: 'tykayn ', -// default_properties_of_point: { -// 'amenity': 'charging_station' -// }, -// tags: { -// nom_amenageur: { -// ignore_this_data: true, -// } -// } -// } \ No newline at end of file +export const mappingTruthy: MappingConfigType = { + + config_name: 'testing config mappingTruthy', + config_author: 'tykayn ', + 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 ', + 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 ', + 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 ', + default_properties_of_point: {}, + tags: { + consolidated_is_lon_lat_correct: { + ignore_if_truthy: true, + }, + }, + add_not_mapped_tags_too: false, + source: {}, + filters: {}, +} \ No newline at end of file diff --git a/mappings/engine.ts b/mappings/engine.ts index bb9cda9..361dec3 100644 --- a/mappings/engine.ts +++ b/mappings/engine.ts @@ -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 diff --git a/tests/main.test.js b/tests/main.test.js index 1669784..b0e4a02 100644 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -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)