From 9b3b277d4ece77080c714eb03d3f57a8cad4a747 Mon Sep 17 00:00:00 2001 From: Mike Lynch <mike@mikelynch.org> Date: Tue, 13 Nov 2018 16:20:16 +1100 Subject: [PATCH] refactored the tests so that the datapub and catalog.json are generated in a before() clause --- lib/catalog.js | 6 ++---- test/catalog.spec.js | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/catalog.js b/lib/catalog.js index a24638a..c9f509d 100644 --- a/lib/catalog.js +++ b/lib/catalog.js @@ -162,9 +162,7 @@ async function datapub2catalog(options) { if( items ) { const eitems = items.filter((i) => i); if( eitems ) { - dataset[property] = items.map((i) => { - return { '@id': i['@id'] } - }); + dataset[property] = items.map(link_id); graph.push(eitems); } } @@ -205,7 +203,7 @@ function make_dataset(id, datapub, organisation, dates, files) { 'description': datapub['description'], 'dateCreated': dates['dateCreated'], 'datePublished': dates['datePublished'], - 'Publisher': link_id(organisation), + 'publisher': link_id(organisation), 'hasPart': files.map(link_id), }; return ds; diff --git a/test/catalog.spec.js b/test/catalog.spec.js index 6901357..e57ba95 100644 --- a/test/catalog.spec.js +++ b/test/catalog.spec.js @@ -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 () => { - const dp = await fs.readJson('./test_data/datapub.json'); - const cj = await catalog.datapub2catalog({ + before(async () => { + dp = await fs.readJson('./test_data/datapub.json'); + cj = await catalog.datapub2catalog({ 'id': DATASET_ID, 'datapub': dp, 'organisation': ORG, 'owner': OWNER, 'approver': APPROVER - }); + }); + }); + + + it("puts a dataset item with correct metadata in the catalog", async () => { assert(cj, "Got an object"); assert(cj['@graph'], "Catalog has a @graph"); const dataset = graph_get(cj['@graph'], DATASET_ID); assert(dataset, "Graph has an item with id " + DATASET_ID); expect(dataset['name']).to.equal(dp['title']); 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); - }) + }); }); -- GitLab