Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Travis
committed
Apr 21, 2020
1 parent
f37fc6d
commit c1af938
Showing
10 changed files
with
1,024 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
require: [ | ||
"ts-node/register/transpile-only", | ||
"tsconfig-paths/register", | ||
"scripts/mocha/register" | ||
], | ||
recursive: true, | ||
reporter: "dot", | ||
spec: [ | ||
"src/**/*.spec.ts", | ||
"test/**/*.spec.ts" | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import * as SuperTest from "supertest"; | ||
import {Controller, ExpressApplication, Get, PathParams, Post, Res} from "@tsed/common"; | ||
import {inject, TestContext} from "@tsed/testing"; | ||
import {expect} from "chai"; | ||
import {Server} from "../../src/Server"; | ||
|
||
@Controller("/") | ||
export class PathParamsCtrl { | ||
@Get("/scenario1/:scope/:scopeId") | ||
async testScenario1(@PathParams("scope") scope: string) { | ||
// Here scope will be {0: 'a', 1: 'b', 2: 'c'} instead of 'abc' in version 5.47.0 | ||
expect(scope).to.eq("abc"); | ||
|
||
return scope; | ||
} | ||
|
||
@Get("/scenario2/:scope/:scopeId") | ||
async testScenario2(@PathParams("scope") scope: any) { | ||
// This way it works in version 5.47.0 | ||
expect(scope).to.eq("abc"); | ||
|
||
return scope; | ||
} | ||
|
||
@Post("/scenario3/:scope/:scopeId") | ||
async testScenario3( | ||
@PathParams("scope") scope: string | ||
): Promise<any[]> { | ||
expect(scope).to.eq("abc"); | ||
|
||
// Here the function will return {0: 'a', 1: 'b', 2: 'c'} instead of ['a','b','c'] in version 5.44.13 | ||
return ["a", "b", "c"]; | ||
} | ||
|
||
@Post("/scenario4/:scope/:scopeId") | ||
async testScenario4( | ||
@PathParams("scope") scope: string, | ||
@Res() response: any | ||
): Promise<any[]> { | ||
expect(scope).to.eq("abc"); | ||
|
||
// This way it works in version 5.44.13 | ||
return response.json(["a", "b", "c"]); | ||
} | ||
} | ||
|
||
describe("PathParams", () => { | ||
let request: SuperTest.SuperTest<SuperTest.Test>; | ||
before(TestContext.bootstrap(Server, { | ||
mount: { | ||
"/rest": PathParamsCtrl | ||
} | ||
})); | ||
before( | ||
inject([ExpressApplication], (expressApplication: ExpressApplication) => { | ||
request = SuperTest(expressApplication); | ||
}) | ||
); | ||
after(TestContext.reset); | ||
|
||
it("scenario 1: GET /rest/scope/scopeId", async () => { | ||
const response = await request.get("/rest/scenario1/abc/1").expect(200); | ||
|
||
response.text.should.be.deep.equal("abc"); | ||
}); | ||
|
||
it("scenario 2: GET /rest/scope/scopeId", async () => { | ||
const response = await request.get("/rest/scenario2/abc/1").expect(200); | ||
|
||
response.text.should.be.deep.equal("abc"); | ||
}); | ||
|
||
it("scenario 3: POST /rest/scope/scopeId", async () => { | ||
const response = await request.post("/rest/scenario3/abc/1").expect(200); | ||
|
||
response.body.should.be.deep.equal(["a", "b", "c"]); | ||
}); | ||
|
||
it("scenario 4: POST /rest/scope/scopeId", async () => { | ||
const response = await request.post("/rest/scenario4/abc/1").expect(200); | ||
|
||
response.body.should.be.deep.equal(["a", "b", "c"]); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.