Skip to content

Commit 19a931a

Browse files
author
Aleksi Pekkala
committed
Test action only transforming requests, cleanup default values from test controllers
1 parent 0d9ebae commit 19a931a

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

test/functional/action-options.spec.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ describe("action options", () => {
4646
@JsonController("", {transformResponse: false})
4747
class NoTransformResponseController {
4848
@Post("/default")
49-
default(@Body() user: UserModel) { return handler(user); }
49+
default(@Body() user: UserModel) {
50+
return handler(user);
51+
}
5052

51-
@Post("/override", {transformRequest: false, transformResponse: true})
52-
transform(@Body() user: UserModel) { return handler(user); }
53+
@Post("/transformRequestOnly", {transformRequest: true, transformResponse: false})
54+
transformRequestOnly(@Body() user: UserModel) {
55+
return handler(user);
56+
}
57+
58+
@Post("/transformResponseOnly", {transformRequest: false, transformResponse: true})
59+
transformResponseOnly(@Body() user: UserModel) {
60+
return handler(user);
61+
}
5362
}
5463
});
5564

@@ -64,12 +73,21 @@ describe("action options", () => {
6473
expect(initializedUser).to.be.instanceOf(User);
6574
expect(initializedUser.lastName).to.be.undefined;
6675
expect(response).to.have.status(200);
67-
expect(response.body.lastName).to.exist;
76+
expect(response.body.lastName).to.equal("default");
77+
});
78+
});
79+
80+
it("should override controller options with action transformRequest option", () => {
81+
assertRequest([3001, 3002], "post", "transformRequestOnly", { firstName: "Umed", lastName: "Khudoiberdiev" }, response => {
82+
expect(initializedUser).to.be.instanceOf(User);
83+
expect(initializedUser.lastName).to.be.undefined;
84+
expect(response).to.have.status(200);
85+
expect(response.body.lastName).to.equal("default");
6886
});
6987
});
7088

71-
it("should override controller options when action transform options are set", () => {
72-
assertRequest([3001, 3002], "post", "override", { firstName: "Umed", lastName: "Khudoiberdiev" }, response => {
89+
it("should override controller options with action transformResponse option", () => {
90+
assertRequest([3001, 3002], "post", "transformResponseOnly", { firstName: "Umed", lastName: "Khudoiberdiev" }, response => {
7391
expect(initializedUser).not.to.be.instanceOf(User);
7492
expect(initializedUser.lastName).to.exist;
7593
expect(response).to.have.status(200);

test/functional/controller-options.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("controller options", () => {
3939
initializedUser = user;
4040
const ret = new User();
4141
ret.firstName = user.firstName;
42-
ret.lastName = user.lastName || "default";
42+
ret.lastName = user.lastName;
4343
return ret;
4444
}
4545

test/functional/global-options.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("routing-controllers global options", () => {
4343
initializedUser = user;
4444
const ret = new User();
4545
ret.firstName = user.firstName;
46-
ret.lastName = user.lastName || "default";
46+
ret.lastName = user.lastName;
4747
return ret;
4848
}
4949

0 commit comments

Comments
 (0)