Browse Source

feat(libpostal_patch): additional tests

pull/1216/head
Peter Johnson 6 years ago
parent
commit
4e8a5385f4
  1. 4
      controller/libpostal.js
  2. 120
      test/unit/controller/libpostal.js

4
controller/libpostal.js

@ -166,8 +166,8 @@ function patchBuggyResponses(response){
if( _.isPlainObject(house_number) && !_.isPlainObject(unit) && _.isString(house_number.value) ){
let split = _.trim(_.trim(house_number.value),'/').split('/');
if( split.length === 2 ){
response[house_number._pos].value = split[1]; // second part (house number)
response.push({ label: 'unit', value: split[0] }); // first part (unit number)
response[house_number._pos].value = _.trim(split[1]); // second part (house number)
response.push({ label: 'unit', value: _.trim(split[0]) }); // first part (unit number)
}
}

120
test/unit/controller/libpostal.js

@ -456,6 +456,126 @@ module.exports.tests.bug_fixes = (test, common) => {
});
test('bug fix: correctly parse australian-style unit numbers - with plus', t => {
const service = (req, callback) => {
const response = [
{
'label': 'house_number',
'value': '2+3/32'
},
{
'label': 'road',
'value': 'dixon street'
},
{
'label': 'suburb',
'value': 'strathpine'
},
{
'label': 'postcode',
'value': '4500'
},
{
'label': 'state',
'value': 'qld'
}
];
callback(null, response);
};
const controller = libpostal(service, () => true);
const req = {
clean: {
text: 'original query'
},
errors: []
};
controller(req, undefined, () => {
t.deepEquals(req, {
clean: {
text: 'original query',
parser: 'libpostal',
parsed_text: {
unit: '2+3',
number: '32',
street: 'dixon street',
neighbourhood: 'strathpine',
postalcode: '4500',
state: 'qld'
}
},
errors: []
}, 'req should not have been modified');
t.end();
});
});
test('bug fix: correctly parse australian-style unit numbers - with unit spelled out', t => {
const service = (req, callback) => {
const response = [
{
'label': 'house_number',
'value': 'unit 3 /30'
},
{
'label': 'road',
'value': 'dan rees street'
},
{
'label': 'suburb',
'value': 'wallsend'
},
{
'label': 'postcode',
'value': '2287'
},
{
'label': 'state',
'value': 'nsw'
}
];
callback(null, response);
};
const controller = libpostal(service, () => true);
const req = {
clean: {
text: 'original query'
},
errors: []
};
controller(req, undefined, () => {
t.deepEquals(req, {
clean: {
text: 'original query',
parser: 'libpostal',
parsed_text: {
unit: 'unit 3',
number: '30',
street: 'dan rees street',
neighbourhood: 'wallsend',
postalcode: '2287',
state: 'nsw'
}
},
errors: []
}, 'req should not have been modified');
t.end();
});
});
test('bug fix: correctly parse australian-style unit numbers - no-op if "unit" already assigned', t => {
const service = (req, callback) => {
const response = [

Loading…
Cancel
Save