|
1 | 1 | import { postMessage } from "./post-message"; |
2 | | -import { st, sym } from "rdflib"; |
3 | | -import { wf } from "../namespaces"; |
| 2 | +import { lit, st, sym } from "rdflib"; |
| 3 | +import { dct, foaf, sioc, wf } from "../namespaces"; |
4 | 4 |
|
5 | 5 | describe("post message", () => { |
6 | 6 | it("inserts a link from chat to message", () => { |
7 | 7 | const result = postMessage( |
8 | | - "https://pod.test/chat/42/chat.ttl#1", |
| 8 | + "https://pod.test/chat/42/chat.ttl#message-1", |
| 9 | + "irrelevant", |
| 10 | + "https://pod.test/irrelevant", |
9 | 11 | sym("https://pod.test/chat/42/index.ttl#this"), |
10 | 12 | ); |
11 | 13 | expect(result.insertions).toContainEqual( |
12 | 14 | st( |
13 | 15 | sym("https://pod.test/chat/42/index.ttl#this"), |
14 | 16 | wf("message"), |
15 | | - sym("https://pod.test/chat/42/chat.ttl#1"), |
| 17 | + sym("https://pod.test/chat/42/chat.ttl#message-1"), |
| 18 | + sym("https://pod.test/chat/42/chat.ttl"), |
| 19 | + ), |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + it("inserts the message content", () => { |
| 24 | + const result = postMessage( |
| 25 | + "https://pod.test/chat/42/chat.ttl#message-1", |
| 26 | + "the text to insert", |
| 27 | + "https://pos.test/irrelevant", |
| 28 | + sym("https://pod.test/chat/42/index.ttl#this"), |
| 29 | + ); |
| 30 | + expect(result.insertions).toContainEqual( |
| 31 | + st( |
| 32 | + sym("https://pod.test/chat/42/chat.ttl#message-1"), |
| 33 | + sioc("content"), |
| 34 | + lit("the text to insert"), |
| 35 | + sym("https://pod.test/chat/42/chat.ttl"), |
| 36 | + ), |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + it("inserts the current time as creation date", () => { |
| 41 | + jest.useFakeTimers({ |
| 42 | + now: new Date("2024-09-08T07:06:05.432Z"), |
| 43 | + }); |
| 44 | + const result = postMessage( |
| 45 | + "https://pod.test/chat/42/chat.ttl#message-1", |
| 46 | + "irrelevant", |
| 47 | + "https://pos.test/irrelevant", |
| 48 | + sym("https://pod.test/chat/42/index.ttl#this"), |
| 49 | + ); |
| 50 | + expect(result.insertions).toContainEqual( |
| 51 | + st( |
| 52 | + sym("https://pod.test/chat/42/chat.ttl#message-1"), |
| 53 | + dct("created"), |
| 54 | + lit( |
| 55 | + "2024-09-08T07:06:05.432Z", |
| 56 | + undefined, |
| 57 | + sym("http://www.w3.org/2001/XMLSchema#dateTime"), |
| 58 | + ), |
| 59 | + sym("https://pod.test/chat/42/chat.ttl"), |
| 60 | + ), |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + it("inserts the author WebID", () => { |
| 65 | + const result = postMessage( |
| 66 | + "https://pod.test/chat/42/chat.ttl#message-1", |
| 67 | + "irrelevant", |
| 68 | + "https://pos.test/alice/profile/card#me", |
| 69 | + sym("https://pod.test/chat/42/index.ttl#this"), |
| 70 | + ); |
| 71 | + expect(result.insertions).toContainEqual( |
| 72 | + st( |
| 73 | + sym("https://pod.test/chat/42/chat.ttl#message-1"), |
| 74 | + foaf("maker"), |
| 75 | + sym("https://pos.test/alice/profile/card#me"), |
16 | 76 | sym("https://pod.test/chat/42/chat.ttl"), |
17 | 77 | ), |
18 | 78 | ); |
|
0 commit comments