cojson 0.18.36 → 0.18.37

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.
@@ -7,6 +7,7 @@ import {
7
7
  createThreeConnectedNodes,
8
8
  createTwoConnectedNodes,
9
9
  loadCoValueOrFail,
10
+ setupTestAccount,
10
11
  setupTestNode,
11
12
  } from "./testUtils";
12
13
  import { expectMap } from "../coValue.js";
@@ -1161,4 +1162,64 @@ describe("extend with role mapping", () => {
1161
1162
  expect(map.get("test")).toEqual("Written from the admin");
1162
1163
  expect(mapOnNode2.get("test")).toEqual("Written from the admin");
1163
1164
  });
1165
+
1166
+ test("if an account is revoked on the child but still a member of the parent, transactions should be considered valid", async () => {
1167
+ const alice = await setupTestAccount({
1168
+ connected: true,
1169
+ });
1170
+ const bob = await setupTestAccount({
1171
+ connected: true,
1172
+ });
1173
+ const charlie = await setupTestAccount({
1174
+ connected: true,
1175
+ });
1176
+
1177
+ const group = alice.node.createGroup();
1178
+ const parentGroup = alice.node.createGroup();
1179
+
1180
+ const bobInAlice = await loadCoValueOrFail(alice.node, bob.accountID);
1181
+ group.addMember(bobInAlice, "admin");
1182
+ group.extend(parentGroup, "admin");
1183
+ parentGroup.addMember(bobInAlice, "admin");
1184
+
1185
+ const groupInBob = await loadCoValueOrFail(bob.node, group.id);
1186
+ groupInBob.removeMember(bob.node.getCurrentAgent());
1187
+
1188
+ const charlieInBob = await loadCoValueOrFail(bob.node, charlie.accountID);
1189
+ groupInBob.addMember(charlieInBob, "reader");
1190
+
1191
+ expect(groupInBob.roleOf(charlie.accountID)).toBe("reader");
1192
+ });
1193
+
1194
+ test("if an account is revoked on the parent, their old transactions on the child should stay valid", async () => {
1195
+ const alice = await setupTestAccount({
1196
+ connected: true,
1197
+ });
1198
+ const bob = await setupTestAccount({
1199
+ connected: true,
1200
+ });
1201
+ const charlie = await setupTestAccount({
1202
+ connected: true,
1203
+ });
1204
+
1205
+ const group = alice.node.createGroup();
1206
+ const parentGroup = alice.node.createGroup();
1207
+
1208
+ const bobInAlice = await loadCoValueOrFail(alice.node, bob.accountID);
1209
+ group.extend(parentGroup, "admin");
1210
+ parentGroup.addMember(bobInAlice, "admin");
1211
+
1212
+ const groupInBob = await loadCoValueOrFail(bob.node, group.id);
1213
+ const parentGroupInBob = await loadCoValueOrFail(bob.node, parentGroup.id);
1214
+ const charlieInBob = await loadCoValueOrFail(bob.node, charlie.accountID);
1215
+ groupInBob.addMember(charlieInBob, "reader");
1216
+
1217
+ await new Promise((r) => setTimeout(r, 10));
1218
+
1219
+ parentGroupInBob.removeMember(bob.node.getCurrentAgent());
1220
+
1221
+ const groupInCharlie = await loadCoValueOrFail(charlie.node, group.id);
1222
+
1223
+ expect(groupInCharlie.roleOf(charlie.accountID)).toBe("reader");
1224
+ });
1164
1225
  });
@@ -346,15 +346,9 @@ describe("Group invites", () => {
346
346
  });
347
347
 
348
348
  const group = admin.node.createGroup();
349
- const person = group.createMap({
350
- name: "John Doe",
351
- });
352
349
 
353
350
  // First add member as admin
354
- const memberAccount = await loadCoValueOrFail(
355
- member.node,
356
- member.accountID,
357
- );
351
+ const memberAccount = await loadCoValueOrFail(admin.node, member.accountID);
358
352
  group.addMember(memberAccount, "admin");
359
353
 
360
354
  // Create a reader invite
@@ -367,8 +361,6 @@ describe("Group invites", () => {
367
361
  expect(groupOnMemberNode.roleOf(member.accountID)).toEqual("admin");
368
362
  });
369
363
 
370
- logger.setLevel(LogLevel.DEBUG);
371
-
372
364
  test("invites should be able to upgrade the role of an existing member", async () => {
373
365
  const admin = await setupTestAccount({
374
366
  connected: true,
@@ -381,10 +373,7 @@ describe("Group invites", () => {
381
373
  const group = admin.node.createGroup();
382
374
 
383
375
  // First add member as reader
384
- const memberAccount = await loadCoValueOrFail(
385
- member.node,
386
- member.accountID,
387
- );
376
+ const memberAccount = await loadCoValueOrFail(admin.node, member.accountID);
388
377
  group.addMember(memberAccount, "reader");
389
378
 
390
379
  // Create an admin invite
@@ -401,10 +390,7 @@ describe("Group invites", () => {
401
390
  const reader = await setupTestAccount({
402
391
  connected: true,
403
392
  });
404
- const readerAccount = await loadCoValueOrFail(
405
- member.node,
406
- reader.accountID,
407
- );
393
+ const readerAccount = await loadCoValueOrFail(admin.node, reader.accountID);
408
394
  groupOnMemberNode.addMember(readerAccount, "reader");
409
395
  });
410
396
 
@@ -423,10 +409,7 @@ describe("Group invites", () => {
423
409
  });
424
410
 
425
411
  // First add member as reader
426
- const memberAccount = await loadCoValueOrFail(
427
- member.node,
428
- member.accountID,
429
- );
412
+ const memberAccount = await loadCoValueOrFail(admin.node, member.accountID);
430
413
  group.addMember(memberAccount, "reader");
431
414
  await group.removeMember(memberAccount);
432
415