|
1 | 1 | import { graph, lit, sym } from "rdflib"; |
2 | 2 | import { GroupQuery } from "./GroupQuery"; |
3 | 3 | import { rdf, vcard } from "../namespaces"; |
| 4 | +import { AddressBookQuery } from "./AddressBookQuery"; |
| 5 | +import * as querystring from "querystring"; |
4 | 6 |
|
5 | 7 | describe(GroupQuery.name, () => { |
6 | 8 | describe("query name", () => { |
@@ -63,4 +65,100 @@ describe(GroupQuery.name, () => { |
63 | 65 | expect(result).toEqual(""); |
64 | 66 | }); |
65 | 67 | }); |
| 68 | + describe("query members", () => { |
| 69 | + it("returns an empty array if nothing found in store", () => { |
| 70 | + const query = new GroupQuery( |
| 71 | + graph(), |
| 72 | + sym("http://pod.test/alice/contacts/1/group/1/index.ttl#this"), |
| 73 | + ); |
| 74 | + const result = query.queryMembers(); |
| 75 | + expect(result).toEqual([]); |
| 76 | + }); |
| 77 | + it("returns a single contact with name and URI", () => { |
| 78 | + const store = graph(); |
| 79 | + const groupNode = sym( |
| 80 | + "http://pod.test/alice/contacts/1/group/1/index.ttl#this", |
| 81 | + ); |
| 82 | + store.add( |
| 83 | + groupNode, |
| 84 | + vcard("hasMember"), |
| 85 | + sym("http://pod.test/alice/contacts/Person/1#this"), |
| 86 | + groupNode.doc(), |
| 87 | + ); |
| 88 | + store.add( |
| 89 | + sym("http://pod.test/alice/contacts/Person/1#this"), |
| 90 | + vcard("fn"), |
| 91 | + lit("Bob"), |
| 92 | + groupNode.doc(), |
| 93 | + ); |
| 94 | + const query = new GroupQuery(store, groupNode); |
| 95 | + const result = query.queryMembers(); |
| 96 | + expect(result).toEqual([ |
| 97 | + { |
| 98 | + uri: "http://pod.test/alice/contacts/Person/1#this", |
| 99 | + name: "Bob", |
| 100 | + }, |
| 101 | + ]); |
| 102 | + }); |
| 103 | + |
| 104 | + it("returns all contacts with name and URI", () => { |
| 105 | + const store = graph(); |
| 106 | + const groupNode = sym( |
| 107 | + "http://pod.test/alice/contacts/1/group/1/index.ttl#this", |
| 108 | + ); |
| 109 | + |
| 110 | + store.add( |
| 111 | + groupNode, |
| 112 | + vcard("hasMember"), |
| 113 | + sym("http://pod.test/alice/contacts/Person/1#this"), |
| 114 | + groupNode.doc(), |
| 115 | + ); |
| 116 | + store.add( |
| 117 | + sym("http://pod.test/alice/contacts/Person/1#this"), |
| 118 | + vcard("fn"), |
| 119 | + lit("Alice"), |
| 120 | + groupNode.doc(), |
| 121 | + ); |
| 122 | + store.add( |
| 123 | + groupNode, |
| 124 | + vcard("hasMember"), |
| 125 | + sym("http://pod.test/alice/contacts/Person/2#this"), |
| 126 | + groupNode.doc(), |
| 127 | + ); |
| 128 | + store.add( |
| 129 | + sym("http://pod.test/alice/contacts/Person/2#this"), |
| 130 | + vcard("fn"), |
| 131 | + lit("Bob"), |
| 132 | + groupNode.doc(), |
| 133 | + ); |
| 134 | + |
| 135 | + const query = new GroupQuery( |
| 136 | + store, |
| 137 | + sym("http://pod.test/alice/contacts/1/group/1/index.ttl#this"), |
| 138 | + ); |
| 139 | + const result = query.queryMembers(); |
| 140 | + expect(result).toEqual([ |
| 141 | + { |
| 142 | + uri: "http://pod.test/alice/contacts/Person/1#this", |
| 143 | + name: "Alice", |
| 144 | + }, |
| 145 | + { |
| 146 | + uri: "http://pod.test/alice/contacts/Person/2#this", |
| 147 | + name: "Bob", |
| 148 | + }, |
| 149 | + ]); |
| 150 | + }); |
| 151 | + |
| 152 | + it("ignores members that are not named nodes", () => { |
| 153 | + const store = graph(); |
| 154 | + const groupNode = sym( |
| 155 | + "http://pod.test/alice/contacts/1/group/1/index.ttl#this", |
| 156 | + ); |
| 157 | + store.add(groupNode, vcard("hasMember"), lit("Bob"), groupNode.doc()); |
| 158 | + |
| 159 | + const query = new GroupQuery(store, groupNode); |
| 160 | + const result = query.queryMembers(); |
| 161 | + expect(result).toEqual([]); |
| 162 | + }); |
| 163 | + }); |
66 | 164 | }); |
0 commit comments