This commit is contained in:
Tykayn 2025-01-15 22:20:14 +01:00 committed by tykayn
commit 996524bc6d
107 changed files with 1295536 additions and 0 deletions

View file

@ -0,0 +1,148 @@
import MappingConfigType from "../../mappings/mapping-config.type";
/**
* configurations de mapping pour les cas de tests
*/
export const mappingRemoveAll: MappingConfigType = {
config_name: 'testing config mappingRemoveAll',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {},
add_not_mapped_tags_too: false,
source: {
geojson_path: "",
url: ""
},
filters: {},
}
export const mappingSame: MappingConfigType = {
config_name: 'testing config mappingSame',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
equal: 'equal'
},
add_not_mapped_tags_too: false,
source: {
geojson_path: "",
url: ""
},
filters: {},
}
export const mappingName: MappingConfigType = {
config_name: 'testing config mappingName',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
add_not_mapped_tags_too: false,
tags: {
nom_amenageur: 'name'
},
source: {
geojson_path: "",
url: ""
},
filters: {},
}
export const mappingPhone: MappingConfigType = {
config_name: 'testing config mappingPhone',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
telephone_operateur: {
key_converted: 'phone',
convert_to_phone: true, // convertit en yes ou no
},
},
add_not_mapped_tags_too: false,
source: {
geojson_path: "",
url: ""
},
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: {
geojson_path: "",
url: ""
},
filters: {},
}
export const mappingTruthy: MappingConfigType = {
config_name: 'testing config mappingTruthy',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_is_lon_lat_correct: {
truthy_value: "succès",
},
},
add_not_mapped_tags_too: false,
source: {
geojson_path: "",
url: ""
},
filters: {},
}
export const mappingFalsy: MappingConfigType = {
config_name: 'testing config mappingFalsy',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_city: {
falsy_value: "pas ouf succès",
},
},
add_not_mapped_tags_too: false,
source: {
geojson_path: "",
url: ""
},
filters: {},
}
export const mappingIgnoreFalsy: MappingConfigType = {
config_name: 'testing config mappingIgnore',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_city: {
ignore_if_falsy: true,
},
},
add_not_mapped_tags_too: false,
source: {
geojson_path: "",
url: ""
},
filters: {},
}
export const mappingIgnoreTruthy: MappingConfigType = {
config_name: 'testing config mappingIgnore',
config_author: 'tykayn <contact@cipherbliss.com>',
default_properties_of_point: {},
tags: {
consolidated_is_lon_lat_correct: {
ignore_if_truthy: true,
},
},
add_not_mapped_tags_too: false,
source: {
geojson_path: "",
url: ""
},
filters: {},
}

24
tests/data/testing.json Normal file
View file

@ -0,0 +1,24 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
4.822159,
45.635079
]
},
"properties": {
"nom_amenageur": "Bob",
"siren_amenageur": "891624884",
"telephone_operateur": "0123456789",
"equal": "same value",
"consolidated_commune": "S\u00e9r\u00e9zin-du-Rh\u00f4ne",
"consolidated_is_lon_lat_correct": true,
"consolidated_city": false
}
}
]
}

164
tests/main.test.js Normal file
View file

@ -0,0 +1,164 @@
import mapping_engine from '../mappings/engine.ts'
import {
mappingPhone,
mappingRemoveAll,
mappingBoolean,
mappingName,
mappingSame, mappingTruthy, mappingFalsy, mappingIgnoreFalsy, mappingIgnoreTruthy
} from './data/mappings_to_test'
const testingGeoJson = require('./data/testing.json')
// import { describe, expect, test } from '@jest/globals'
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 )
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 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)
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 })
feature_to_test.properties.telephone_operateur = '3615'
expected_converted_phone = '+33 36 15'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '+33 6 12928883'
expected_converted_phone = '+33 6 12 92 88 83'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '+(33)-(9)-69366018'
expected_converted_phone = '+33 9 69 36 60 18'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '0811 69 06 06'
expected_converted_phone = '+33 8 11 69 06 06'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '+ 33 1 30 31 30 46 (numéro unique)'
expected_converted_phone = '+33 1 30 31 30 46'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '+ 3 3 1 3 0 3 13046 (numéro unique)'
expected_converted_phone = '+33 1 30 31 30 46'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '3 56 80 09'
expected_converted_phone = '+33 3 56 80 09'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '+ 33 1 30 31 30 46 (numéro unique)'
expected_converted_phone = '+33 1 30 31 30 46'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = 'Stations-e'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ })
feature_to_test.properties.telephone_operateur = '+33 0 7 66 38 74 96'
expected_converted_phone = '+33 7 66 38 74 96'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
feature_to_test.properties.telephone_operateur = '+ 33 1 30 31 30 46 (numéro unique)'
expected_converted_phone = '+33 1 30 31 30 46'
mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
expect(mapped_point.properties).toStrictEqual({ phone: expected_converted_phone })
// +19 0142056650;+19 0664534050
})
})
xdescribe('filters points', () => {
test('filter no points', () => { })
test('filter only one point', () => { })
test('filter X number of points', () => { })
test('filter city points', () => { })
test('filter bounding box', () => { })
test('filter combo, city', () => { })
test('filter combo, city + bbox', () => { })
test('filter combo, city + bbox + offset', () => { })
})
/**
* thats a roadmap, yes
*/
xdescribe('infer domain of values from csv file', () => {
test('gets the list of unique values in column', () => { })
})
xdescribe('infer domain of values from geojson file', () => {
test('gets the list of unique values in column', () => { })
})
xdescribe('build mapping engine config from unique values', () => {
test('builds a valid mapping config', () => { })
})