diff --git a/lib/catalog.js b/lib/catalog.js index ae080147c63a3b6e175d963fd869475ff4a3cfb7..efd9e7c22a3ef4d69c86af62af546420b09ed794 100644 --- a/lib/catalog.js +++ b/lib/catalog.js @@ -168,10 +168,10 @@ async function datapub2catalog(options) { _.forEach(DATASET_PROPERTIES, ( make_items, property ) => { const items = make_items(datapub, prefixes[property]); if( items && items.length > 0 ) { - const eitems = items.filter((i) => i); + const eitems = _.flatten(items.filter((i) => i)); if( eitems ) { - dataset[property] = items.map(link_id); - graph.push(..._.flatten(eitems)); + dataset[property] = eitems.map(link_id); + graph.push(...eitems); } } }); diff --git a/test/catalog.spec.js b/test/catalog.spec.js index 2a769ca53c2d6735b213702fea57aab0b8e9c8fe..42d4f0e4284ba8447116fcdafb3f3daeb46102a1 100644 --- a/test/catalog.spec.js +++ b/test/catalog.spec.js @@ -84,6 +84,15 @@ function get_type(c, t) { return c['@graph'].filter((item) => item['@type'] === t); } +function assert_link(prop, item) { + const id = item['@id']; + expect(cjds).to.have.property(prop); + const links = cjds[prop]; + const link = links.filter((l) => l['@id'] === id); + expect(link).to.be.an('array'); + expect(link).to.have.lengthOf(1); +} + @@ -124,6 +133,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { }); + it("has a dataset item with correct metadata", () => { assert(cj, "Got an object"); assert(cj['@graph'], "Catalog has a @graph"); @@ -158,6 +168,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { const fids = files.map((f) => f['@id']).sort(); const dlids = datalocs.map((dl) => dl['name']).sort(); expect(fids).to.eql(dlids); + files.map((f) => assert_link('hasPart', f)); }); @@ -168,13 +179,15 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { const about = cjds['about'].map((i) => i['@id']); _.forEach(fields, (field) => { const pref = IRI_PREFIXES['about'][field]; - const expectsubs = dp[field].map((f) => f['name']); - const gotsubs = get_id_prefix(cj, pref).map((f) => f['name']); + const expectnames = dp[field].map((f) => f['name']); + const gotsubs = get_id_prefix(cj, pref) + const gotnames = gotsubs.map((f) => f['name']); if( dp[field] && dp[field].length > 0 ) { - expect(gotsubs.sort()).to.eql(expectsubs.sort()); + expect(gotnames.sort()).to.eql(expectnames.sort()); } else { expect(gotsubs).to.be.empty; } + gotsubs.map((s) => assert_link('about', s)); }) }); @@ -255,7 +268,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { }); it("has related works", () => { - assert(false, "Not written yet"); + });