Skip to content

Commit

Permalink
Added tests for rdf:type related queries (#102)
Browse files Browse the repository at this point in the history
Resolves #101.
  • Loading branch information
karelklima authored Jan 14, 2024
1 parent 55ea58c commit 76830a1
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
99 changes: 99 additions & 0 deletions tests/e2e/rdf_types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { assertEquals } from "../test_deps.ts";

import { initStore, ttl, x } from "../test_utils.ts";

import { createLens, type Schema } from "ldkit";
import { ldkit, rdf, xsd } from "ldkit/namespaces";

const Director = {
types: {
"@id": rdf.type,
"@type": ldkit.IRI,
"@array": true,
},
name: x.name,
birthDate: {
"@id": x.birthDate,
"@type": xsd.date,
},
movies: {
"@id": x.movie,
"@array": true,
},
} as const;

const defaultStoreContent = ttl(`
x:A
a x:TypeA, x:TypeAOrB .
x:B
a x:TypeB, x:TypeAOrB .
x:C
a x:TypeC .
`);

const init = () => {
const { store, options, assertStore, empty } = initStore();
store.addQuads(defaultStoreContent);
const Directors = createLens(Director, options);
return { Directors, assertStore, empty, store, options };
};

Deno.test("E2E / RDF types / Query one type", async () => {
const { options } = init();

const SchemaPrototype = {
"@type": x.TypeB,
} satisfies Schema;

const results = await createLens(SchemaPrototype, options).find();

assertEquals(results.length, 1);
assertEquals(results[0], {
$id: x.B,
});
});

Deno.test("E2E / RDF types / Query multiple types", async () => {
const { options } = init();

const SchemaPrototype = {
"@type": [x.TypeA, x.TypeAOrB],
} satisfies Schema;

const results = await createLens(SchemaPrototype, options).find();

assertEquals(results.length, 1);
assertEquals(results[0], {
$id: x.A,
});
});

Deno.test("E2E / RDF types / Query types using search", async () => {
const { options } = init();

const SchemaPrototype = {
types: {
"@id": rdf.type,
"@type": ldkit.IRI,
"@array": true,
},
} satisfies Schema;

const results = await createLens(SchemaPrototype, options).find({
where: {
types: {
$in: [x.TypeB, x.TypeC],
},
},
});

assertEquals(results.length, 2);
assertEquals(results[0], {
$id: x.B,
types: [x.TypeB],
});
assertEquals(results[1], {
$id: x.C,
types: [x.TypeC],
});
});
2 changes: 1 addition & 1 deletion www/data/docs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import RAW_TOC from "../../docs/table-of-contents.json" assert { type: "json" };
import RAW_TOC from "../../docs/table-of-contents.json" with { type: "json" };

type RawTableOfContents = Record<string, RawTableOfContentsEntry>;

Expand Down

0 comments on commit 76830a1

Please sign in to comment.