Skip to content

Commit

Permalink
fix(gnaf): silence gnaf mapper warning when ID field is undefined (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink authored Mar 31, 2022
1 parent 9757c13 commit 5a99348
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/streams/gnafMapperStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function () {

// detect Australian G-NAF PID concordances
const oaid = _.get(doc.getMeta('oa'), 'ID');
if (oaid.length === 14 && oaid.match(GNAF_PID_PATTERN)) {
if (_.isString(oaid) && oaid.length === 14 && oaid.match(GNAF_PID_PATTERN)) {
doc.setAddendum('concordances', { 'gnaf:pid': oaid });
}
}
Expand Down
23 changes: 22 additions & 1 deletion test/streams/gnafMapperStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports.tests.au_gnaf_id = function (test) {
});
};

module.exports.tests.non_au_gnaf_id = function (test) {
module.exports.tests.au_invalid_gnaf_id = function (test) {
var doc = new Document('oa', 'a', 1);
doc.setMeta('country_code', 'AU');
doc.setMeta('oa', {
Expand All @@ -64,6 +64,27 @@ module.exports.tests.non_au_gnaf_id = function (test) {
});
};

module.exports.tests.au_missing_id_field = function (test) {
var doc = new Document('oa', 'a', 1);
doc.setMeta('country_code', 'AU');
doc.setMeta('oa', {
ID: undefined, // note: missing ID field
NUMBER: '360',
STREET: 'BRUNSWICK STREET',
LAT: -37.79647546,
LON: 144.978997
});
test('maps - GNAF ID', t => {
var stream = mapper();
stream.pipe(through.obj((doc, enc, next) => {
t.deepEqual(doc.getAddendum('concordances'), undefined);
t.end();
next();
}));
stream.write(doc);
});
};

module.exports.tests.non_au_gnaf_id = function (test) {
var doc = new Document('oa', 'a', 1);
doc.setMeta('country_code', 'NZ'); // note: country code not AU
Expand Down

0 comments on commit 5a99348

Please sign in to comment.