From 7475bb9fa47b082b0cfff4d148b4c3f8dff64b32 Mon Sep 17 00:00:00 2001 From: Aleksandr Zinin Date: Thu, 24 Oct 2024 00:01:34 +0400 Subject: [PATCH] add Datahandler constructor test Signed-off-by: Aleksandr Zinin --- test/unit/DataHandler.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/unit/DataHandler.ts diff --git a/test/unit/DataHandler.ts b/test/unit/DataHandler.ts new file mode 100644 index 00000000..850366a1 --- /dev/null +++ b/test/unit/DataHandler.ts @@ -0,0 +1,30 @@ +import * as sinon from "sinon"; +import { expect } from "chai"; +import DataHandler from "../../lib/DataHandler"; + +describe("DataHandler", () => { + afterEach(() => { + sinon.restore(); + }); + + describe("constructor()", () => { + it("should add a data handler to the redis stream properly", () => { + const dataHandledable = { + stream: { + prependListener: sinon.spy(), + resume: sinon.spy(), + }, + }; + new DataHandler(dataHandledable, {}); + + expect(dataHandledable.stream.prependListener.calledOnce).to.eql(true); + expect(dataHandledable.stream.resume.calledOnce).to.eql(true); + + expect( + dataHandledable.stream.resume.calledAfter( + dataHandledable.stream.prependListener + ) + ).to.eql(true); + }); + }); +});