Skip to content

Commit 8e6341d

Browse files
committed
contacts: query for group name
1 parent 0c10ae7 commit 8e6341d

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { graph, lit, sym } from "rdflib";
2+
import { GroupQuery } from "./GroupQuery";
3+
import { rdf, vcard } from "../namespaces";
4+
5+
describe(GroupQuery.name, () => {
6+
describe("query name", () => {
7+
it("returns nothing if store is empty", () => {
8+
const store = graph();
9+
10+
const query = new GroupQuery(
11+
store,
12+
sym("https://pod.test/alice/group/1/index.ttl#this"),
13+
);
14+
const result = query.queryName();
15+
expect(result).toEqual("");
16+
});
17+
18+
it("returns the group's vcard:fn from the group document", () => {
19+
const store = graph();
20+
store.add(
21+
sym("https://pod.test/alice/group/1/index.ttl#this"),
22+
vcard("fn"),
23+
lit("Family"),
24+
sym("https://pod.test/alice/group/1/index.ttl"),
25+
);
26+
const query = new GroupQuery(
27+
store,
28+
sym("https://pod.test/alice/group/1/index.ttl#this"),
29+
);
30+
const result = query.queryName();
31+
expect(result).toEqual("Family");
32+
});
33+
34+
it("returns nothing if vcard:fn is from wrong group", () => {
35+
const store = graph();
36+
store.add(
37+
sym("https://pod.test/alice/group/1/index.ttl#other"),
38+
vcard("fn"),
39+
lit("Family"),
40+
sym("https://pod.test/alice/group/1/index.ttl"),
41+
);
42+
const query = new GroupQuery(
43+
store,
44+
sym("https://pod.test/alice/group/1/index.ttl#this"),
45+
);
46+
const result = query.queryName();
47+
expect(result).toEqual("");
48+
});
49+
50+
it("returns nothing, if vcard:fn is missing", () => {
51+
const store = graph();
52+
store.add(
53+
sym("https://pod.test/alice/group/1/index.ttl#this"),
54+
rdf("type"),
55+
vcard("Group"),
56+
sym("https://pod.test/alice/group/1/index.ttl"),
57+
);
58+
const query = new GroupQuery(
59+
store,
60+
sym("https://pod.test/alice/group/1/index.ttl#this"),
61+
);
62+
const result = query.queryName();
63+
expect(result).toEqual("");
64+
});
65+
});
66+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { IndexedFormula, NamedNode } from "rdflib";
2+
import { vcard } from "../namespaces";
3+
4+
export class GroupQuery {
5+
private groupDoc: NamedNode;
6+
7+
constructor(
8+
private store: IndexedFormula,
9+
public groupNode: NamedNode,
10+
) {
11+
this.groupDoc = groupNode.doc();
12+
}
13+
queryName(): string {
14+
return (
15+
this.store.anyValue(
16+
this.groupNode,
17+
vcard("fn"),
18+
undefined,
19+
this.groupDoc,
20+
) ?? ""
21+
);
22+
}
23+
}

0 commit comments

Comments
 (0)