Skip to content

Commit

Permalink
finished test for error-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha GRASSO committed Dec 29, 2017
1 parent 0341184 commit 7043e23
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ Go have a look at https://github.com/gaspaonrocks/universal-node-router/blob/mas
If it is still not working, post an issue.`;
return true;
default:
this.result = 'No error here...';
this.result = 'Use case not covered';
return false;
}
} else if (typeof method === 'function') {
this.result = 'No error here...';
return false;
}
}
}
40 changes: 40 additions & 0 deletions test/error-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,44 @@ describe('ErrorHandler module', () => {
it('ErrorHandler.errorChecker should be a Function', () => {
expect(typeof TestEH.errorChecker, 'function');
});

it('ErrorHandler.errorChecker should return a boolean with a value of false when given an unknown method and any string', () => {
function mockFn() {
return 'HelloWorldOfTest !';
};

let useCase = TestEH.errorChecker(mockFn, 'anyCase');

expect(useCase).to.equal(false);
expect(TestEH.result).to.equal('No error here...');
});

it('ErrorHandler.errorChecker should return a boolean with a value of false when given an undefined controller method and a string !== "controller" && string !== "mapper"', () => {
let mockFn = undefined;

let useCase = TestEH.errorChecker(mockFn, 'anyCase');

expect(useCase).to.equal(false);
expect(TestEH.result).to.equal('Use case not covered');
});

it('ErrorHandler.errorChecker should return a boolean with a value of true when given an undefined controller method and a string === "mapper"', () => {
let mockFn = undefined;

let useCase = TestEH.errorChecker(mockFn, 'mapper');

expect(useCase).to.equal(true);
expect(TestEH.result).to.equal('Request not handled, it must be one of GET, POST, PUT, PATCH, or DELETE');
});

it('ErrorHandler.errorChecker should return a boolean with a value of true when given an undefined controller method and a string === "controller"', () => {
let mockFn = undefined;

let useCase = TestEH.errorChecker(mockFn, 'controller');

expect(useCase).to.equal(true);
expect(TestEH.result).to.equal(`Trying to use a method not implemented in the controller like advised in the docs of the router.
Go have a look at https://github.com/gaspaonrocks/universal-node-router/blob/master/readme.md for more info.
If it is still not working, post an issue.`);
});
});

0 comments on commit 7043e23

Please sign in to comment.