|
| 1 | +import { MessageQuery } from "./MessageQuery"; |
| 2 | +import { graph, parse, sym } from "rdflib"; |
| 3 | + |
| 4 | +describe(MessageQuery.name, () => { |
| 5 | + describe("queryMessage", () => { |
| 6 | + it("returns null if store is empty", () => { |
| 7 | + const store = graph(); |
| 8 | + const result = new MessageQuery( |
| 9 | + sym("https://pod.test/message#1"), |
| 10 | + store, |
| 11 | + ).queryMessage(); |
| 12 | + expect(result).toEqual(null); |
| 13 | + }); |
| 14 | + |
| 15 | + it("returns a complete message", () => { |
| 16 | + const store = graph(); |
| 17 | + parse( |
| 18 | + ` |
| 19 | + @prefix : <#>. |
| 20 | + @prefix sioc: <http://rdfs.org/sioc/ns#>. |
| 21 | + @prefix dct: <http://purl.org/dc/terms/>. |
| 22 | + @prefix foaf: <http://xmlns.com/foaf/0.1/>. |
| 23 | + @prefix xsd: <http://www.w3.org/2001/XMLSchema#>. |
| 24 | + |
| 25 | + :1 sioc:content "A message" ; |
| 26 | + dct:created "2024-07-01T17:47:14Z"^^xsd:dateTime ; |
| 27 | + foaf:maker <https://pod.test/alice/profile/card#me> ; |
| 28 | + . |
| 29 | + |
| 30 | + `, |
| 31 | + store, |
| 32 | + "https://pod.test/message", |
| 33 | + ); |
| 34 | + const result = new MessageQuery( |
| 35 | + sym("https://pod.test/message#1"), |
| 36 | + store, |
| 37 | + ).queryMessage(); |
| 38 | + expect(result).toEqual({ |
| 39 | + uri: "https://pod.test/message#1", |
| 40 | + authorWebId: "https://pod.test/alice/profile/card#me", |
| 41 | + date: new Date("2024-07-01T17:47:14Z"), |
| 42 | + text: "A message", |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe("returns null for invalid messages", () => { |
| 47 | + it("that have no content", () => { |
| 48 | + const store = graph(); |
| 49 | + parse( |
| 50 | + ` |
| 51 | + @prefix : <#>. |
| 52 | + @prefix sioc: <http://rdfs.org/sioc/ns#>. |
| 53 | + @prefix dct: <http://purl.org/dc/terms/>. |
| 54 | + @prefix foaf: <http://xmlns.com/foaf/0.1/>. |
| 55 | + @prefix xsd: <http://www.w3.org/2001/XMLSchema#>. |
| 56 | + |
| 57 | + :1 |
| 58 | + dct:created "2024-07-01T17:47:14Z"^^xsd:dateTime ; |
| 59 | + foaf:maker <https://pod.test/alice/profile/card#me> ; |
| 60 | + . |
| 61 | + |
| 62 | + `, |
| 63 | + store, |
| 64 | + "https://pod.test/message", |
| 65 | + ); |
| 66 | + const result = new MessageQuery( |
| 67 | + sym("https://pod.test/message#1"), |
| 68 | + store, |
| 69 | + ).queryMessage(); |
| 70 | + expect(result).toEqual(null); |
| 71 | + }); |
| 72 | + |
| 73 | + it("that have no date", () => { |
| 74 | + const store = graph(); |
| 75 | + parse( |
| 76 | + ` |
| 77 | + @prefix : <#>. |
| 78 | + @prefix sioc: <http://rdfs.org/sioc/ns#>. |
| 79 | + @prefix dct: <http://purl.org/dc/terms/>. |
| 80 | + @prefix foaf: <http://xmlns.com/foaf/0.1/>. |
| 81 | + @prefix xsd: <http://www.w3.org/2001/XMLSchema#>. |
| 82 | + |
| 83 | + :1 sioc:content "A message" ; |
| 84 | + foaf:maker <https://pod.test/alice/profile/card#me> ; |
| 85 | + . |
| 86 | + |
| 87 | + `, |
| 88 | + store, |
| 89 | + "https://pod.test/message", |
| 90 | + ); |
| 91 | + const result = new MessageQuery( |
| 92 | + sym("https://pod.test/message#1"), |
| 93 | + store, |
| 94 | + ).queryMessage(); |
| 95 | + expect(result).toEqual(null); |
| 96 | + }); |
| 97 | + |
| 98 | + it("that have no author", () => { |
| 99 | + const store = graph(); |
| 100 | + parse( |
| 101 | + ` |
| 102 | + @prefix : <#>. |
| 103 | + @prefix sioc: <http://rdfs.org/sioc/ns#>. |
| 104 | + @prefix dct: <http://purl.org/dc/terms/>. |
| 105 | + @prefix foaf: <http://xmlns.com/foaf/0.1/>. |
| 106 | + @prefix xsd: <http://www.w3.org/2001/XMLSchema#>. |
| 107 | + |
| 108 | + :1 sioc:content "A message" ; |
| 109 | + dct:created "2024-07-01T17:47:14Z"^^xsd:dateTime ; |
| 110 | + . |
| 111 | + |
| 112 | + `, |
| 113 | + store, |
| 114 | + "https://pod.test/message", |
| 115 | + ); |
| 116 | + const result = new MessageQuery( |
| 117 | + sym("https://pod.test/message#1"), |
| 118 | + store, |
| 119 | + ).queryMessage(); |
| 120 | + expect(result).toEqual(null); |
| 121 | + }); |
| 122 | + }); |
| 123 | + }); |
| 124 | +}); |
0 commit comments