|
1 | 1 | import assert from "node:assert/strict"; |
2 | 2 | import test from "node:test"; |
3 | | -import { hasMockSubscription } from "./e2eBridgeSubscriptions.ts"; |
| 3 | +import { |
| 4 | + createMockSubscription, |
| 5 | + hasMockSubscription, |
| 6 | +} from "./e2eBridgeSubscriptions.ts"; |
| 7 | + |
| 8 | +const ready = (filters, channel = "channel", kind = 9, exact = true) => |
| 9 | + hasMockSubscription([createMockSubscription(filters)], channel, kind, exact); |
4 | 10 |
|
5 | 11 | test("channel readiness rejects global-only, wrong-channel and wrong-kind REQs", () => { |
6 | | - const subscription = (channelIds, kinds) => ({ channelIds, kinds }); |
7 | | - for (const candidate of [ |
8 | | - subscription(["*"], [9]), |
9 | | - subscription(["other"], [9]), |
10 | | - subscription(["channel"], [30078]), |
11 | | - ]) { |
12 | | - assert.equal(hasMockSubscription([candidate], "channel", 9, true), false); |
13 | | - } |
| 12 | + for (const filter of [ |
| 13 | + { kinds: [9] }, |
| 14 | + { "#h": [], kinds: [9] }, |
| 15 | + { "#h": ["other"], kinds: [9] }, |
| 16 | + { "#h": ["channel"], kinds: [30078] }, |
| 17 | + ]) |
| 18 | + assert.equal(ready([filter]), false); |
14 | 19 | assert.equal(hasMockSubscription([], "channel", 9, true), false); |
15 | | - for (const kinds of [[9], [7, 9], null]) { |
16 | | - assert.equal( |
17 | | - hasMockSubscription( |
18 | | - [subscription(["channel"], kinds)], |
19 | | - "channel", |
20 | | - 9, |
21 | | - true, |
22 | | - ), |
23 | | - true, |
24 | | - ); |
| 20 | + for (const kinds of [[9], [7, 9], [], undefined]) { |
| 21 | + assert.equal(ready([{ "#h": ["channel"], kinds }]), true); |
| 22 | + } |
| 23 | +}); |
| 24 | + |
| 25 | +test("REQ storage preserves channel/kind correlation across OR filters", () => { |
| 26 | + for (const unrelated of [{ kinds: [9] }, { "#h": ["other"], kinds: [9] }]) { |
| 27 | + const filters = [{ "#h": ["channel"], kinds: [30078] }, unrelated]; |
| 28 | + const stored = createMockSubscription(filters); |
| 29 | + assert.deepEqual(stored.filters, filters); |
| 30 | + assert.equal(hasMockSubscription([stored], "channel", 9, true), false); |
| 31 | + assert.equal(hasMockSubscription([stored], "channel", 30078, true), true); |
| 32 | + assert.equal(ready([...filters, { "#h": ["channel"], kinds: [9] }]), true); |
25 | 33 | } |
26 | 34 | }); |
27 | 35 |
|
28 | 36 | test("legacy readiness and explicit global queries retain their semantics", () => { |
29 | | - const global = [{ channelIds: ["*"], kinds: [30078] }]; |
| 37 | + const global = [createMockSubscription([{ kinds: [30078] }])]; |
30 | 38 | assert.equal(hasMockSubscription(global, "channel"), true); |
31 | 39 | assert.equal(hasMockSubscription(global, "channel", 9), false); |
| 40 | + assert.equal(hasMockSubscription(global, "channel", 30078), true); |
32 | 41 | assert.equal(hasMockSubscription(global, "*", 30078), true); |
33 | 42 | assert.equal(hasMockSubscription(global, "*", 9), false); |
| 43 | + assert.equal(hasMockSubscription(global, "channel", 30078, true), false); |
| 44 | + assert.equal( |
| 45 | + ready( |
| 46 | + [{ "#h": ["channel"], kinds: [30078] }, { kinds: [9] }], |
| 47 | + "channel", |
| 48 | + 9, |
| 49 | + false, |
| 50 | + ), |
| 51 | + true, |
| 52 | + ); |
34 | 53 | }); |
0 commit comments