mirror of
https://forge.chapril.org/tykayn/wololo
synced 2025-06-20 01:34:42 +02:00
tests update
This commit is contained in:
parent
088aa1f5f4
commit
353fa37c85
4 changed files with 49 additions and 24 deletions
|
@ -1,4 +1,3 @@
|
|||
|
||||
import MappingConfigType from "./mapping-config.type";
|
||||
import Formatters from "./formatters";
|
||||
import config from "../config";
|
||||
|
@ -22,8 +21,8 @@ export default class MappingEngine {
|
|||
private current_geojson_point: any; // currently converting point
|
||||
|
||||
constructor(mappingConfig: MappingConfigType) {
|
||||
this.mapping_config = mappingConfig;
|
||||
|
||||
this.setConfig(mappingConfig)
|
||||
this.stats = {
|
||||
filtered_by_excluded_tags: 0,
|
||||
phones_updated: 0,
|
||||
|
@ -35,9 +34,8 @@ export default class MappingEngine {
|
|||
}
|
||||
|
||||
setConfig(mappingConfig: MappingConfigType) {
|
||||
debugLog('load config', mappingConfig.config_name)
|
||||
debugLog('load config', mappingConfig.config_name)
|
||||
this.mapping_config = mappingConfig
|
||||
//debugLog('load config', mappingConfig.config_name);
|
||||
this.mapping_config = mappingConfig;
|
||||
}
|
||||
|
||||
getConfig() {
|
||||
|
@ -411,10 +409,10 @@ export default class MappingEngine {
|
|||
if (configObject.remove_original_key) {
|
||||
remove_original_key = true
|
||||
}
|
||||
if (configObject.ignore_if_falsy && custom_utils.falsyValues.indexOf(originalValue) !== -1) {
|
||||
if (configObject.ignore_if_falsy && custom_utils.falsyValues.indexOf(this.convertToBoolean(originalValue)) !== -1) {
|
||||
remove_original_key = true
|
||||
}
|
||||
if (configObject.ignore_if_truthy && custom_utils.truthyValues.indexOf(originalValue) !== -1) {
|
||||
if (configObject.ignore_if_truthy && custom_utils.truthyValues.indexOf(this.convertToBoolean(originalValue)) !== -1) {
|
||||
remove_original_key = true
|
||||
}
|
||||
|
||||
|
|
|
@ -144,5 +144,21 @@ export const mappingIgnoreTruthy: MappingConfigType = {
|
|||
geojson_path: "",
|
||||
url: ""
|
||||
},
|
||||
tags_to_ignore_if_value_is: ['non spécifié'],
|
||||
filters: {},
|
||||
}
|
||||
|
||||
export const mappingIgnoreOsmId: MappingConfigType = {
|
||||
config_name: 'testing config mappingIgnoreOsmId',
|
||||
config_author: 'tykayn <contact@cipherbliss.com>',
|
||||
default_properties_of_point: {},
|
||||
tags: {},
|
||||
add_not_mapped_tags_too: false,
|
||||
source: {
|
||||
geojson_path: "",
|
||||
url: ""
|
||||
},
|
||||
filters: {
|
||||
exclude_point_if_tag_not_empty: ['osm_id'],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
"equal": "same value",
|
||||
"consolidated_commune": "S\u00e9r\u00e9zin-du-Rh\u00f4ne",
|
||||
"consolidated_is_lon_lat_correct": true,
|
||||
"consolidated_city": false
|
||||
"consolidated_city": false,
|
||||
"osm_id": 1234567890,
|
||||
"non_spécifié": "non spécifié"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
import MappingEngine from '../mappings/engine.ts'
|
||||
import {
|
||||
mappingPhone,
|
||||
mappingRemoveAll,
|
||||
mappingBoolean,
|
||||
mappingName,
|
||||
mappingSame, mappingTruthy, mappingFalsy, mappingIgnoreFalsy, mappingIgnoreTruthy
|
||||
} from './data/mappings_to_test'
|
||||
import * as mappings from './data/mappings_to_test'
|
||||
import utils from '../mappings/utils'
|
||||
import Formatters from '../mappings/formatters'
|
||||
|
||||
|
@ -20,7 +14,8 @@ describe('mapping properties with rich mapping engine', () => {
|
|||
// })
|
||||
|
||||
// test('remove all properties when mapping says so', () => {
|
||||
// let Mapping_engine = new mapping_engine(mappingRemoveAll)
|
||||
// let Mapping_engine = new MappingEngine(mappings.mappingRemoveAll)
|
||||
// Mapping_engine.setConfig(mappings.mappingRemoveAll)
|
||||
// let feature_to_test = testingGeoJson.features[0]
|
||||
// let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
// expect(mapped_point).toBeTruthy()
|
||||
|
@ -58,42 +53,56 @@ describe('convert boolean keys', () => {
|
|||
|
||||
|
||||
test('conditional truthy transform', () => {
|
||||
let Mapping_engine = new MappingEngine(mappingTruthy)
|
||||
let Mapping_engine = new MappingEngine(mappings.mappingTruthy)
|
||||
Mapping_engine.setConfig(mappings.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 MappingEngine(mappingFalsy)
|
||||
let Mapping_engine = new MappingEngine(mappings.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 MappingEngine(mappingBoolean)
|
||||
let Mapping_engine = new MappingEngine(mappings.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 Mapping_engine = new MappingEngine(mappings.mappingIgnoreTruthy)
|
||||
// Mapping_engine.setConfig(mappings.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 Mapping_engine = new MappingEngine(mappings.mappingIgnoreFalsy)
|
||||
// let feature_to_test = testingGeoJson.features[0]
|
||||
// let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
|
||||
// expect(mapped_point.properties).toStrictEqual({})
|
||||
// })
|
||||
})
|
||||
|
||||
describe('ignore points having osm id', () => {
|
||||
test('ignore points having osm id', () => {
|
||||
if (mappings.mappingIgnoreOsmId) {
|
||||
|
||||
let Mapping_engine = new MappingEngine(mappings.mappingIgnoreOsmId)
|
||||
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 MappingEngine(mappingPhone)
|
||||
let Mapping_engine = new MappingEngine(mappings.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'
|
||||
|
@ -156,7 +165,7 @@ describe('convert phone numbers', () => {
|
|||
// +19 0142056650;+19 0664534050
|
||||
})
|
||||
})
|
||||
xdescribe('filters points', () => {
|
||||
describe('filters points', () => {
|
||||
test('filter no points', () => { })
|
||||
test('filter only one point', () => { })
|
||||
test('filter X number of points', () => { })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue