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

Added test for whether the empty datapub generates citations (test fails)

parent dcbe89c8
Branches
Tags
No related merge requests found
......@@ -16,6 +16,26 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* TODO
These tests are a bit clunky and only cover two cases:
- a datapublication with decent values in every field
- a datapublication with only the minimum mandatory content, but with
the slightly janky JSON which the redbox-portal frontend produces,
with things like empty objects where the user hasn't selected a funder,
etc
The second set of tests were included so that the publication workflow
produced decent looking DataCrates.
Mature tests would abstract out the code in the before clauses
to a general function which loaded a datapub and returned a catalog object,
and generate lots of datapubs programmatically to fuzz the crosswalk.
*/
const chai = require('chai');
const chaiFiles = require('chai-files');
chai.use(chaiFiles);
......@@ -96,7 +116,6 @@ function assert_link(ds, prop, item) {
var mdp, dp, cj, cjds;
// TODO: it would be great if these could be run against a
......@@ -106,7 +125,9 @@ var mdp, dp, cj, cjds;
describe("Try to load a janky default DataPub with empty fields", () => {
it("loads without throwing an error", async () => {
var mdp, dp, cj, cjds;
before(async () => {
mdp = await fs.readJson('./test_data/janky_datapub.json');
dp = mdp['metadata'];
cj = await catalog.datapub2catalog({
......@@ -117,11 +138,32 @@ describe("Try to load a janky default DataPub with empty fields", () => {
'approver': APPROVER,
'prefixes': IRI_PREFIXES
});
const roots = cj['@graph'].filter((item) => {return item['path'] === 'data/'});
cjds = roots[0];
await fs.writeJson('./test_data/janky_CATALOG.json', cj, { 'spaces': 4 });
});
it("has the basic json-ld properties", async () => {
expect(cj).to.be.an('object');
expect(cj).to.have.property('@graph');
expect(cj).to.have.property('@context');
});
it("has a trimmed context", async () => {
expect(cj['@context']).not.to.have.property('Bacteria');
});
it("has no funders", async () => {
const funderids = cjds['funder'].map((i) => i['@id']);
expect(funderids).to.be.empty;
});
it("has no related works", async () => {
const citationids = cjds['citation'].map((i) => i['@id']);
expect(citationids).to.be.empty;
})
});
......@@ -130,6 +172,8 @@ describe("Try to load a janky default DataPub with empty fields", () => {
describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
var mdp, dp, cj, cjds;
before(async () => {
mdp = await fs.readJson('./test_data/datapub.json');
dp = mdp['metadata'];
......@@ -146,7 +190,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => {
await fs.writeJson('./test_data/CATALOG.json', cj, { 'spaces': 4 });
});
it("has a context which has been trimmed", () => {
it("has a trimmed context", () => {
expect(cj).to.have.property("@context");
const context = cj['@context'];
expect(context).to.not.have.property('Bacteria');
......
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