Skip to content

Commit

Permalink
feat(post): bugfix for alphanumeric postcodes post-processing script
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink committed May 27, 2024
1 parent f64cd68 commit a9e4865
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion post/alphanumeric_postcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function postcodes( doc ){

// ensure postcode is alphanumeric
let matches = postcode.match(ALPHANUMERIC_POSTCODE);
if( matches.length !== 4 ){ return; }
if( !Array.isArray( matches ) || matches.length !== 4 ){ return; }

// generate postcode aliases for the postcode.
let [ , numeric, spaces, alpha ] = matches;
Expand Down
21 changes: 21 additions & 0 deletions test/post/alphanumeric_postcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ module.exports.tests.noop = function(test) {

t.end();
});

test('noop: no postcode', function(t) {
const doc = new Document('mysource','address','myid');

// no alias added
t.deepEqual(doc.getAddressAliases('zip'), [], 'no alias set');

t.end();
});

test('noop: no numeric', function(t) {
const doc = new Document('mysource','address','myid');

// set postcode
doc.setAddress('zip', '3040');

// no alias added
t.deepEqual(doc.getAddressAliases('zip'), [], 'no alias set');

t.end();
});
};

module.exports.all = function (tape, common) {
Expand Down

0 comments on commit a9e4865

Please sign in to comment.