cojson 0.9.19 → 0.9.23

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.
@@ -1,4 +1,4 @@
1
- import { expect, test } from "vitest";
1
+ import { expect, test, vi } from "vitest";
2
2
  import { expectMap } from "../coValue.js";
3
3
  import { ControlledAgent } from "../coValues/account.js";
4
4
  import { WasmCrypto } from "../crypto/WasmCrypto.js";
@@ -2908,3 +2908,61 @@ test("extend cycles should not break the keys rotation", () => {
2908
2908
 
2909
2909
  expect(map.get("test")).toEqual("Hello!");
2910
2910
  });
2911
+
2912
+ test("Admin can remove themselves from a group", async () => {
2913
+ const warnSpy = vi.spyOn(console, "warn");
2914
+ const { group, admin } = newGroupHighLevel();
2915
+
2916
+ // Admin removes themselves
2917
+ await group.removeMember(admin);
2918
+
2919
+ expect(group.myRole()).toBeUndefined();
2920
+ expect(warnSpy).not.toHaveBeenCalled();
2921
+ });
2922
+
2923
+ test("Can revoke read permission from 'everyone'", async () => {
2924
+ const { group } = newGroupHighLevel();
2925
+ const childObject = group.createMap();
2926
+
2927
+ // Give everyone read access
2928
+ group.addMember("everyone", "reader");
2929
+
2930
+ childObject.set("foo", "bar", "private");
2931
+ expect(childObject.get("foo")).toEqual("bar");
2932
+
2933
+ // Create a new account to verify access
2934
+ const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
2935
+ const childContent = expectMap(
2936
+ childObject.core
2937
+ .testWithDifferentAccount(
2938
+ newAccount,
2939
+ Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
2940
+ )
2941
+ .getCurrentContent(),
2942
+ );
2943
+
2944
+ // Verify the new account can read
2945
+ expect(childContent.get("foo")).toEqual("bar");
2946
+
2947
+ // Revoke everyone's access
2948
+ await group.removeMember("everyone");
2949
+
2950
+ childObject.set("foo", "updated after revoke", "private");
2951
+
2952
+ // Create another new account to verify access is revoked
2953
+ const newAccount2 = new ControlledAgent(
2954
+ Crypto.newRandomAgentSecret(),
2955
+ Crypto,
2956
+ );
2957
+ const childContent2 = expectMap(
2958
+ childObject.core
2959
+ .testWithDifferentAccount(
2960
+ newAccount2,
2961
+ Crypto.newRandomSessionID(newAccount2.currentAgentID()._unsafeUnwrap()),
2962
+ )
2963
+ .getCurrentContent(),
2964
+ );
2965
+
2966
+ // Verify the new account cannot read after revocation
2967
+ expect(childContent2.get("foo")).toEqual("bar");
2968
+ });