diff --git a/tests/data/mappings_to_test.js b/tests/data/mappings_to_test.js new file mode 100644 index 0000000..1e0bad3 --- /dev/null +++ b/tests/data/mappings_to_test.js @@ -0,0 +1,43 @@ +export const mappingTruthy = { + config_name: 'testing config mappingTruthy', + tags: { + consolidated_is_lon_lat_correct: { + key_converted: 'consolidated_is_lon_lat_correct', + truthy_value: 'succès' + } + }, + default_properties_of_point: {} +}; + +export const mappingFalsy = { + config_name: 'testing config mappingFalsy', + tags: { + consolidated_city: { + key_converted: 'consolidated_city', + falsy_value: 'pas ouf succès' + } + }, + default_properties_of_point: {} +}; + +export const mappingBoolean = { + config_name: 'testing config mappingBoolean', + tags: { + consolidated_is_lon_lat_correct: { + key_converted: 'consolidated_is_lon_lat_correct', + convert_to_boolean_value: true + } + }, + default_properties_of_point: {} +}; + +export const mappingPhone = { + config_name: 'testing config mappingPhone', + tags: { + telephone_operateur: { + key_converted: 'phone', + convert_to_phone: true + } + }, + default_properties_of_point: {} +}; \ No newline at end of file diff --git a/tests/main.test.js b/tests/main.test.js index e85b3ce..2d94391 100644 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -1,4 +1,4 @@ -import mapping_engine from '../mappings/engine.ts' +import MappingEngine from '../mappings/engine.ts' import { mappingPhone, mappingRemoveAll, @@ -18,67 +18,83 @@ 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] - test('remove all properties when mapping says so', () => { - let Mapping_engine = new mapping_engine(mappingRemoveAll) - let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test) - expect(mapped_point).toBeTruthy() - 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 newProperties = Mapping_engine.convertProperty('equal', - Object.keys(mappingSame.tags), - feature_to_test, - mappingSame.default_properties_of_point) + // test('remove all properties when mapping says so', () => { + // let Mapping_engine = new mapping_engine(mappingRemoveAll) + // let feature_to_test = testingGeoJson.features[0] + // let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test) + // expect(mapped_point).toBeTruthy() + // 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 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') + // }) + // test('maps nom_amenageur to name, and keep the same value', () => { + // let Mapping_engine = new mapping_engine(mappingName) + // let newProperties = Mapping_engine.convertProperty('nom_amenageur', Object.keys(mappingName.tags), feature_to_test, mappingName.default_properties_of_point) + // expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingName') + + // expect(newProperties).toStrictEqual({ + // name: "Bob" + // }) + // }) + +}) + +describe('convert boolean keys', () => { - 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') - }) - test('maps nom_amenageur to name, and keep the same value', () => { - let Mapping_engine = new mapping_engine(mappingName) - let newProperties = Mapping_engine.convertProperty('nom_amenageur', Object.keys(mappingName.tags), feature_to_test, mappingName.default_properties_of_point) - expect(Mapping_engine.getConfig().config_name).toBe('testing config mappingName') - expect(newProperties).toStrictEqual({ - name: "Bob" - }) - }) - 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', () => { - let Mapping_engine = new mapping_engine(mappingTruthy) + let Mapping_engine = new MappingEngine(mappingTruthy) + let feature_to_test = testingGeoJson.features[0] 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 Mapping_engine = new MappingEngine(mappingFalsy) + let feature_to_test = testingGeoJson.features[0] 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 MappingEngine(mappingBoolean) + let feature_to_test = testingGeoJson.features[0] let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test) expect(mapped_point.properties).toStrictEqual({ consolidated_is_lon_lat_correct: 'yes' }) }) + + // test('ignore one value if it is truthy', () => { + // let Mapping_engine = new MappingEngine(mappingIgnoreTruthy) + // let feature_to_test = testingGeoJson.features[0] + // 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 MappingEngine(mappingIgnoreFalsy) + // let feature_to_test = testingGeoJson.features[0] + // let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test) + // expect(mapped_point.properties).toStrictEqual({}) + // }) +}) + +describe('convert phone numbers', () => { + test('conditional phone transform', () => { - let Mapping_engine = new mapping_engine(mappingPhone) + let Mapping_engine = new MappingEngine(mappingPhone) + let feature_to_test = testingGeoJson.features[0] let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test) let expected_converted_phone = '+33 1 23 45 67 89' expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone }) @@ -140,7 +156,6 @@ describe('mapping properties with rich mapping engine', () => { // +19 0142056650;+19 0664534050 }) }) - xdescribe('filters points', () => { test('filter no points', () => { }) test('filter only one point', () => { }) @@ -187,6 +202,12 @@ describe('find max in enum', () => { console.log('max', max) expect(max).toBe(10) }) + test('value has no enums and unit', () => { + let max = utils.find_max_in_string('10kw') + console.log('max', max) + expect(max).toBe(10) + }) + }) describe('truncate enums to limit', () => {