Skip to content

Commit

Permalink
fix: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Jul 29, 2019
1 parent 586ef40 commit 5496caf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/RequestManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});
});
});
2 changes: 1 addition & 1 deletion src/RequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ interface IJSONRPCNotification {
class RequestManager {
public transports: ITransport[];
public connectPromise: Promise<any>;
public batch: IJSONRPCRequest[] = [];
private requests: any;
private batchStarted: boolean = false;
private batch: IJSONRPCRequest[] = [];
private lastId: number = -1;

constructor(transports: ITransport[]) {
Expand Down

0 comments on commit 5496caf

Please sign in to comment.