hookshot/tests/MessageQueueTest.ts
Will Hunt 819c089aa4
Update minimum Node version to 22 (#990)
* Update dependencies

* Node 22 is now the new minimum version.

* changelog.

* Begin porting eslint to new config format.

* Make linter happy.

* Update reqwest to fix SSL issue?

* Fix test types

* quick check on ubuntu LTS 24.04

* Change cache key

* update rust action

* revert mocha due to esminess

* Remove the only usage of pqueue

* Use babel for TS transformations to get around ESM import bug.

* Dependency bundle upgrade

* Drop babel, not actually used.

* lint

* lint

* update default config (mostly sections moving around)
2024-11-28 15:04:01 +00:00

54 lines
1.7 KiB
TypeScript

import { expect } from "chai";
import { createMessageQueue } from "../src/MessageQueue/MessageQueue";
const mq = createMessageQueue();
describe("MessageQueueTest", () => {
describe("LocalMq", () => {
it("should be able to push an event, and listen for it", (done) => {
mq.subscribe("fakeevent");
mq.on("fakeevent", (msg) => {
expect(msg).to.deep.equal({
sender: "foo",
eventName: "fakeevent",
messageId: "foooo",
data: 51,
});
done();
});
mq.push<number>({
sender: "foo",
eventName: "fakeevent",
messageId: "foooo",
data: 51,
});
});
it("should be able to push an event, and respond to it", async () => {
mq.subscribe("fakeevent2");
mq.subscribe("response.fakeevent2");
mq.on("fakeevent2", async (msg) => {
expect(msg).to.deep.equal({
sender: "foo",
eventName: "fakeevent2",
messageId: "foooo",
data: 49,
});
await mq.push<string>({
sender: "foo",
eventName: "response.fakeevent2",
messageId: "foooo",
data: "worked",
});
});
const response = await mq.pushWait<number, string>({
sender: "foo",
eventName: "fakeevent2",
messageId: "foooo",
data: 49,
});
expect(response).to.equal("worked");
});
});
});