Skip to content

Commit

Permalink
laid down tests for server stream decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
iangeckeler committed Aug 7, 2019
1 parent d1a9a3c commit 9ae443c
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions __tests__/callFactories/callDecorators/serverStreamDecorator.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
const object = {};
const basicCallDecorator = require("../../../lib/callFactories/callDecorators/basicCallDecorator");
const serverStreamDecorator = require("../../../lib/callFactories/callDecorators/serverStreamDecorator");

const customCall = {};

const mockEmit = jest.fn();
const mockSendMetadata = jest.fn();
const mockWrite = jest.fn();

const originalCall = {
hello: "hello"
hello: "hello",
emit: mockEmit,
write: mockWrite,
sendMetadata: mockSendMetadata
};
const serverStreamDecorator = require("../../../lib/callFactories/callDecorators/serverStreamDecorator");

basicCallDecorator(customCall, originalCall);
serverStreamDecorator(customCall, originalCall);

describe("server stream decorator tests.", () => {
beforeEach(() => {
mockWrite.mockClear();
mockEmit.mockClear();
mockSendMetadata.mockClear();
});
describe("decorator adds the right methods", () => {
//adds properties
beforeEach(() => {
serverStreamDecorator(object, originalCall);
});

it("Has an set property", () => {
expect(object.hasOwnProperty("set")).toBeTruthy();
expect(customCall.hasOwnProperty("set")).toBeTruthy();
});
it("Has an send property", () => {
expect(object.hasOwnProperty("send")).toBeTruthy();
expect(customCall.hasOwnProperty("send")).toBeTruthy();
});
it("Has an throw property", () => {
expect(object.hasOwnProperty("throw")).toBeTruthy();
expect(customCall.hasOwnProperty("throw")).toBeTruthy();
});
});

describe("tests for throw", () => {
it("throw will throw if not an error", () => {
expect(() => customCall.throw("fake")).toThrow();
});
it("expect it to emit error", () => {
const fakeError = new Error("fake");
customCall.throw(fakeError);
expect(mockEmit.mock.calls[0][0]).toEqual("error");
expect(mockEmit.mock.calls[0][1]).toBe(fakeError);
});
});

describe("tests for set", () => {});
describe("tests for send", () => {});
});

0 comments on commit 9ae443c

Please sign in to comment.