mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-04 06:43:12 +00:00
fix: filter subscription with pubsubTopic1 and decoder with pubsubTopic2 (#1675)
* add a test for a failing case * add error handling & update test * remove only * rename test
This commit is contained in:
parent
81b2bf46ab
commit
491366bd4f
@ -74,6 +74,16 @@ class Subscription {
|
|||||||
callback: Callback<T>
|
callback: Callback<T>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const decodersArray = Array.isArray(decoders) ? decoders : [decoders];
|
const decodersArray = Array.isArray(decoders) ? decoders : [decoders];
|
||||||
|
|
||||||
|
// check that all decoders are configured for the same pubsub topic as this subscription
|
||||||
|
decodersArray.forEach((decoder) => {
|
||||||
|
if (decoder.pubsubTopic !== this.pubsubTopic) {
|
||||||
|
throw new Error(
|
||||||
|
`Pubsub topic not configured: decoder is configured for pubsub topic ${decoder.pubsubTopic} but this subscription is for pubsub topic ${this.pubsubTopic}. Please create a new Subscription for the different pubsub topic.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const decodersGroupedByCT = groupByContentTopic(decodersArray);
|
const decodersGroupedByCT = groupByContentTopic(decodersArray);
|
||||||
const contentTopics = Array.from(decodersGroupedByCT.keys());
|
const contentTopics = Array.from(decodersGroupedByCT.keys());
|
||||||
|
|
||||||
|
|||||||
@ -146,4 +146,15 @@ describe("Waku Filter V2: Multiple PubSubtopics", function () {
|
|||||||
expectedMessageText: "M2"
|
expectedMessageText: "M2"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Should fail to subscribe with decoder with wrong pubsubTopic", async function () {
|
||||||
|
// this subscription object is set up with the `customPubsubTopic` but we're passing it a Decoder with the `DefaultPubsubTopic`
|
||||||
|
try {
|
||||||
|
await subscription.subscribe([TestDecoder], messageCollector.callback);
|
||||||
|
} catch (error) {
|
||||||
|
expect((error as Error).message).to.include(
|
||||||
|
"Pubsub topic not configured"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user