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

refactored the tests so that the datapub and catalog.json are generated

in a before() clause
parent 3dbf788f
Branches
Tags
No related merge requests found
...@@ -162,9 +162,7 @@ async function datapub2catalog(options) { ...@@ -162,9 +162,7 @@ async function datapub2catalog(options) {
if( items ) { if( items ) {
const eitems = items.filter((i) => i); const eitems = items.filter((i) => i);
if( eitems ) { if( eitems ) {
dataset[property] = items.map((i) => { dataset[property] = items.map(link_id);
return { '@id': i['@id'] }
});
graph.push(eitems); graph.push(eitems);
} }
} }
...@@ -205,7 +203,7 @@ function make_dataset(id, datapub, organisation, dates, files) { ...@@ -205,7 +203,7 @@ function make_dataset(id, datapub, organisation, dates, files) {
'description': datapub['description'], 'description': datapub['description'],
'dateCreated': dates['dateCreated'], 'dateCreated': dates['dateCreated'],
'datePublished': dates['datePublished'], 'datePublished': dates['datePublished'],
'Publisher': link_id(organisation), 'publisher': link_id(organisation),
'hasPart': files.map(link_id), 'hasPart': files.map(link_id),
}; };
return ds; return ds;
......
...@@ -48,30 +48,36 @@ function graph_get(graph, id) { ...@@ -48,30 +48,36 @@ function graph_get(graph, id) {
} }
} }
var dp, cj;
describe("ReDBox data publication to DataCrate catalog.json", () => { describe("DataPub to DataCrate: core metadata", () => {
it("returns a catalog with a dataset item", async () => { before(async () => {
const dp = await fs.readJson('./test_data/datapub.json'); dp = await fs.readJson('./test_data/datapub.json');
const cj = await catalog.datapub2catalog({ cj = await catalog.datapub2catalog({
'id': DATASET_ID, 'id': DATASET_ID,
'datapub': dp, 'datapub': dp,
'organisation': ORG, 'organisation': ORG,
'owner': OWNER, 'owner': OWNER,
'approver': APPROVER 'approver': APPROVER
}); });
});
it("puts a dataset item with correct metadata in the catalog", async () => {
assert(cj, "Got an object"); assert(cj, "Got an object");
assert(cj['@graph'], "Catalog has a @graph"); assert(cj['@graph'], "Catalog has a @graph");
const dataset = graph_get(cj['@graph'], DATASET_ID); const dataset = graph_get(cj['@graph'], DATASET_ID);
assert(dataset, "Graph has an item with id " + DATASET_ID); assert(dataset, "Graph has an item with id " + DATASET_ID);
expect(dataset['name']).to.equal(dp['title']); expect(dataset['name']).to.equal(dp['title']);
expect(dataset['description']).to.equal(dp['description']); expect(dataset['description']).to.equal(dp['description']);
expect(dataset['publisher']['@id']).to.equal(ORG['id']);
}); });
it("Can set dateCreated and datePublished", async() => { it("has a history section with the owner and approver", async () => {
assert(true); assert(true);
}) });
}); });
......
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