mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
286 lines
7.1 KiB
286 lines
7.1 KiB
8 years ago
|
const _ = require('lodash');
|
||
8 years ago
|
const sanitizer = require('../../../sanitizer/_city_name_standardizer');
|
||
8 years ago
|
|
||
|
module.exports.tests = {};
|
||
|
|
||
|
module.exports.tests.text_parser = function(test, common) {
|
||
|
test('clean without parsed_text should not throw exception', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('undefined parsed_text.city should be unchanged', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
|
address: 'address value',
|
||
|
city: undefined
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
|
address: 'address value',
|
||
|
city: undefined
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('\'saint\' should be abbreviated to \'st\' wherever it appears in the city', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
|
query: 'saint query value',
|
||
|
neighbourhood: 'saint neighbourhood value',
|
||
|
borough: 'saint borough value',
|
||
8 years ago
|
city: 'SainT city sAiNt value saInt',
|
||
8 years ago
|
county: 'saint county value',
|
||
|
state: 'saint state value',
|
||
|
postalcode: 'saint postalcode value',
|
||
|
country: 'saint country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
|
query: 'saint query value',
|
||
|
neighbourhood: 'saint neighbourhood value',
|
||
|
borough: 'saint borough value',
|
||
|
city: 'st city st value st',
|
||
|
county: 'saint county value',
|
||
|
state: 'saint state value',
|
||
|
postalcode: 'saint postalcode value',
|
||
|
country: 'saint country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('\'sainte\' should be abbreviated to \'ste\' wherever it appears in the city', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
|
query: 'sainte query value',
|
||
|
neighbourhood: 'sainte neighbourhood value',
|
||
|
borough: 'sainte borough value',
|
||
8 years ago
|
city: 'SaintE city sAinTe value saINte',
|
||
8 years ago
|
county: 'sainte county value',
|
||
|
state: 'sainte state value',
|
||
|
postalcode: 'sainte postalcode value',
|
||
|
country: 'sainte country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
|
query: 'sainte query value',
|
||
|
neighbourhood: 'sainte neighbourhood value',
|
||
|
borough: 'sainte borough value',
|
||
|
city: 'ste city ste value ste',
|
||
|
county: 'sainte county value',
|
||
|
state: 'sainte state value',
|
||
|
postalcode: 'sainte postalcode value',
|
||
|
country: 'sainte country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('\'ft\' should be expanded to \'fort\' wherever it appears in the city', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
|
query: 'ft query value',
|
||
|
neighbourhood: 'ft neighbourhood value',
|
||
|
borough: 'ft borough value',
|
||
8 years ago
|
city: 'Ft city ft value fT',
|
||
8 years ago
|
county: 'ft county value',
|
||
|
state: 'ft state value',
|
||
|
postalcode: 'ft postalcode value',
|
||
|
country: 'ft country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
|
query: 'ft query value',
|
||
|
neighbourhood: 'ft neighbourhood value',
|
||
|
borough: 'ft borough value',
|
||
|
city: 'fort city fort value fort',
|
||
|
county: 'ft county value',
|
||
|
state: 'ft state value',
|
||
|
postalcode: 'ft postalcode value',
|
||
|
country: 'ft country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('\'mt\' should be expanded to \'mount\' wherever it appears in the city', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
|
query: 'mt query value',
|
||
|
neighbourhood: 'mt neighbourhood value',
|
||
|
borough: 'mt borough value',
|
||
8 years ago
|
city: 'Mt city mt value mT',
|
||
8 years ago
|
county: 'mt county value',
|
||
|
state: 'mt state value',
|
||
|
postalcode: 'mt postalcode value',
|
||
|
country: 'mt country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
|
query: 'mt query value',
|
||
|
neighbourhood: 'mt neighbourhood value',
|
||
|
borough: 'mt borough value',
|
||
|
city: 'mount city mount value mount',
|
||
|
county: 'mt county value',
|
||
|
state: 'mt state value',
|
||
|
postalcode: 'mt postalcode value',
|
||
|
country: 'mt country value'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('mixture of \'mt\', \'ft\', \'saint\', and \'sainte\' should be expanded/abbreviated', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
8 years ago
|
city: 'mt. ft saint sainte mt ft.'
|
||
8 years ago
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
8 years ago
|
city: 'mount fort st ste mount fort'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('period word boundary on \'mt.\' should replace with a space', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
|
city: 'mt.city'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
|
city: 'mount city'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
test('period word boundary on \'ft.\' should replace with a space', function(t) {
|
||
|
const raw = {};
|
||
|
|
||
|
const clean = {
|
||
|
parsed_text: {
|
||
|
city: 'ft.city'
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const expected_clean = {
|
||
|
parsed_text: {
|
||
|
city: 'fort city'
|
||
8 years ago
|
}
|
||
|
};
|
||
|
|
||
|
const messages = sanitizer(raw, clean);
|
||
|
|
||
|
t.deepEquals(clean, expected_clean);
|
||
|
t.deepEquals(messages.errors, [], 'no errors');
|
||
|
t.deepEquals(messages.warnings, [], 'no warnings');
|
||
|
t.end();
|
||
|
|
||
|
});
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports.all = function (tape, common) {
|
||
|
function test(name, testFunction) {
|
||
8 years ago
|
return tape('sanitizer _city_name_standardizer: ' + name, testFunction);
|
||
8 years ago
|
}
|
||
|
|
||
|
for( const testCase in module.exports.tests ){
|
||
|
module.exports.tests[testCase](test, common);
|
||
|
}
|
||
|
};
|