Skip to content
Snippets Groups Projects
Commit 1a0f428f authored by Mike Lynch's avatar Mike Lynch
Browse files

Found a bug in the loop which linked items like subjects and related works back to

the dataset, which was leaving the ids empty
parent 4181cc4a
Branches
Tags
No related merge requests found
......@@ -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);
}
}
});
......
......@@ -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");
});
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment