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

Added tests for related works, which are not yet passing

parent cc899ed8
Branches
Tags
No related merge requests found
......@@ -26,13 +26,14 @@ const path = require('path');
const DEFAULTS = path.join(__dirname, "../defaults");
const CONTEXT = path.join(DEFAULTS, 'context.json');
const RELATED = [ 'publications', 'websites', 'metadata', 'data' ];
const RELATED = [ 'publications', 'websites', 'metadata', 'data', 'services' ];
const RELATED_TYPES = {
'publications': 'ScholarlyArticle',
'websites': 'WebSite',
'metadata': 'CreativeWork', // schema.org hasn't got a dedicated type
'data': 'DataSet'
'data': 'DataSet',
'services': 'CreateWork' // I'm not sure about this?
};
const ROOT_PATH = 'data/';
......
......@@ -84,10 +84,10 @@ function get_type(c, t) {
return c['@graph'].filter((item) => item['@type'] === t);
}
function assert_link(prop, item) {
function assert_link(ds, prop, item) {
const id = item['@id'];
expect(cjds).to.have.property(prop);
const links = cjds[prop];
expect(ds).to.have.property(prop);
const links = ds[prop];
const link = links.filter((l) => l['@id'] === id);
expect(link).to.be.an('array');
expect(link).to.have.lengthOf(1);
......@@ -168,7 +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));
files.map((f) => assert_link(cjds, 'hasPart', f));
});
......@@ -187,7 +187,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
} else {
expect(gotsubs).to.be.empty;
}
gotsubs.map((s) => assert_link('about', s));
gotsubs.map((s) => assert_link(cjds, 'about', s));
})
});
......@@ -215,7 +215,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
} else {
expect(gotfunders).to.be.empty;
}
gotfunders.map((s) => assert_link('funder', s));
gotfunders.map((s) => assert_link(cjds, 'funder', s));
});
......@@ -236,14 +236,14 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
expect(matches).to.have.lengthOf(1);
expect(matches[0]['latitude']).to.equal(gl['latitude']);
expect(matches[0]['longitude']).to.equal(gl['longitude']);
assert_link('spatialCoverage', matches[0]);
assert_link(cjds, 'spatialCoverage', matches[0]);
});
}
if( dp['geospatial']) {
const matches = spatials.filter((s) => s['@type'] === 'FeatureCollection' );
expect(matches).to.have.lengthOf(1);
expect(matches[0]['features']).to.eql(dp['geospatial']['features']);
assert_link('spatialCoverage', matches[0]);
assert_link(cjds, 'spatialCoverage', matches[0]);
}
});
......@@ -292,12 +292,37 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
expect(litem['name']).to.equal(dp['license_statement']);
expect(litem['url]']).to.equal(dp['license_statement_url']);
}
assert_link('license', litem);
assert_link(cjds, 'license', litem);
}
});
it("has related works", () => {
assert(false, "Not written yet");
const REL_FIELDS = [ 'publications', 'websites', 'metadata', 'data', 'services' ];
const REL_TYPES = {
'publications': 'ScholarlyArticle',
'websites': 'WebSite',
'metadata': 'CreativeWork',
'data': 'DataSet',
'service': 'CreativeWork'
}
REL_FIELDS.map((f) => {
const field = 'related_' + f;
if( dp[field] ) {
dp[field].map((rw) => {
const id = rw['related_url'];
console.log(JSON.stringify(rw));
console.log("id = " + id);
assert(id, "related_X in datapub has a URL");
const item = get_id(cj, id);
expect(item).to.be.an('object');
expect(item['identifier']).to.equal(id);
expect(item['@type']).to.equal(REL_TYPES[f]);
expect(item['name']).to.equal(dp[field]['related_title']);
expect(item['description']).to.equal(dp[field]['related_notes']);
assert_link(cjds, 'citation', id);
})
}
})
});
......
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