From 7087ad2295bf389de2b3aa1801055b13fb897145 Mon Sep 17 00:00:00 2001 From: "@s.roertgen" Date: Tue, 30 Jan 2024 15:14:35 +0100 Subject: [PATCH] Fix validation test #289 --- test/validate.test.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/validate.test.js b/test/validate.test.js index 2e865da..0df7739 100644 --- a/test/validate.test.js +++ b/test/validate.test.js @@ -1,5 +1,10 @@ import { describe, expect, it } from "vitest" import { validate } from "../src/validate" +import fs from "fs" +import jsonld from "jsonld" +import n3 from "n3" +const { DataFactory } = n3 +const { namedNode } = DataFactory describe("validate", () => { it("Returns true for a valid SkoHub Turtle File", async () => { @@ -10,10 +15,45 @@ describe("validate", () => { expect(result).toBeTruthy() }) it("Throws error for an invalid SkoHub Turtle File", async () => { + const inverses = { + "http://www.w3.org/2004/02/skos/core#narrower": + "http://www.w3.org/2004/02/skos/core#broader", + "http://www.w3.org/2004/02/skos/core#broader": + "http://www.w3.org/2004/02/skos/core#narrower", + "http://www.w3.org/2004/02/skos/core#related": + "http://www.w3.org/2004/02/skos/core#related", + "http://www.w3.org/2004/02/skos/core#hasTopConcept": + "http://www.w3.org/2004/02/skos/core#topConceptOf", + "http://www.w3.org/2004/02/skos/core#topConceptOf": + "http://www.w3.org/2004/02/skos/core#hasTopConcept", + } + + jsonld.registerRDFParser("text/turtle", (ttlString) => { + const quads = new n3.Parser().parse(ttlString) + const store = new n3.Store() + store.addQuads(quads) + quads.forEach((quad) => { + quad.object.language && + inverses[quad.predicate.id] && + store.addQuad( + quad.object, + namedNode(inverses[quad.predicate.id]), + quad.subject, + quad.graph + ) + }) + return store.getQuads() + }) + const f = "./test/data/ttl/invalid_hashURIConceptScheme.ttl" + + const ttlString = fs.readFileSync(f).toString() + const doc = await jsonld.fromRDF(ttlString, { format: "text/turtle" }) + await expect(() => validate( "./shapes/skohub.shacl.ttl", - "./test/data/ttl/invalid_hashURIConceptScheme.ttl" + "./test/data/ttl/invalid_hashURIConceptScheme.ttl", + doc ) ).rejects.toThrowError() })