From f84c0d73ccac78fe58fcb5fb90147f6f22c7721b Mon Sep 17 00:00:00 2001 From: tailuge Date: Sat, 28 Dec 2024 17:23:56 +0000 Subject: [PATCH] tidy --- src/network/client/nchanmessagerelay.ts | 6 ++++-- test/server/messagerelay.spec.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/network/client/nchanmessagerelay.ts b/src/network/client/nchanmessagerelay.ts index 4b416af..9537e2d 100644 --- a/src/network/client/nchanmessagerelay.ts +++ b/src/network/client/nchanmessagerelay.ts @@ -3,12 +3,14 @@ import { MessageRelay } from "./messagerelay" export class NchanMessageRelay implements MessageRelay { private readonly websockets: Map = new Map() - constructor(private readonly baseURL: string) {} + constructor( + private readonly baseURL: string = "https://billiards-network.onrender.com" + ) {} subscribe(channel: string, callback: (message: T) => void): void { const url = `${this.baseURL}/subscribe/${channel}` const ws = new WebSocket(url) - + console.log("Subscribed to ", url) ws.onmessage = (event) => { try { const message = JSON.parse(event.data) as T diff --git a/test/server/messagerelay.spec.ts b/test/server/messagerelay.spec.ts index 03778c1..acbaf3f 100644 --- a/test/server/messagerelay.spec.ts +++ b/test/server/messagerelay.spec.ts @@ -1,6 +1,8 @@ import { expect } from "chai" import { InMemoryMessageRelay } from "../mocks/inmemorymessagerelay" import { MessageRelay } from "../../src/network/client/messagerelay" +import { BreakEvent } from "../../src/events/breakevent" +import { GameEvent } from "../../src/events/gameevent" const jestConsole = console @@ -13,11 +15,11 @@ afterEach(() => { }) describe("MessageRelay", () => { - const relay: MessageRelay = new InMemoryMessageRelay() + const relay: MessageRelay = new InMemoryMessageRelay() it("validate subscriber receives published message", (done) => { const channel = "test" - const message = "hello" + const message = new BreakEvent() relay.subscribe(channel, (msg) => { expect(msg).to.equal(message) done()