Skip to content

Commit 57adcde

Browse files
committed
add test (still failing)
1 parent fe5a7be commit 57adcde

1 file changed

Lines changed: 260 additions & 0 deletions

File tree

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
import { describe, it, expect, beforeAll, afterAll } from "vitest";
2+
import { parseRdf, toTurtle } from "@ldo/ldo";
3+
import { toRDF } from "jsonld";
4+
import {
5+
NodeSchemaProfileShapeType,
6+
NodeInstanceProfileShapeType,
7+
RelationInstanceProfileShapeType,
8+
RelationDefProfileShapeType,
9+
AbstractRelationDefProfileShapeType,
10+
} from "../../app/utils/conversion/ldo/dgBase.shapeTypes";
11+
12+
// example data
13+
14+
const exNodeSchema = {
15+
"@context": [
16+
"http://localhost:3000/schema/context.jsonld",
17+
{
18+
sdata: "http://localhost:3000/api/data/131102/",
19+
page: "http://localhost:3000/api/content/131102/131157#",
20+
},
21+
],
22+
has_container: "http://localhost:3000/api/data/131102",
23+
"@id": "sdata:131157",
24+
"@type": "NodeSchema",
25+
modified: "2026-01-24T15:38:14.553Z",
26+
created: "2026-01-24T15:38:14.553Z",
27+
subClassOf: ["dgc:Claim", "mira:Claim"],
28+
label: "Claim",
29+
creator: "someone",
30+
};
31+
32+
const exNodeInstance = {
33+
"@context": [
34+
"http://localhost:3000/schema/context.jsonld",
35+
{
36+
sdata: "http://localhost:3000/api/data/131102/",
37+
page: "http://localhost:3000/api/content/131102/254918#",
38+
},
39+
],
40+
has_container: "http://localhost:3000/api/data/131102",
41+
"@id": "sdata:254918",
42+
"@type": ["sdata:131157", "dgc:Claim", "mira:Claim"],
43+
modified: "2026-05-26T00:39:03.077Z",
44+
created: "2025-12-04T15:47:51.694Z",
45+
title: "CLM - Some base claim",
46+
description: {
47+
"@id": "page:content",
48+
format: "text/html",
49+
content:
50+
'<hr />\n<p>nodeTypeId: node<em>OHkZtsR6jkJIVaNmMY</em>GB\nnodeInstanceId: c1f02ff4-f116-452f-a490-3e0309667145</p>\n<h2 id="publishedtogroups">publishedToGroups:</h2>\n<p>That file was empty</p>',
51+
},
52+
creator: "someone",
53+
};
54+
55+
const exAbstractRelnDef = {
56+
"@context": [
57+
"http://localhost:3000/schema/context.jsonld",
58+
{
59+
sdata: "http://localhost:3000/api/data/131102/",
60+
page: "http://localhost:3000/api/content/131102/131164#",
61+
},
62+
],
63+
has_container: "http://localhost:3000/api/data/131102",
64+
"@id": "sdata:131164",
65+
"@type": "AbstractRelationDef",
66+
modified: "2026-01-24T15:38:14.553Z",
67+
created: "2026-01-24T15:38:14.553Z",
68+
subClassOf: [
69+
"dgb:RelationInstance",
70+
{
71+
"@type": "owl:Restriction",
72+
onProperty: "rdf:predicate",
73+
hasValue: "sdata:131164",
74+
},
75+
],
76+
label: "supports",
77+
creator: "someone",
78+
};
79+
80+
const exRelnType = {
81+
"@context": [
82+
"http://localhost:3000/schema/context.jsonld",
83+
{
84+
sdata: "http://localhost:3000/api/data/131102/",
85+
page: "http://localhost:3000/api/content/131102/131169#",
86+
},
87+
],
88+
has_container: "http://localhost:3000/api/data/131102",
89+
"@id": "sdata:131169",
90+
"@type": "RelationDef",
91+
modified: "2026-01-24T15:38:14.553Z",
92+
created: "2026-01-24T15:38:14.553Z",
93+
domain: "sdata:131157",
94+
range: "sdata:131157",
95+
subClassOf: [
96+
"dgb:RelationInstance",
97+
{
98+
"@type": "owl:Restriction",
99+
onProperty: "rdf:predicate",
100+
hasValue: "sdata:131169",
101+
},
102+
],
103+
label: "supports",
104+
creator: "someone",
105+
};
106+
107+
const exRelnInstance = {
108+
"@context": [
109+
"http://localhost:3000/schema/context.jsonld",
110+
{
111+
sdata: "http://localhost:3000/api/data/131102/",
112+
page: "http://localhost:3000/api/content/131102/261147#",
113+
},
114+
],
115+
has_container: "http://localhost:3000/api/data/131102",
116+
"@id": "sdata:261147",
117+
"@type": "sdata:131164",
118+
modified: "2026-06-03T10:13:09.101Z",
119+
created: "2026-06-03T10:13:09.101Z",
120+
source: "sdata:261134",
121+
destination: "sdata:254918",
122+
title:
123+
"[[CLM - Some supporting claim]] -supports-> [[CLM - Some base claim]]",
124+
creator: "someone",
125+
};
126+
127+
describe("LTO parsing of JSON-LD data", { tags: ["database"] }, () => {
128+
beforeAll(() => {});
129+
130+
afterAll(() => {});
131+
132+
const spaceUrl = "http://localhost:3000/api/data/131102";
133+
134+
it("Reads a node schema", async () => {
135+
const id = exNodeSchema["@id"].split(":")[1];
136+
const entityUrl = `${spaceUrl}/${id}`;
137+
138+
const asQuads = await toRDF(exNodeSchema, {
139+
format: "application/n-quads",
140+
});
141+
const ldoDataset = await parseRdf(asQuads, {
142+
baseIRI: entityUrl,
143+
});
144+
const parsedNodeSchema = ldoDataset
145+
.usingType(NodeSchemaProfileShapeType)
146+
.fromSubject(entityUrl);
147+
148+
expect(parsedNodeSchema);
149+
expect(parsedNodeSchema["@id"]);
150+
expect(parsedNodeSchema.subClassOf);
151+
expect(parsedNodeSchema.created);
152+
expect(parsedNodeSchema.modified);
153+
expect(parsedNodeSchema.creator);
154+
expect(parsedNodeSchema.hasContainer);
155+
// const turtleData = await toTurtle(parsedNodeSchema);
156+
// console.log(turtleData);
157+
});
158+
159+
it("Reads a node instance", async () => {
160+
const id = exNodeInstance["@id"];
161+
const entityUrl = `${spaceUrl}/${id}`;
162+
163+
const asQuads = await toRDF(exNodeInstance, {
164+
format: "application/n-quads",
165+
});
166+
const ldoDataset = await parseRdf(asQuads, {
167+
baseIRI: entityUrl,
168+
});
169+
const parsedNodeInstance = ldoDataset
170+
.usingType(NodeInstanceProfileShapeType)
171+
.fromSubject(entityUrl);
172+
173+
expect(parsedNodeInstance);
174+
expect(parsedNodeInstance["@id"]);
175+
expect(parsedNodeInstance.description);
176+
expect(parsedNodeInstance.created);
177+
expect(parsedNodeInstance.modified);
178+
expect(parsedNodeInstance.creator);
179+
expect(parsedNodeInstance.hasContainer);
180+
// const turtleData = await toTurtle(parsedNodeInstance);
181+
// console.log(turtleData);
182+
});
183+
184+
it("Reads an abstract relation definition", async () => {
185+
const id = exAbstractRelnDef["@id"].split(":")[1];
186+
const entityUrl = `${spaceUrl}/${id}`;
187+
188+
const asQuads = await toRDF(exAbstractRelnDef, {
189+
format: "application/n-quads",
190+
});
191+
const ldoDataset = await parseRdf(asQuads, {
192+
baseIRI: entityUrl,
193+
});
194+
const parsedRelnDef = ldoDataset
195+
.usingType(AbstractRelationDefProfileShapeType)
196+
.fromSubject(entityUrl);
197+
198+
expect(parsedRelnDef);
199+
expect(parsedRelnDef["@id"]);
200+
expect(parsedRelnDef.label);
201+
expect(parsedRelnDef.created);
202+
expect(parsedRelnDef.modified);
203+
expect(parsedRelnDef.creator);
204+
expect(parsedRelnDef.hasContainer);
205+
// const turtleData = await toTurtle(parsedRelnSchema);
206+
// console.log(turtleData);
207+
});
208+
209+
it("Reads a full relation definition", async () => {
210+
const id = exRelnType["@id"].split(":")[1];
211+
const entityUrl = `${spaceUrl}/${id}`;
212+
213+
const asQuads = await toRDF(exRelnType, {
214+
format: "application/n-quads",
215+
});
216+
const ldoDataset = await parseRdf(asQuads, {
217+
baseIRI: entityUrl,
218+
});
219+
const parsedRelnSchema = ldoDataset
220+
.usingType(RelationDefProfileShapeType)
221+
.fromSubject(entityUrl);
222+
223+
expect(parsedRelnSchema);
224+
expect(parsedRelnSchema["@id"]);
225+
expect(parsedRelnSchema.domain);
226+
expect(parsedRelnSchema.range);
227+
expect(parsedRelnSchema.created);
228+
expect(parsedRelnSchema.modified);
229+
expect(parsedRelnSchema.creator);
230+
expect(parsedRelnSchema.hasContainer);
231+
// const turtleData = await toTurtle(parsedRelnSchema);
232+
// console.log(turtleData);
233+
});
234+
235+
it("Reads a relation instance", async () => {
236+
const id = exRelnInstance["@id"].split(":")[1];
237+
const entityUrl = `${spaceUrl}/${id}`;
238+
239+
const asQuads = await toRDF(exRelnInstance, {
240+
format: "application/n-quads",
241+
});
242+
const ldoDataset = await parseRdf(asQuads, {
243+
baseIRI: entityUrl,
244+
});
245+
const parsedRelnInstance = ldoDataset
246+
.usingType(RelationInstanceProfileShapeType)
247+
.fromSubject(entityUrl);
248+
249+
expect(parsedRelnInstance);
250+
expect(parsedRelnInstance["@id"]);
251+
expect(parsedRelnInstance.source);
252+
expect(parsedRelnInstance.destination);
253+
expect(parsedRelnInstance.created);
254+
expect(parsedRelnInstance.modified);
255+
expect(parsedRelnInstance.creator);
256+
expect(parsedRelnInstance.hasContainer);
257+
// const turtleData = await toTurtle(parsedRelnInstance);
258+
// console.log(turtleData);
259+
});
260+
});

0 commit comments

Comments
 (0)