|
| 1 | +import { Fetcher, graph, UpdateManager } from "rdflib"; |
| 2 | +import { ContactsModuleRdfLib } from "./ContactsModuleRdfLib"; |
| 3 | +import { mockTurtleResponse } from "../test-support/mockResponses"; |
| 4 | +import { expectPatchRequest } from "../test-support/expectRequests"; |
| 5 | + |
| 6 | +describe("add contact to group", () => { |
| 7 | + it("references the contact to the group document", async () => { |
| 8 | + const authenticatedFetch = jest.fn(); |
| 9 | + |
| 10 | + const store = graph(); |
| 11 | + const fetcher = new Fetcher(store, { |
| 12 | + fetch: authenticatedFetch, |
| 13 | + }); |
| 14 | + const updater = new UpdateManager(store); |
| 15 | + const contacts = new ContactsModuleRdfLib({ |
| 16 | + store, |
| 17 | + fetcher, |
| 18 | + updater, |
| 19 | + }); |
| 20 | + |
| 21 | + mockTurtleResponse( |
| 22 | + authenticatedFetch, |
| 23 | + "https://pod.test/alice/contacts/Group/1/index.ttl", |
| 24 | + ` |
| 25 | + @prefix vcard: <http://www.w3.org/2006/vcard/ns#>. |
| 26 | + |
| 27 | + <#this> a vcard:Group; |
| 28 | + vcard:fn "Friends". |
| 29 | +`, |
| 30 | + ); |
| 31 | + |
| 32 | + mockTurtleResponse( |
| 33 | + authenticatedFetch, |
| 34 | + "https://pod.test/alice/contacts/Person/1/index.ttl", |
| 35 | + ` |
| 36 | + @prefix vcard: <http://www.w3.org/2006/vcard/ns#>. |
| 37 | + |
| 38 | + <#this> a vcard:Individual; |
| 39 | + vcard:fn "Finley Kim". |
| 40 | +`, |
| 41 | + ); |
| 42 | + |
| 43 | + await contacts.addContactToGroup({ |
| 44 | + groupUri: "https://pod.test/alice/contacts/Group/1/index.ttl#this", |
| 45 | + contactUri: "https://pod.test/alice/contacts/Person/1/index.ttl#this", |
| 46 | + }); |
| 47 | + |
| 48 | + expectPatchRequest( |
| 49 | + authenticatedFetch, |
| 50 | + "https://pod.test/alice/contacts/Group/1/index.ttl", |
| 51 | + `INSERT DATA { <https://pod.test/alice/contacts/Group/1/index.ttl#this> <http://www.w3.org/2006/vcard/ns#hasMember> <https://pod.test/alice/contacts/Person/1/index.ttl#this> . |
| 52 | +<https://pod.test/alice/contacts/Person/1/index.ttl#this> <http://www.w3.org/2006/vcard/ns#fn> "Finley Kim" . |
| 53 | + }`, |
| 54 | + ); |
| 55 | + }); |
| 56 | +}); |
0 commit comments