@arcote.tech/arc-host 0.7.15 → 0.7.17

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,95 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import type { CommittedChange } from "@arcote.tech/arc";
3
- import { filterChangeForSubscriber } from "./ws";
4
-
5
- const R = { workspaceId: "w1" };
6
-
7
- function change(partial: Partial<CommittedChange>): CommittedChange {
8
- return { store: "tasks", id: "t1", oldRow: null, newRow: null, ...partial };
9
- }
10
-
11
- describe("filterChangeForSubscriber — old/new restriction matrix", () => {
12
- it("new row matches → set with the full row", () => {
13
- const result = filterChangeForSubscriber(
14
- change({ newRow: { _id: "t1", title: "A", workspaceId: "w1" } }),
15
- R,
16
- );
17
- expect(result).toEqual({
18
- type: "set",
19
- id: "t1",
20
- item: { _id: "t1", title: "A", workspaceId: "w1" },
21
- });
22
- });
23
-
24
- it("neither row matches → null (no id leakage to other tenants)", () => {
25
- const result = filterChangeForSubscriber(
26
- change({
27
- oldRow: { _id: "t1", workspaceId: "w2" },
28
- newRow: { _id: "t1", workspaceId: "w2" },
29
- }),
30
- R,
31
- );
32
- expect(result).toBeNull();
33
- });
34
-
35
- it("scope transition OUT: old matched, new does not → delete", () => {
36
- const result = filterChangeForSubscriber(
37
- change({
38
- oldRow: { _id: "t1", workspaceId: "w1" },
39
- newRow: { _id: "t1", workspaceId: "w2" },
40
- }),
41
- R,
42
- );
43
- expect(result).toEqual({ type: "delete", id: "t1", item: null });
44
- });
45
-
46
- it("scope transition IN: old did not match, new does → set", () => {
47
- const result = filterChangeForSubscriber(
48
- change({
49
- oldRow: { _id: "t1", workspaceId: "w2" },
50
- newRow: { _id: "t1", workspaceId: "w1" },
51
- }),
52
- R,
53
- );
54
- expect(result?.type).toBe("set");
55
- });
56
-
57
- it("delete of an item in my slice → delete", () => {
58
- const result = filterChangeForSubscriber(
59
- change({ oldRow: { _id: "t1", workspaceId: "w1" }, newRow: null }),
60
- R,
61
- );
62
- expect(result).toEqual({ type: "delete", id: "t1", item: null });
63
- });
64
-
65
- it("delete of another tenant's item → null", () => {
66
- const result = filterChangeForSubscriber(
67
- change({ oldRow: { _id: "t1", workspaceId: "w2" }, newRow: null }),
68
- R,
69
- );
70
- expect(result).toBeNull();
71
- });
72
-
73
- it("brand new item outside my slice → null", () => {
74
- const result = filterChangeForSubscriber(
75
- change({ newRow: { _id: "t1", workspaceId: "w2" } }),
76
- R,
77
- );
78
- expect(result).toBeNull();
79
- });
80
-
81
- it("null restrictions (unprotected view) → everything as set/delete", () => {
82
- expect(
83
- filterChangeForSubscriber(
84
- change({ newRow: { _id: "t1", workspaceId: "anything" } }),
85
- null,
86
- )?.type,
87
- ).toBe("set");
88
- expect(
89
- filterChangeForSubscriber(
90
- change({ oldRow: { _id: "t1", workspaceId: "anything" }, newRow: null }),
91
- null,
92
- )?.type,
93
- ).toBe("delete");
94
- });
95
- });