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

Tightening up the tests a lot

parent 91b863f3
Branches
Tags
No related merge requests found
......@@ -31,21 +31,20 @@ const RELATED = [ 'publications', 'websites', 'metadata', 'data' ];
const RELATED_TYPES = {
'publications': 'ScholarlyArticle',
'websites': 'WebSite',
'metadata': 'DataSet', // schema.org hasn't got a dedicated type
'metadata': 'CreativeWork', // schema.org hasn't got a dedicated type
'data': 'DataSet'
};
const ROOT_PATH = 'data/';
const FUNDING_FIELDS = [ 'foaf:fundedBy_foaf:Agent', 'foaf:fundedBy_vivo:Grant' ];
const SUBJECT_FIELDS = [ 'dc:subject_anzsrc:for', 'dc:subject_anzsrc:seo' ];
// these will do for now
const SUBJECT_IRI_PREFIX = {
'dc:subject_anzsrc:for': '_:FOR/',
'dc:subject_anzsrc:seo': '_:SEO/',
'finalKeywords': '_:keywords/'
'dc:subject_anzsrc:seo': '_:SEO/'
};
// dataset -> about -> subjects
......@@ -164,11 +163,12 @@ async function datapub2catalog(options) {
const eitems = items.filter((i) => i);
if( eitems ) {
dataset[property] = items.map(link_id);
graph.push(eitems);
graph.push(..._.flatten(eitems));
}
}
});
// todo: trim context here?
return {
'@context': context,
'@graph': graph.filter((e) => e)
......@@ -199,7 +199,7 @@ function make_dataset(id, datapub, organisation, dates, files) {
const ds = {
'@id': id,
'@type': 'Dataset',
'path': './',
'path': ROOT_PATH,
'name': datapub['title'],
'description': datapub['description'],
'dateCreated': dates['dateCreated'],
......@@ -207,6 +207,10 @@ function make_dataset(id, datapub, organisation, dates, files) {
'publisher': link_id(organisation),
'hasPart': files.map(link_id),
};
// see https://schema.org/keywords
if( datapub['finalKeywords'] ) {
ds['keywords'] = datapub['finalKeywords'].join(', ');
}
return ds;
}
......@@ -287,9 +291,9 @@ function make_files(datapub) {
'name': dl['name'],
'path': dl['name'],
'@type': 'File',
'description': dl['notes'],
'contentSize': dl['contentSize'],
'encodingFormat': dl['encodingFormat'],
'fileFormat': dl['fileFormat']
'encodingFormat': dl['mimeType']
}
} else {
// todo: URLs and physical locations
......@@ -386,17 +390,23 @@ function make_funders(datapub) {
}
// note - keywords are added on the dataset item
function make_subjects(datapub) {
return SUBJECT_FIELDS.map((field) => {
if( datapub[field] ) {
return datapub[field].map((subj) => {
const id = SUBJECT_IRI_PREFIX[field] + subj;
return datapub[field].map((cat) => {
const id = SUBJECT_IRI_PREFIX[field] + cat['notation'];
return {
'@id': id,
'@type': 'StructuredValue',
'url': id,
'identifier': id,
'name': subj
'name': cat['name']
};
})
} else {
return [];
}
});
}
......
......@@ -77,21 +77,33 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
'owner': OWNER,
'approver': APPROVER
});
const roots = cj['@graph'].filter((item) => {item['path'] === './'});
const roots = cj['@graph'].filter((item) => {return item['path'] === 'data/'});
cjds = roots[0];
console.log("cjds = " + JSON.stringify(cjds));
console.log("cj = " + JSON.stringify(cj));
await fs.writeJson('./test_data/CATALOG.json', cj, { 'spaces': 4 });
});
it("has a root dataset", () => {
expect(cjds).to.be.a('object');
});
it("has string @id values for every graph item", () => {
cj['@graph'].map((i) => {
console.log("graph items @id: " + JSON.stringify(i['@id']));
expect(i).to.have.property('@id');
expect(i['@id']).to.be.a('string');
})
});
it("has a dataset item with correct metadata in the catalog", () => {
it("has a dataset item with correct metadata", () => {
assert(cj, "Got an object");
assert(cj['@graph'], "Catalog has a @graph");
const dataset = get_id(cj, 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']);
expect(dataset['publisher']['@id']).to.equal(ORG['id'])
expect(dataset['keywords']).to.equal(dp['finalKeywords'].join(', '));
});
it("has a create action with the owner", () => {
......@@ -127,33 +139,40 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
// };
it("has subjects", () => {
// finalKeywords, FORs and SEOs
const fields = [ 'finalKeywords', 'dc:subject_anzsrc:for', 'dc:subject_anzsrc:seo'];
// FORs and SEOs
const fields = [ 'dc:subject_anzsrc:for', 'dc:subject_anzsrc:seo'];
const SUBJECT_IRI_PREFIX = {
'dc:subject_anzsrc:for': '_:FOR/',
'dc:subject_anzsrc:seo': '_:SEO/'
};
const about = cjds['about'].map((i) => i['@id']);
_.forEach(fields, (field) => {
const subjects = cj.filter((i) => { i['name'] === dp[field]});
expect(subjects.length).to.equal(1);
const pref = SUBJECT_IRI_PREFIX[field];
const expectsubs = dp[field].map((f) => { return f['name'] });
const subjects = cj['@graph'].filter((i) => { return i['@id'].startsWith(pref) });
const gotsubs = subjects.map((f) => { return f['name']} );
expect(gotsubs.sort()).to.eql(expectsubs.sort());
})
});
it("has spatial coverage", () => {
assert(false);
});
it("has temporal coverage", () => {
assert(false);
});
it("has funders", () => {
assert(false);
});
it("has a licence", () => {
assert(false);
});
it("has related works", () => {
assert(false);
});
......
......@@ -114,7 +114,30 @@
]
}
],
"dc:subject_anzsrc:seo" : [],
"dc:subject_anzsrc:seo" : [
{
"name" : "81 - DEFENCE",
"label" : "DEFENCE",
"notation" : "81"
},
{
"name" : "8201 - FORESTRY",
"label" : "FORESTRY",
"notation" : "8201",
"geneaology" : [
"82"
]
},
{
"name" : "830101 - Aquaculture Crustaceans (excl. Rock Lobster and Prawns)",
"label" : "Aquaculture Crustaceans (excl. Rock Lobster and Prawns)",
"notation" : "830101",
"geneaology" : [
"83",
"8301"
]
}
],
"startDate" : "2018-11-18",
"endDate" : "2018-12-02",
"timePeriod" : "The Anthropocene",
......
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