cojson 0.14.1 → 0.14.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,6 +157,29 @@ describe("extend", () => {
157
157
 
158
158
  expect(childGroup.roleOf(node2.accountID)).toEqual(undefined);
159
159
  });
160
+
161
+ test("should be possible to extend a group without having membership in the parent group", async () => {
162
+ const { node1, node2, node3 } = await createThreeConnectedNodes(
163
+ "server",
164
+ "server",
165
+ "server",
166
+ );
167
+
168
+ const parentGroup = node1.node.createGroup();
169
+ const childGroup = node2.node.createGroup();
170
+
171
+ const alice = await loadCoValueOrFail(node1.node, node3.accountID);
172
+ parentGroup.addMember(alice, "writer");
173
+
174
+ const parentGroupOnNode2 = await loadCoValueOrFail(
175
+ node2.node,
176
+ parentGroup.id,
177
+ );
178
+
179
+ childGroup.extend(parentGroupOnNode2);
180
+
181
+ expect(childGroup.roleOf(alice.id)).toBe("writer");
182
+ });
160
183
  });
161
184
 
162
185
  describe("unextend", () => {
@@ -191,6 +214,78 @@ describe("unextend", () => {
191
214
  expect(childGroup.roleOf(alice.id)).toBe(undefined);
192
215
  });
193
216
 
217
+ test("should work when the account has no access to the parent group but owns the writeKey", async () => {
218
+ const { node1, node2, node3 } = await createThreeConnectedNodes(
219
+ "server",
220
+ "server",
221
+ "server",
222
+ );
223
+
224
+ const parentGroup = node1.node.createGroup();
225
+ const childGroup = node2.node.createGroup();
226
+
227
+ const alice = await loadCoValueOrFail(node1.node, node3.accountID);
228
+ parentGroup.addMember(alice, "writer");
229
+
230
+ const parentGroupOnNode2 = await loadCoValueOrFail(
231
+ node2.node,
232
+ parentGroup.id,
233
+ );
234
+
235
+ childGroup.extend(parentGroupOnNode2);
236
+
237
+ expect(childGroup.roleOf(alice.id)).toBe("writer");
238
+
239
+ // `childGroup` no longer has `parentGroup`'s members
240
+ await childGroup.revokeExtend(parentGroup);
241
+ expect(childGroup.roleOf(alice.id)).toBe(undefined);
242
+
243
+ const map = childGroup.createMap();
244
+ map.set("test", "Hello!");
245
+
246
+ const mapOnAlice = await loadCoValueOrFail(node3.node, map.id);
247
+
248
+ expect(mapOnAlice.get("test")).toEqual(undefined);
249
+ });
250
+
251
+ test("should work when the account has no access to the parent group and not owns the writeKey", async () => {
252
+ const {
253
+ node1: bobNode,
254
+ node2: johnNode,
255
+ node3: aliceNode,
256
+ } = await createThreeConnectedNodes("server", "server", "server");
257
+
258
+ const parentGroup = bobNode.node.createGroup();
259
+ const childGroup = johnNode.node.createGroup();
260
+
261
+ const parentGroupOnJohn = await loadCoValueOrFail(
262
+ johnNode.node,
263
+ parentGroup.id,
264
+ );
265
+
266
+ childGroup.extend(parentGroupOnJohn);
267
+
268
+ const bob = await loadCoValueOrFail(johnNode.node, bobNode.accountID);
269
+ const alice = await loadCoValueOrFail(johnNode.node, aliceNode.accountID);
270
+ childGroup.addMember(alice, "admin");
271
+
272
+ const childGroupOnAlice = await loadCoValueOrFail(
273
+ aliceNode.node,
274
+ childGroup.id,
275
+ );
276
+
277
+ // `childGroup` no longer has `parentGroup`'s members
278
+ await childGroupOnAlice.revokeExtend(parentGroup);
279
+ expect(childGroupOnAlice.roleOf(bob.id)).toBe(undefined);
280
+
281
+ const map = childGroupOnAlice.createMap();
282
+ map.set("test", "Hello!");
283
+
284
+ const mapOnBob = await loadCoValueOrFail(bobNode.node, map.id);
285
+
286
+ expect(mapOnBob.get("test")).toEqual(undefined);
287
+ });
288
+
194
289
  test("should do nothing if applied to a group that is not extended", async () => {
195
290
  const { node1, node2, node3 } = await createThreeConnectedNodes(
196
291
  "server",
@@ -1982,40 +1982,6 @@ test("Writers, readers and writeOnly can set child extensions", () => {
1982
1982
  expect(groupAsReader.get(`child_${childGroup.id}`)).toEqual("extend");
1983
1983
  });
1984
1984
 
1985
- test("Invitees can not set child extensions", () => {
1986
- const { group, node } = newGroupHighLevel();
1987
- const childGroup = node.createGroup();
1988
-
1989
- const adminInvite = createAccountInNode(node);
1990
- const writerInvite = createAccountInNode(node);
1991
- const readerInvite = createAccountInNode(node);
1992
-
1993
- group.addMember(adminInvite, "adminInvite");
1994
- group.addMember(writerInvite, "writerInvite");
1995
- group.addMember(readerInvite, "readerInvite");
1996
-
1997
- const groupAsAdminInvite = expectGroup(
1998
- group.core.contentInClonedNodeWithDifferentAccount(adminInvite),
1999
- );
2000
-
2001
- groupAsAdminInvite.set(`child_${childGroup.id}`, "extend", "trusting");
2002
- expect(groupAsAdminInvite.get(`child_${childGroup.id}`)).toBeUndefined();
2003
-
2004
- const groupAsWriterInvite = expectGroup(
2005
- group.core.contentInClonedNodeWithDifferentAccount(writerInvite),
2006
- );
2007
-
2008
- groupAsWriterInvite.set(`child_${childGroup.id}`, "extend", "trusting");
2009
- expect(groupAsWriterInvite.get(`child_${childGroup.id}`)).toBeUndefined();
2010
-
2011
- const groupAsReaderInvite = expectGroup(
2012
- group.core.contentInClonedNodeWithDifferentAccount(readerInvite),
2013
- );
2014
-
2015
- groupAsReaderInvite.set(`child_${childGroup.id}`, "extend", "trusting");
2016
- expect(groupAsReaderInvite.get(`child_${childGroup.id}`)).toBeUndefined();
2017
- });
2018
-
2019
1985
  test("Member roles are inherited by child groups (except invites)", () => {
2020
1986
  const { group, node, admin } = newGroupHighLevel();
2021
1987
  const parentGroup = node.createGroup();