|
| 1 | +import { DataFactory, Parser, Store } from "n3"; |
| 2 | +import assert from "node:assert"; |
| 3 | +import { describe, it } from "node:test"; |
| 4 | +import { ContainerDataset } from "@solid/object"; |
| 5 | + |
| 6 | +describe("ContainerDataset", () => { |
| 7 | + const emptyContainerRDF = ` |
| 8 | + @prefix dc: <http://purl.org/dc/terms/>. |
| 9 | + @prefix ldp: <http://www.w3.org/ns/ldp#>. |
| 10 | + @prefix posix: <http://www.w3.org/ns/posix/stat#>. |
| 11 | + @prefix xsd: <http://www.w3.org/2001/XMLSchema#>. |
| 12 | + <> a ldp:Container, ldp:BasicContainer, ldp:Resource; |
| 13 | + dc:modified "2026-07-23T10:41:12.846Z"^^xsd:dateTime; |
| 14 | + posix:mtime 1784803272. |
| 15 | + `; |
| 16 | + |
| 17 | + const nonEmptyContainerRDF = ` |
| 18 | + @prefix ldp: <http://www.w3.org/ns/ldp#>. |
| 19 | + <https://pod.example/container/> |
| 20 | + a ldp:Container; |
| 21 | + ldp:contains <https://pod.example/container/file.txt> . |
| 22 | + <https://pod.example/container/file.txt> |
| 23 | + a ldp:Resource . |
| 24 | + `; |
| 25 | + |
| 26 | + it("resolves an empty container via rdf:type when ldp:contains is absent", () => { |
| 27 | + const store = new Store(); |
| 28 | + const parser = new Parser({ baseIRI: "https://pod.example/empty/" }); |
| 29 | + store.addQuads(parser.parse(emptyContainerRDF)); |
| 30 | + const dataset = new ContainerDataset(store, DataFactory); |
| 31 | + const container = dataset.container; |
| 32 | + assert.ok(container !== undefined); |
| 33 | + assert.equal(container.id, "https://pod.example/empty/"); |
| 34 | + assert.equal(container.contains.size, 0); |
| 35 | + }); |
| 36 | + |
| 37 | + it("still resolves a non-empty container via ldp:contains", () => { |
| 38 | + const store = new Store(); |
| 39 | + store.addQuads(new Parser().parse(nonEmptyContainerRDF)); |
| 40 | + const dataset = new ContainerDataset(store, DataFactory); |
| 41 | + const container = dataset.container; |
| 42 | + assert.ok(container !== undefined); |
| 43 | + assert.equal(container.id, "https://pod.example/container/"); |
| 44 | + assert.equal(container.contains.size, 1); |
| 45 | + assert.equal( |
| 46 | + container.contains.values().next().value?.id, |
| 47 | + "https://pod.example/container/file.txt", |
| 48 | + ); |
| 49 | + }); |
| 50 | +}); |
0 commit comments