Skip to content

Commit

Permalink
added basic tests for server side decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
iangeckeler committed Aug 6, 2019
1 parent 8e63409 commit a443a10
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ const originalCall = {
};
const clientUnaryDecorator = require("../../../lib/callFactories/callDecorators/clientUnaryDecorator");

describe("Client unary decorator tests.", () => {
describe("decorator adds the right methods", () => {
//adds properties
describe("tests for client unary decorator", () => {
describe("basic Tests for method assignment", () => {
beforeEach(() => {
clientUnaryDecorator(object, originalCall);
clientUnaryDecorator(object, () => {});
});
it("Has an on property", () => {
it("should have an on", () => {
expect(object.hasOwnProperty("on")).toBeTruthy();
});
});
Expand Down
16 changes: 11 additions & 5 deletions __tests__/callFactories/callDecorators/serverStreamDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ const object = {};
const originalCall = {
hello: "hello"
};
const clientUnaryDecorator = require("../../../lib/callFactories/callDecorators/clientUnaryDecorator");
const serverStreamDecorator = require("../../../lib/callFactories/callDecorators/serverStreamDecorator");

describe("Client unary decorator tests.", () => {
describe("server stream decorator tests.", () => {
describe("decorator adds the right methods", () => {
//adds properties
beforeEach(() => {
clientUnaryDecorator(object, originalCall);
serverStreamDecorator(object, originalCall);
});
it("Has an on property", () => {
expect(object.hasOwnProperty("on")).toBeTruthy();
it("Has an set property", () => {
expect(object.hasOwnProperty("set")).toBeTruthy();
});
it("Has an send property", () => {
expect(object.hasOwnProperty("send")).toBeTruthy();
});
it("Has an throw property", () => {
expect(object.hasOwnProperty("throw")).toBeTruthy();
});
});
});
2 changes: 1 addition & 1 deletion lib/callFactories/callDecorators/clientUnaryDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//this.body becomes the thing

module.exports = function clientUnaryDecorator(customCall, originalCall) {
customCall.body = originCall.request;
customCall.body = originalCall.request;

customCall.head = originalCall.metadata;

Expand Down
2 changes: 1 addition & 1 deletion lib/callFactories/callDecorators/serverStreamDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = function serverStreamDecorator(customCall, originalCall) {
}
};

customCall.customCall.send = function(message) {
customCall.send = function(message) {
if (!this.metadataSent && this.metadata) {
const metadata = generateMeta(this.metadata);
this.call.sendMetadata(metadata);
Expand Down

0 comments on commit a443a10

Please sign in to comment.