|
| 1 | +import { MessagesDocumentQuery } from "./MessagesDocumentQuery"; |
| 2 | +import { graph, parse, sym } from "rdflib"; |
| 3 | + |
| 4 | +describe(MessagesDocumentQuery.name, () => { |
| 5 | + describe("query messages", () => { |
| 6 | + it("returns empty array if store is empty", () => { |
| 7 | + const result = new MessagesDocumentQuery( |
| 8 | + sym("https://pod.example/chat/1/index.ttl#this"), |
| 9 | + sym("https://pod.example/chat/1/2024/07/30/chat.ttl"), |
| 10 | + graph(), |
| 11 | + ).queryMessages(); |
| 12 | + expect(result).toEqual([]); |
| 13 | + }); |
| 14 | + |
| 15 | + it("returns the message linked to the chat", () => { |
| 16 | + const store = graph(); |
| 17 | + parse( |
| 18 | + `@prefix wf: <http://www.w3.org/2005/01/wf/flow#> . |
| 19 | +
|
| 20 | +<https://pod.example/chat/1/index.ttl#this> |
| 21 | + wf:message <#message-1> . |
| 22 | +
|
| 23 | +<#message-1> |
| 24 | + <http://rdfs.org/sioc/ns#content> "A chat message" ; |
| 25 | + <http://purl.org/dc/terms/created> "2024-07-01T17:47:14Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> ; |
| 26 | + <http://xmlns.com/foaf/0.1/maker> <http://localhost:3000/alice/profile/card#me> ; |
| 27 | +. |
| 28 | + `, |
| 29 | + store, |
| 30 | + "https://pod.example/chat/1/2024/07/30/chat.ttl", |
| 31 | + ); |
| 32 | + |
| 33 | + const result = new MessagesDocumentQuery( |
| 34 | + sym("https://pod.example/chat/1/index.ttl#this"), |
| 35 | + sym("https://pod.example/chat/1/2024/07/30/chat.ttl"), |
| 36 | + store, |
| 37 | + ).queryMessages(); |
| 38 | + expect(result).toEqual([ |
| 39 | + { |
| 40 | + uri: "https://pod.example/chat/1/2024/07/30/chat.ttl#message-1", |
| 41 | + text: "A chat message", |
| 42 | + date: new Date("2024-07-01T17:47:14Z"), |
| 43 | + authorWebId: "http://localhost:3000/alice/profile/card#me", |
| 44 | + }, |
| 45 | + ]); |
| 46 | + }); |
| 47 | + |
| 48 | + it("returns all messages linked to the chat", () => { |
| 49 | + const store = graph(); |
| 50 | + parse( |
| 51 | + `@prefix wf: <http://www.w3.org/2005/01/wf/flow#> . |
| 52 | +
|
| 53 | +<https://pod.example/chat/1/index.ttl#this> |
| 54 | + wf:message <#message-1>, <#message-2> . |
| 55 | +
|
| 56 | +<#message-1> |
| 57 | + <http://rdfs.org/sioc/ns#content> "First message" ; |
| 58 | + <http://purl.org/dc/terms/created> "2024-07-01T17:47:14Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> ; |
| 59 | + <http://xmlns.com/foaf/0.1/maker> <http://localhost:3000/alice/profile/card#me> . |
| 60 | + |
| 61 | +<#message-2> |
| 62 | + <http://rdfs.org/sioc/ns#content> "Second message" ; |
| 63 | + <http://purl.org/dc/terms/created> "2024-07-01T17:48:14Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> ; |
| 64 | + <http://xmlns.com/foaf/0.1/maker> <http://localhost:3000/bob/profile/card#me> ; |
| 65 | +. |
| 66 | + `, |
| 67 | + store, |
| 68 | + "https://pod.example/chat/1/2024/07/30/chat.ttl", |
| 69 | + ); |
| 70 | + |
| 71 | + const result = new MessagesDocumentQuery( |
| 72 | + sym("https://pod.example/chat/1/index.ttl#this"), |
| 73 | + sym("https://pod.example/chat/1/2024/07/30/chat.ttl"), |
| 74 | + store, |
| 75 | + ).queryMessages(); |
| 76 | + expect(result).toEqual([ |
| 77 | + { |
| 78 | + uri: "https://pod.example/chat/1/2024/07/30/chat.ttl#message-1", |
| 79 | + text: "First message", |
| 80 | + date: new Date("2024-07-01T17:47:14Z"), |
| 81 | + authorWebId: "http://localhost:3000/alice/profile/card#me", |
| 82 | + }, |
| 83 | + { |
| 84 | + uri: "https://pod.example/chat/1/2024/07/30/chat.ttl#message-2", |
| 85 | + text: "Second message", |
| 86 | + date: new Date("2024-07-01T17:48:14Z"), |
| 87 | + authorWebId: "http://localhost:3000/bob/profile/card#me", |
| 88 | + }, |
| 89 | + ]); |
| 90 | + }); |
| 91 | + |
| 92 | + describe("ignores messages", () => { |
| 93 | + it("that are not linked to the chat", () => { |
| 94 | + const store = graph(); |
| 95 | + parse( |
| 96 | + `@prefix wf: <http://www.w3.org/2005/01/wf/flow#> . |
| 97 | +
|
| 98 | +<#message-1> |
| 99 | + <http://rdfs.org/sioc/ns#content> "A chat message" ; |
| 100 | + <http://purl.org/dc/terms/created> "2024-07-01T17:47:14Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> ; |
| 101 | + <http://xmlns.com/foaf/0.1/maker> <http://localhost:3000/alice/profile/card#me> ; |
| 102 | +. |
| 103 | + `, |
| 104 | + store, |
| 105 | + "https://pod.example/chat/1/2024/07/30/chat.ttl", |
| 106 | + ); |
| 107 | + |
| 108 | + const result = new MessagesDocumentQuery( |
| 109 | + sym("https://pod.example/chat/1/index.ttl#this"), |
| 110 | + sym("https://pod.example/chat/1/2024/07/30/chat.ttl"), |
| 111 | + store, |
| 112 | + ).queryMessages(); |
| 113 | + expect(result).toEqual([]); |
| 114 | + }); |
| 115 | + |
| 116 | + it("that are linked to the chat in the wrong document", () => { |
| 117 | + const store = graph(); |
| 118 | + parse( |
| 119 | + `@prefix wf: <http://www.w3.org/2005/01/wf/flow#> . |
| 120 | +
|
| 121 | +<https://pod.example/chat/1/index.ttl#this> |
| 122 | + wf:message <chat.ttl#message-1> .`, |
| 123 | + store, |
| 124 | + "https://pod.example/chat/1/2024/07/30/wrong.ttl", |
| 125 | + ); |
| 126 | + parse( |
| 127 | + `@prefix wf: <http://www.w3.org/2005/01/wf/flow#> . |
| 128 | +
|
| 129 | +<#message-1> |
| 130 | + <http://rdfs.org/sioc/ns#content> "A chat message" ; |
| 131 | + <http://purl.org/dc/terms/created> "2024-07-01T17:47:14Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> ; |
| 132 | + <http://xmlns.com/foaf/0.1/maker> <http://localhost:3000/alice/profile/card#me> ; |
| 133 | +. |
| 134 | + `, |
| 135 | + store, |
| 136 | + "https://pod.example/chat/1/2024/07/30/chat.ttl", |
| 137 | + ); |
| 138 | + |
| 139 | + const result = new MessagesDocumentQuery( |
| 140 | + sym("https://pod.example/chat/1/index.ttl#this"), |
| 141 | + sym("https://pod.example/chat/1/2024/07/30/chat.ttl"), |
| 142 | + store, |
| 143 | + ).queryMessages(); |
| 144 | + expect(result).toEqual([]); |
| 145 | + }); |
| 146 | + }); |
| 147 | + }); |
| 148 | +}); |
0 commit comments