cojson 0.11.6 → 0.11.7

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.
@@ -2277,30 +2277,16 @@ test("Member roles are inherited by child groups (except invites)", () => {
2277
2277
  parentGroup.addMember(writerInvite, "writerInvite");
2278
2278
  parentGroup.addMember(readerInvite, "readerInvite");
2279
2279
 
2280
- expect(group.roleOfInternal(admin.id)).toEqual({
2281
- role: "admin",
2282
- via: undefined,
2283
- });
2280
+ expect(group.roleOfInternal(admin.id)).toEqual("admin");
2284
2281
 
2285
- expect(group.roleOfInternal(writer.id)).toEqual({
2286
- role: "writer",
2287
- via: parentGroup.id,
2288
- });
2289
2282
  expect(group.roleOf(writer.id)).toEqual("writer");
2290
2283
 
2291
- expect(group.roleOfInternal(reader.id)).toEqual({
2292
- role: "reader",
2293
- via: parentGroup.id,
2294
- });
2295
2284
  expect(group.roleOf(reader.id)).toEqual("reader");
2296
2285
 
2297
- expect(group.roleOfInternal(adminInvite.id)).toEqual(undefined);
2298
2286
  expect(group.roleOf(adminInvite.id)).toEqual(undefined);
2299
2287
 
2300
- expect(group.roleOfInternal(writerInvite.id)).toEqual(undefined);
2301
2288
  expect(group.roleOf(writerInvite.id)).toEqual(undefined);
2302
2289
 
2303
- expect(group.roleOfInternal(readerInvite.id)).toEqual(undefined);
2304
2290
  expect(group.roleOf(readerInvite.id)).toEqual(undefined);
2305
2291
  });
2306
2292
 
@@ -2324,30 +2310,16 @@ test("Member roles are inherited by grand-children groups (except invites)", ()
2324
2310
  grandParentGroup.addMember(writerInvite, "writerInvite");
2325
2311
  grandParentGroup.addMember(readerInvite, "readerInvite");
2326
2312
 
2327
- expect(group.roleOfInternal(admin.id)).toEqual({
2328
- role: "admin",
2329
- via: undefined,
2330
- });
2313
+ expect(group.roleOfInternal(admin.id)).toEqual("admin");
2331
2314
 
2332
- expect(group.roleOfInternal(writer.id)).toEqual({
2333
- role: "writer",
2334
- via: parentGroup.id,
2335
- });
2336
2315
  expect(group.roleOf(writer.id)).toEqual("writer");
2337
2316
 
2338
- expect(group.roleOfInternal(reader.id)).toEqual({
2339
- role: "reader",
2340
- via: parentGroup.id,
2341
- });
2342
2317
  expect(group.roleOf(reader.id)).toEqual("reader");
2343
2318
 
2344
- expect(group.roleOfInternal(adminInvite.id)).toEqual(undefined);
2345
2319
  expect(group.roleOf(adminInvite.id)).toEqual(undefined);
2346
2320
 
2347
- expect(group.roleOfInternal(writerInvite.id)).toEqual(undefined);
2348
2321
  expect(group.roleOf(writerInvite.id)).toEqual(undefined);
2349
2322
 
2350
- expect(group.roleOfInternal(readerInvite.id)).toEqual(undefined);
2351
2323
  expect(group.roleOf(readerInvite.id)).toEqual(undefined);
2352
2324
  });
2353
2325
 
@@ -1,6 +1,6 @@
1
1
  import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
2
  import { expectMap } from "../coValue.js";
3
- import type { CoValueHeader } from "../coValueCore.js";
3
+ import type { CoValueHeader, TryAddTransactionsError } from "../coValueCore.js";
4
4
  import type { RawAccountID } from "../coValues/account.js";
5
5
  import { type MapOpPayload, RawCoMap } from "../coValues/coMap.js";
6
6
  import type { RawGroup } from "../coValues/group.js";
@@ -9,7 +9,7 @@ import { stableStringify } from "../jsonStringify.js";
9
9
  import { LocalNode } from "../localNode.js";
10
10
  import { getPriorityFromHeader } from "../priority.js";
11
11
  import { connectedPeers, newQueuePair } from "../streamUtils.js";
12
- import type { SyncMessage } from "../sync.js";
12
+ import type { LoadMessage, SyncMessage } from "../sync.js";
13
13
  import {
14
14
  blockMessageTypeOnOutgoingPeer,
15
15
  connectNodeToSyncServer,
@@ -2055,3 +2055,106 @@ function groupStateEx(group: RawGroup) {
2055
2055
  id: group.core.id,
2056
2056
  };
2057
2057
  }
2058
+
2059
+ describe("LocalNode.load", () => {
2060
+ test("should throw error when trying to load with undefined ID", async () => {
2061
+ const { node } = await createConnectedTestNode();
2062
+
2063
+ // @ts-expect-error Testing with undefined ID
2064
+ await expect(node.load(undefined)).rejects.toThrow(
2065
+ "Trying to load CoValue with undefined id",
2066
+ );
2067
+ });
2068
+
2069
+ test("should throw error when trying to load with invalid ID format", async () => {
2070
+ const { node } = await createConnectedTestNode();
2071
+
2072
+ // @ts-expect-error Testing with invalid ID format
2073
+ await expect(node.load("invalid_id")).rejects.toThrow(
2074
+ "Trying to load CoValue with invalid id invalid_id",
2075
+ );
2076
+ });
2077
+ });
2078
+
2079
+ describe("SyncManager.handleSyncMessage", () => {
2080
+ test("should ignore messages with undefined ID", async () => {
2081
+ const { node: client } = await createConnectedTestNode();
2082
+ const peer = client.syncManager.getPeers()[0]!;
2083
+
2084
+ // Create an invalid message with undefined ID
2085
+ const invalidMessage = {
2086
+ action: "load",
2087
+ id: undefined,
2088
+ header: false,
2089
+ sessions: {},
2090
+ } as unknown as LoadMessage;
2091
+
2092
+ await client.syncManager.handleSyncMessage(invalidMessage, peer);
2093
+
2094
+ // Verify that no state changes occurred
2095
+ expect(peer.knownStates.has(invalidMessage.id)).toBe(false);
2096
+ expect(peer.optimisticKnownStates.has(invalidMessage.id)).toBe(false);
2097
+ });
2098
+
2099
+ test("should ignore messages with invalid ID format", async () => {
2100
+ const { node: client } = await createConnectedTestNode();
2101
+ const peer = client.syncManager.getPeers()[0]!;
2102
+
2103
+ // Create an invalid message with wrong ID format
2104
+ const invalidMessage = {
2105
+ action: "load",
2106
+ id: "invalid_id",
2107
+ header: false,
2108
+ sessions: {},
2109
+ } as unknown as LoadMessage;
2110
+
2111
+ await client.syncManager.handleSyncMessage(invalidMessage, peer);
2112
+
2113
+ // Verify that no state changes occurred
2114
+ expect(peer.knownStates.has(invalidMessage.id)).toBe(false);
2115
+ expect(peer.optimisticKnownStates.has(invalidMessage.id)).toBe(false);
2116
+ });
2117
+
2118
+ test("should ignore messages for errored coValues", async () => {
2119
+ const { node: client } = await createConnectedTestNode();
2120
+ const peer = client.syncManager.getPeers()[0]!;
2121
+
2122
+ // Add a coValue to the errored set
2123
+ const erroredId = "co_z123" as const;
2124
+ peer.erroredCoValues.set(
2125
+ erroredId,
2126
+ new Error("Test error") as unknown as TryAddTransactionsError,
2127
+ );
2128
+
2129
+ const message = {
2130
+ action: "load" as const,
2131
+ id: erroredId,
2132
+ header: false,
2133
+ sessions: {},
2134
+ } satisfies LoadMessage;
2135
+
2136
+ await client.syncManager.handleSyncMessage(message, peer);
2137
+
2138
+ // Verify that no state changes occurred
2139
+ expect(peer.knownStates.has(message.id)).toBe(false);
2140
+ expect(peer.optimisticKnownStates.has(message.id)).toBe(false);
2141
+ });
2142
+
2143
+ test("should process valid messages", async () => {
2144
+ const { node: client } = await createConnectedTestNode();
2145
+ const group = client.createGroup();
2146
+ const peer = client.syncManager.getPeers()[0]!;
2147
+
2148
+ const validMessage = {
2149
+ action: "load" as const,
2150
+ id: group.id,
2151
+ header: false,
2152
+ sessions: {},
2153
+ };
2154
+
2155
+ await client.syncManager.handleSyncMessage(validMessage, peer);
2156
+
2157
+ // Verify that the message was processed
2158
+ expect(peer.knownStates.has(group.id)).toBe(true);
2159
+ });
2160
+ });