Skip to content

Commit 6601707

Browse files
committed
contacts: integrate readGroup fetching and reading real group name
1 parent 8e6341d commit 6601707

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

contacts/src/rdflib/ContactsModuleRdfLib.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { createAddressBook, createNewContact } from "./update-operations";
1313
import { executeUpdate } from "./web-operations/executeUpdate";
1414
import { fetchNode } from "./web-operations/fetchNode";
1515
import { createNewGroup } from "./update-operations/createNewGroup";
16+
import { GroupQuery } from "./queries/GroupQuery";
1617

1718
interface ModuleConfig {
1819
store: IndexedFormula;
@@ -102,9 +103,13 @@ export class ContactsModuleRdfLib implements ContactsModule {
102103
}
103104

104105
async readGroup(uri: string): Promise<FullGroup> {
106+
const groupNode = sym(uri);
107+
await this.fetchNode(groupNode);
108+
const query = new GroupQuery(this.store, groupNode);
109+
const name = query.queryName();
105110
return {
106111
uri,
107-
name: "Officials",
112+
name,
108113
members: [
109114
{
110115
name: "Molly Braaten",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Fetcher, graph, UpdateManager } from "rdflib";
2+
import { ContactsModuleRdfLib } from "./ContactsModuleRdfLib";
3+
import { mockTurtleResponse } from "../test-support/mockResponses";
4+
5+
describe("read group", () => {
6+
it("returns the group's name and uri", async () => {
7+
const authenticatedFetch = jest.fn();
8+
9+
const store = graph();
10+
const fetcher = new Fetcher(store, {
11+
fetch: authenticatedFetch,
12+
});
13+
const updater = new UpdateManager(store);
14+
const contacts = new ContactsModuleRdfLib({
15+
store,
16+
fetcher,
17+
updater,
18+
});
19+
20+
mockTurtleResponse(
21+
authenticatedFetch,
22+
"https://pod.test/alice/contacts/Group/1/index.ttl",
23+
`
24+
@prefix vcard: <http://www.w3.org/2006/vcard/ns#>.
25+
26+
<#this> a vcard:Group;
27+
vcard:fn "Officials".
28+
`,
29+
);
30+
31+
const result = await contacts.readGroup(
32+
"https://pod.test/alice/contacts/Group/1/index.ttl#this",
33+
);
34+
35+
expect(result).toMatchObject({
36+
uri: "https://pod.test/alice/contacts/Group/1/index.ttl#this",
37+
name: "Officials",
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)