diff --git a/lib/streams/gnafMapperStream.js b/lib/streams/gnafMapperStream.js index 9e71b7069..805bc8917 100644 --- a/lib/streams/gnafMapperStream.js +++ b/lib/streams/gnafMapperStream.js @@ -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 }); } } diff --git a/test/streams/gnafMapperStream.js b/test/streams/gnafMapperStream.js index dfb97c55f..255672994 100644 --- a/test/streams/gnafMapperStream.js +++ b/test/streams/gnafMapperStream.js @@ -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', { @@ -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