Skip to content

Commit

Permalink
Added test case for inversify/InversifyJS/issues/527
Browse files Browse the repository at this point in the history
  • Loading branch information
remojansen committed Apr 7, 2017
1 parent bd16e7a commit 585eb3b
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/bugs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { expect } from "chai";
import * as express from "express";
import { Controller, Method, Get, Request, Response, RequestParam } from "../src/decorators";
import { interfaces } from "../src/interfaces";
import { METADATA_KEY, PARAMETER_TYPE } from "../src/constants";
import { InversifyExpressServer } from "../src/server";
import { Container, injectable } from "inversify";
import { TYPE } from "../src/constants";
import * as request from "supertest";

describe("Unit Test: Previous bugs", () => {

it("should support multiple controller methods with param annotations", (done) => {

let container = new Container();

@injectable()
@Controller("/api/test")
class TestController {
@Get("/")
public get(
@Request() req: express.Request,
@Response() res: express.Response
) {
expect(req.url).not.to.eql(undefined);
expect((req as any).setHeader).to.eql(undefined);
expect(res.setHeader).not.to.eql(undefined);
expect((res as any).url).to.eql(undefined);
res.json([{ id: 1 }, { id: 2 }]);
}
@Get("/:id")
public getById(
@RequestParam("id") id: string,
@Request() req: express.Request,
@Response() res: express.Response
) {
expect(id).to.eql("5");
expect(req.url).not.to.eql(undefined);
expect((req as any).setHeader).to.eql(undefined);
expect(res.setHeader).not.to.eql(undefined);
expect((res as any).url).to.eql(undefined);
res.json({ id: id });
}
}

container.bind(TYPE.Controller).to(TestController);
let server = new InversifyExpressServer(container);
let app = server.build();

request(app).get("/api/test/")
.expect("Content-Type", /json/)
.expect(200)
.then(response1 => {
expect(Array.isArray(response1.body)).to.eql(true);
expect(response1.body[0].id).to.eql("1");
expect(response1.body[0].id).to.eql("2");
});

request(app).get("/api/test/5")
.expect("Content-Type", /json/)
.expect(200)
.then(response2 => {
expect(Array.isArray(response2.body)).to.eql(false);
expect(response2.body.id).to.eql("5");
done();
});

});

});

1 comment on commit 585eb3b

@dcavanagh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remojansen This test case is actually failing. I noticed it when i was writing a pull request. My test was producing a similar error but would stop the rest of the tests from executing.

The problem is that you are inputing 1 and 2 on line 29 and expecting "1" and "2" in lines 55 & 56

I have no idea why this isn't causing a test failure.

this message appears
Unit Test: Previous bugs
(node:24900) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected 1 to deeply equal '1'
(node:24900) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js pro

Please sign in to comment.