From 0dcfd0dee84beb2c3d7d760b1f3428ed5590db5f Mon Sep 17 00:00:00 2001 From: tailuge Date: Fri, 27 Dec 2024 17:41:20 +0000 Subject: [PATCH] tidy --- src/network/client/nchanmessagerelay.ts | 2 +- test/server/messagerelay.spec.ts | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/server/messagerelay.spec.ts diff --git a/src/network/client/nchanmessagerelay.ts b/src/network/client/nchanmessagerelay.ts index 555b6668..390f38e1 100644 --- a/src/network/client/nchanmessagerelay.ts +++ b/src/network/client/nchanmessagerelay.ts @@ -2,7 +2,7 @@ import { MessageRelay } from "./messagerelay" export class NchanMessageRelay implements MessageRelay { - private websockets: Map = new Map() + private readonly websockets: Map = new Map() constructor(private readonly baseURL: string) { } diff --git a/test/server/messagerelay.spec.ts b/test/server/messagerelay.spec.ts new file mode 100644 index 00000000..305a7f6a --- /dev/null +++ b/test/server/messagerelay.spec.ts @@ -0,0 +1,28 @@ +import "mocha" +import { expect } from "chai" +import { InMemoryMessageRelay } from "../mocks/inmemorymessagerelay" +import { MessageRelay } from "../../src/network/client/messagerelay" + +const jestConsole = console + +beforeEach(() => { + global.console = require("console") +}) + +afterEach(() => { + global.console = jestConsole +}) + +describe("Lobby", () => { + const relay: MessageRelay = new InMemoryMessageRelay() + + it("validate subscriber receives published message", (done) => { + const channel = "test" + const message = "hello" + relay.subscribe(channel, (msg) => { + expect(msg).to.equal(message) + done() + }) + relay.publish(channel, message) + }) +})