Skip to content

Commit

Permalink
Merge pull request #86 from inversify/dependencies
Browse files Browse the repository at this point in the history
Upgraded dependencies
  • Loading branch information
remojansen committed Nov 2, 2017
2 parents 3fb992e + f0f7e7c commit cd420ee
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ test/**/*.js

type_definitions/**/*.js
type_definitions/*.js
package-lock.json
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ wallaby.js
.travis.yml
.gitignore
.vscode
type_definitions
type_definitions
package-lock.json
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
language: node_js
node_js:
- stable
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.0
- 5.1.1
- 4.4.6
- 8.8.1
- 7.10.1
before_install:
- npm install -g codeclimate-test-reporter
after_success:
Expand Down
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inversify-restify-utils",
"version": "3.2.0",
"version": "3.3.0",
"description": "Some utilities for the development of restify applications with Inversify",
"main": "lib/index.js",
"jsnext:main": "es/index.js",
Expand All @@ -27,30 +27,30 @@
},
"homepage": "https://github.com/inversify/inversify-restify-utils#readme",
"devDependencies": {
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.31",
"@types/node": "^8.0.9",
"@types/restify": "^5.0.2",
"@types/sinon": "^2.1.0",
"@types/supertest": "^2.0.0",
"chai": "^4.1.0",
"gulp": "^3.9.1",
"gulp-istanbul": "^1.0.0",
"gulp-mocha": "^4.0.1",
"gulp-tslint": "^7.0.0",
"gulp-typescript": "^3.0.2",
"inversify": "^4.0.0",
"mocha": "^3.1.1",
"publish-please": "^2.1.4",
"reflect-metadata": "^0.1.3",
"run-sequence": "^1.2.0",
"sinon": "^3.0.0",
"source-map-support": "^0.4.14",
"supertest": "^3.0.0",
"tslint": "^5.0.0",
"typescript": "^2.2.0"
"@types/chai": "4.0.4",
"@types/mocha": "2.2.44",
"@types/node": "8.0.47",
"@types/restify": "5.0.6",
"@types/sinon": "2.3.7",
"@types/supertest": "2.0.3",
"chai": "4.1.2",
"gulp": "3.9.1",
"gulp-istanbul": "1.1.2",
"gulp-mocha": "3.0.1",
"gulp-tslint": "8.1.2",
"gulp-typescript": "3.2.3",
"inversify": "4.5.0",
"mocha": "4.0.1",
"publish-please": "2.3.1",
"reflect-metadata": "0.1.10",
"run-sequence": "2.2.0",
"sinon": "4.0.2",
"source-map-support": "0.5.0",
"supertest": "3.0.0",
"tslint": "5.8.0",
"typescript": "2.6.1"
},
"dependencies": {
"restify": "^6.0.0"
"restify": "6.2.3"
}
}
7 changes: 5 additions & 2 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ export function Options(options: interfaces.RouteOptions, ...middleware: interfa
}

export function Method(
method: string, options: interfaces.RouteOptions, ...middleware: interfaces.Middleware[]): interfaces.HandlerDecorator {
return function (target: any, key: string, value: any) {
method: string,
options: interfaces.RouteOptions,
...middleware: interfaces.Middleware[]
): interfaces.HandlerDecorator {
return function (target: any, key: string) {
let metadata: interfaces.ControllerMethodMetadata = {options, middleware, method, target, key};
let metadataList: interfaces.ControllerMethodMetadata[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { interfaces as inversifyInterfaces } from "inversify";
namespace interfaces {

export type Middleware = (inversifyInterfaces.ServiceIdentifier<any> | restify.RequestHandler);

export interface ControllerMetadata {
path: string;
middleware: Middleware[];
Expand Down
9 changes: 6 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ export class InversifyRestifyServer {
*
* @param container Container loaded with all controllers and their dependencies.
*/
constructor(container: inversify.interfaces.Container, opts?: restify.ServerOptions | interfaces.ServerOptions) {
constructor(container: inversify.interfaces.Container, opts?: (restify.ServerOptions & interfaces.ServerOptions)) {
this.container = container;
this.app = restify.createServer(opts as restify.ServerOptions);
if (opts && opts.hasOwnProperty("defaultRoot") &&
typeof (opts as interfaces.ServerOptions).defaultRoot === "string") {
if (
opts &&
opts.hasOwnProperty("defaultRoot") &&
typeof (opts as interfaces.ServerOptions).defaultRoot === "string"
) {
this.defaultRoot = (opts as interfaces.ServerOptions).defaultRoot as string;
}
}
Expand Down
75 changes: 43 additions & 32 deletions test/framework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("Integration Tests:", () => {
@injectable()
@Controller("/")
class TestController {
@Get("/") public getTest(req: restify.Request, res: restify.Response) {
@Get("/") public getTest() {
return new Promise(((resolve) => {
setTimeout(resolve, 100, "GET");
}));
Expand All @@ -46,7 +46,7 @@ describe("Integration Tests:", () => {
@injectable()
@Controller("/")
class TestController {
@Get("/") public getTest(req: restify.Request, res: restify.Response) {
@Get("/") public getTest() {
return new Promise(((resolve, reject) => {
setTimeout(reject, 100, "GET");
}));
Expand Down Expand Up @@ -132,18 +132,23 @@ describe("Integration Tests:", () => {
}
container.bind<interfaces.Controller>(TYPE.Controller).to(TestController).whenTargetNamed("TestController");

server = new InversifyRestifyServer(container, { formatters: {
"application/json": function formatFoo(req: restify.Request, res: restify.Response, body: any, cb: any) {
res.setHeader(customHeaderName, customHeaderValue);
return cb();
server = new InversifyRestifyServer(
container,
{
formatters: {
"application/json": (req: restify.Request, res: restify.Response, body: any) => {
res.setHeader(customHeaderName, customHeaderValue);
return null;
}
}
}
} });
);
request(server.build())
.get("/")
.expect(customHeaderName, customHeaderValue)
.expect(200, done);
});

it("should allow server options with defaultRoot", (done) => {
let result = {"hello": "world"};
let customHeaderName = "custom-header-name";
Expand All @@ -156,12 +161,18 @@ describe("Integration Tests:", () => {
}
container.bind<interfaces.Controller>(TYPE.Controller).to(TestController).whenTargetNamed("TestController");

server = new InversifyRestifyServer(container, { formatters: {
"application/json": function formatFoo(req: restify.Request, res: restify.Response, body: any, cb: any) {
res.setHeader(customHeaderName, customHeaderValue);
return cb();
server = new InversifyRestifyServer(
container,
{
defaultRoot: "/v1",
formatters: {
"application/json": (req: restify.Request, res: restify.Response, body: any) => {
res.setHeader(customHeaderName, customHeaderValue);
return null;
}
}
}
}, defaultRoot: "/v1" });
);
request(server.build())
.get("/v1")
.expect(customHeaderName, customHeaderValue)
Expand Down Expand Up @@ -210,9 +221,9 @@ describe("Integration Tests:", () => {
request(server.build())
.get("/")
.expect(200, "GET", function () {
expect(spyA.calledOnce).to.be.true;
expect(spyB.calledOnce).to.be.true;
expect(spyC.calledOnce).to.be.true;
expect(spyA.calledOnce).to.eq(true);
expect(spyB.calledOnce).to.eq(true);
expect(spyC.calledOnce).to.eq(true);
expect(result).to.equal("abc");
done();
});
Expand All @@ -231,9 +242,9 @@ describe("Integration Tests:", () => {
request(server.build())
.get("/")
.expect(200, "GET", function () {
expect(spyA.calledOnce).to.be.true;
expect(spyB.calledOnce).to.be.true;
expect(spyC.calledOnce).to.be.true;
expect(spyA.calledOnce).to.eq(true);
expect(spyB.calledOnce).to.eq(true);
expect(spyC.calledOnce).to.eq(true);
expect(result).to.equal("abc");
done();
});
Expand All @@ -259,9 +270,9 @@ describe("Integration Tests:", () => {
request(server.build())
.get("/")
.expect(200, "GET", function () {
expect(spyA.calledOnce).to.be.true;
expect(spyB.calledOnce).to.be.true;
expect(spyC.calledOnce).to.be.true;
expect(spyA.calledOnce).to.eq(true);
expect(spyB.calledOnce).to.eq(true);
expect(spyC.calledOnce).to.eq(true);
expect(result).to.equal("abc");
done();
});
Expand All @@ -285,9 +296,9 @@ describe("Integration Tests:", () => {
request(server.build())
.get("/")
.expect(200, "GET", function () {
expect(spyA.calledOnce).to.be.true;
expect(spyB.calledOnce).to.be.true;
expect(spyC.calledOnce).to.be.true;
expect(spyA.calledOnce).to.eq(true);
expect(spyB.calledOnce).to.eq(true);
expect(spyC.calledOnce).to.eq(true);
expect(result).to.equal("abc");
done();
});
Expand All @@ -311,9 +322,9 @@ describe("Integration Tests:", () => {

request(server.build())
.get("/")
.expect(200, "GET", function() {
expect(spyA.calledOnce).to.be.true;
expect(spyB.calledOnce).to.be.true;
.expect(200, "GET", function() {
expect(spyA.calledOnce).to.eq(true);
expect(spyB.calledOnce).to.eq(true);
expect(result).to.equal("ab");
done();
});
Expand All @@ -339,8 +350,8 @@ describe("Integration Tests:", () => {
request(server.build())
.get("/")
.expect(200, "GET", function() {
expect(spyA.calledOnce).to.be.true;
expect(spyB.calledOnce).to.be.true;
expect(spyA.calledOnce).to.eq(true);
expect(spyB.calledOnce).to.eq(true);
expect(result).to.equal("ab");
done();
});
Expand All @@ -366,8 +377,8 @@ describe("Integration Tests:", () => {
request(server.build())
.get("/")
.expect(200, "GET", function() {
expect(spyA.calledOnce).to.be.true;
expect(spyB.calledOnce).to.be.true;
expect(spyA.calledOnce).to.eq(true);
expect(spyB.calledOnce).to.eq(true);
expect(result).to.equal("ab");
done();
});
Expand Down
23 changes: 13 additions & 10 deletions test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ describe("Unit Test: InversifyRestifyServer", () => {

server.setConfig(configFn);

expect(configFn.called).to.be.false;
expect(configFn.called).to.eq(false);

server.build();

expect(configFn.calledOnce).to.be.true;
expect(configFn.calledOnce).to.eq(true);
});

it("should generate routes for controller methods", () => {
Expand All @@ -49,17 +49,17 @@ describe("Unit Test: InversifyRestifyServer", () => {
let app = server.build();

let routeOne = app.router.routes.GET.find(route => route.spec.path === "/root/routeOne");
expect(routeOne).not.to.be.undefined;
expect(routeOne).not.to.eq(undefined);

let routeTwo = app.router.routes.GET.find(route => route.spec.path === "/root/routeTwo");
expect(routeTwo).not.to.be.undefined;
expect(routeTwo).not.to.eq(undefined);
expect((<any>routeTwo).spec.options).to.eq("test");

let routeThree = app.router.routes.GET.find(route => route.spec.path === "/root/routeThree");
expect(routeThree).not.to.be.undefined;
expect(routeThree).not.to.eq(undefined);

});

it("should generate routes for controller methods using defaultRoot", () => {

@injectable()
Expand All @@ -77,20 +77,23 @@ describe("Unit Test: InversifyRestifyServer", () => {

let container = new Container();
container.bind(TYPE.Controller).to(TestController);

let server = new InversifyRestifyServer(container, {
defaultRoot: "/v1"
});

let app = server.build();

let routeOne = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeOne");
expect(routeOne).not.to.be.undefined;
expect(routeOne).not.to.eq(undefined);

let routeTwo = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeTwo");
expect(routeTwo).not.to.be.undefined;
expect(routeTwo).not.to.eq(undefined);
expect((<any>routeTwo).spec.options).to.eq("test");

let routeThree = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeThree");
expect(routeThree).not.to.be.undefined;
let routeThree = app.router.routes.GET.find(route => route.spec.path === "/v1/root/routeThree");
expect(routeThree).not.eq(undefined);

});

});
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{
"rules": {
"class-name": true,
Expand Down Expand Up @@ -34,7 +35,6 @@
"no-switch-case-fall-through": false,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": true,
"one-line": [true,
Expand Down

0 comments on commit cd420ee

Please sign in to comment.