wololo/tests/main.test.js

252 lines
No EOL
9.5 KiB
JavaScript

import MappingEngine from '../mappings/engine.ts'
import * as mappings from './data/mappings_to_test'
import utils from '../mappings/utils'
import Formatters from '../mappings/formatters'
const testingGeoJson = require('./data/testing.json')
// import { describe, expect, test } from '@jest/globals'
describe('mapping engine', () => {
test('load mapping config', () => {
let Mapping_engine = new MappingEngine(mappings.mappingSame)
expect(Mapping_engine.getConfig()).toStrictEqual(mappings.mappingSame)
})
})
describe('mapping properties with rich mapping engine', () => {
// test('do not add properties at all when there is nothing in tags of the mapping config', () => {
//
// })
// test('remove all properties when mapping says so', () => {
// 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()
// expect(Object.keys(mapped_point.properties)).toStrictEqual([])
// })
// let Mapping_engine = new MappingEngine(mappings.mappingSame)
// test('maps simple key to key, and keep the same value', () => {
// Mapping_engine.setConfig(mappings.mappingSame)
// let feature_to_test = testingGeoJson.features[0]
// let mapped_point = Mapping_engine.mapElementFromConf(feature_to_test)
// expect(mapped_point.properties).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', () => {
test('conditional truthy transform', () => {
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(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(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('no result with enum transform', () => {
// on ne doit rien garder en cas d'énumération dans une propriété censée être booléenne si elle est une énumération
expect(utils.convertToYesOrNo("True;FALSE")).toStrictEqual('')
})
test('no result with simple transform', () => {
expect(utils.convertToYesOrNo("1")).toStrictEqual('yes')
})
test('no result with simple transform', () => {
expect(utils.convertToYesOrNo("False")).toStrictEqual('no')
})
})
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(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'
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
})
})
describe('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', () => { })
})
describe('find max in enum', () => {
test('value has enums', () => {
let value = '1;2;3;10;4;5;6;7;8;9;'
let max = utils.find_max_in_string(value)
expect(max).toBe(10)
})
test('value has enums with maybe units', () => {
let value = '1;2;3;10 km;4;5 kw;6;7;8;9;'
let max = utils.find_max_in_string(value)
expect(max).toBe(10)
})
test('value has enums with kW units', () => {
let value = '12 kW;120 kW'
let max = utils.find_max_in_string(value)
expect(max).toBe(120)
})
test('value has no enums', () => {
let max = utils.find_max_in_string('10')
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', () => {
test('truncate enums to limit', () => {
let value = '1;2;3;10 km;4;5 kw;6;7;8;9;'
let truncated = utils.truncate_enums_to_limit(value, 5)
expect(truncated).toBe('1;2;')
})
})
describe('formatters tests', () => {
test('format phone', () => {
let phone = '+331 2345 6789'
let formatted = Formatters.convertToPhone(phone)
expect(formatted).toBe('+33 1 23 45 67 89')
})
test('format name', () => {
let name = 'bob lénon'
let formatted = Formatters.convertToName(name)
expect(formatted).toBe('Bob lénon')
})
})