it("should decompress with 'deflateRaw'", () => { const mw = Middleware({ method: "deflateRaw", threshold: 0 }); mw.created(broker); const meta = {}; const next = jest.fn(); const receive = mw.transporterReceive.call(broker, next); const compressedData = Buffer.concat([COMPRESSED_FLAG, zlib.deflateRawSync(Buffer.from("compressed data"))]); return receive("topic", compressedData, meta).catch(protectReject).then(() => { expect(next).toHaveBeenCalledTimes(1); expect(next).toHaveBeenCalledWith("topic", Buffer.from("compressed data"), meta); }); });
it("should compress with 'deflateRaw'", () => { const mw = Middleware({ method: "deflateRaw", threshold: 0 }); mw.created(broker); const meta = {}; const next = jest.fn(() => Promise.resolve()); const send = mw.transporterSend.call(broker, next); return send("topic", Buffer.from("uncompressed data"), meta).catch(protectReject).then(() => { expect(next).toHaveBeenCalledTimes(1); expect(next).toHaveBeenCalledWith("topic", expect.any(Buffer), meta); expect(next.mock.calls[0][1]).toEqual(Buffer.concat([COMPRESSED_FLAG, zlib.deflateRawSync(Buffer.from("uncompressed data"))])); }); });