From 5496caff4dd8f5aeb67d99bc7cb9bb14dff56564 Mon Sep 17 00:00:00 2001 From: Zachary Belford Date: Mon, 29 Jul 2019 16:21:01 -0700 Subject: [PATCH] fix: improve coverage --- src/RequestManager.test.ts | 34 ++++++++++++++++++++++++++++++++++ src/RequestManager.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/RequestManager.test.ts b/src/RequestManager.test.ts index 5eb4803..05edcf0 100644 --- a/src/RequestManager.test.ts +++ b/src/RequestManager.test.ts @@ -171,6 +171,25 @@ describe("client-js", () => { }); }); + it("onData throws if the ID is not found", async () => { + const emitter = new EventEmitter(); + const transport = new EventEmitterTransport(emitter, "from1", "to1"); + const serverTransport = new EventEmitterTransport(emitter, "to1", "from1"); + const c = new RequestManager([transport]); + await c.connect(); + expect(() => serverTransport.sendData(JSON.stringify({ + jsonrpc: "2.0", + id: 10, + error: { + code: 0, + message: "out of order", + data: { + foo: "bar", + }, + }, + }))).toThrow(); + }); + describe("stopBatch", () => { it("does nothing if the batch is empty", () => { const emitter = new EventEmitter(); @@ -182,4 +201,19 @@ describe("client-js", () => { expect(transport.sendData).not.toHaveBeenCalled(); }); }); + + describe("startBatch", () => { + it("it does nothing if a batch is already started", async () => { + const emitter = new EventEmitter(); + const transport = new EventEmitterTransport(emitter, "from1", "to1"); + const c = new RequestManager([transport]); + await c.connect(); + c.startBatch(); + c.request("foo", []); + expect(c.batch.length).toBe(1); + c.startBatch(); + c.request("foo", []); + expect(c.batch.length).toBe(2); + }); + }); }); diff --git a/src/RequestManager.ts b/src/RequestManager.ts index 76ab368..59d785d 100644 --- a/src/RequestManager.ts +++ b/src/RequestManager.ts @@ -33,9 +33,9 @@ interface IJSONRPCNotification { class RequestManager { public transports: ITransport[]; public connectPromise: Promise; + public batch: IJSONRPCRequest[] = []; private requests: any; private batchStarted: boolean = false; - private batch: IJSONRPCRequest[] = []; private lastId: number = -1; constructor(transports: ITransport[]) {