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

more complete file / datalocation comparison tests

parent 9b3b277d
Branches
Tags v1.0.5
No related merge requests found
...@@ -25,10 +25,8 @@ const file = chaiFiles.file; ...@@ -25,10 +25,8 @@ const file = chaiFiles.file;
const fs = require('fs-extra'); const fs = require('fs-extra');
const catalog = require('../lib/catalog.js'); const catalog = require('../lib/catalog.js');
const ORG = { const ORG = {
'id': 'https://www.uts.edu.au', 'id': 'https://www.uts.edu.au',
'name': 'University of Technology Sydney' 'name': 'University of Technology Sydney'
...@@ -39,15 +37,30 @@ const APPROVER = 'data.librarian@uts.edu.au'; ...@@ -39,15 +37,30 @@ const APPROVER = 'data.librarian@uts.edu.au';
const DATASET_ID = 'DATASET_ID'; const DATASET_ID = 'DATASET_ID';
function graph_get(graph, id) { // get catalog item by id: returns null if the item isn't unique, because
const match = graph.filter((item) => item['@id'] === id); // this should always make the test fail
function get_id(c, id) {
const match = c['@graph'].filter((item) => item['@id'] === id);
if( match.length ) { if( match.length ) {
return match[0]; if( match.length > 1 ) {
console.error(`Warning: catalog has ${match.length} items with ID ${id}`);
return null;
} else {
return match[0];
}
} else { } else {
return null; return null;
} }
} }
// this one returns an array of items with the requested type
function get_type(c, t) {
return c['@graph'].filter((item) => item['@type'] === t);
}
var dp, cj; var dp, cj;
...@@ -61,24 +74,48 @@ describe("DataPub to DataCrate: core metadata", () => { ...@@ -61,24 +74,48 @@ describe("DataPub to DataCrate: core metadata", () => {
'organisation': ORG, 'organisation': ORG,
'owner': OWNER, 'owner': OWNER,
'approver': APPROVER 'approver': APPROVER
}); });
}); });
it("puts a dataset item with correct metadata in the catalog", async () => { it("has a dataset item with correct metadata in the catalog", () => {
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 = get_id(cj, 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']); expect(dataset['publisher']['@id']).to.equal(ORG['id']);
}); });
it("has a history section with the owner and approver", async () => { it("has a create action with the owner", () => {
assert(true); const cas = get_type(cj, 'CreateAction');
expect(cas).to.have.length(1);
const ca = cas[0];
expect(ca['agent']['@id']).to.equal(OWNER);
}); });
it("has an update action with the approver", () => {
const uas = get_type(cj, 'UpdateAction');
expect(uas).to.have.length(1);
const ua = uas[0];
expect(ua['agent']['@id']).to.equal(APPROVER);
});
it("has the payload files", () => {
const files = get_type(cj, "File");
const datalocs = dp['dataLocations'];
expect(files).to.have.length(datalocs.length);
const fids = files.map((f) => f['@id']).sort();
const dlids = datalocs.map((dl) => dl['name']).sort();
expect(fids).to.eql(dlids);
});
it("", () => {
});
}); });
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