Skip to content

Commit 7fdd52b

Browse files
committed
contacts: integrate add contact to group
1 parent 33867b1 commit 7fdd52b

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

contacts/src/rdflib/ContactsModuleRdfLib.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { executeUpdate } from "./web-operations/executeUpdate";
1515
import { fetchNode } from "./web-operations/fetchNode";
1616
import { createNewGroup } from "./update-operations/createNewGroup";
1717
import { GroupQuery } from "./queries/GroupQuery";
18+
import { addContactToGroup } from "./update-operations/addContactToGroup";
1819

1920
interface ModuleConfig {
2021
store: IndexedFormula;
@@ -116,5 +117,13 @@ export class ContactsModuleRdfLib implements ContactsModule {
116117
};
117118
}
118119

119-
async addContactToGroup({ contactUri, groupUri }: AddContactToGroupCommand) {}
120+
async addContactToGroup({ contactUri, groupUri }: AddContactToGroupCommand) {
121+
const contactNode = sym(contactUri);
122+
const groupNode = sym(groupUri);
123+
await this.fetchNode(contactNode);
124+
const contactQuery = new ContactQuery(this.store, contactNode);
125+
const groupQuery = new GroupQuery(this.store, groupNode);
126+
const operation = addContactToGroup(contactQuery, groupQuery);
127+
await executeUpdate(this.fetcher, this.updater, operation);
128+
}
120129
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)