Skip to content

Commit 3cc5c3f

Browse files
committed
added test covering the merge of global and local ValidationOptions
1 parent 9432860 commit 3cc5c3f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/functional/class-validator-options.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,52 @@ describe("parameters auto-validation", () => {
158158
});
159159
});
160160

161+
describe("should merge local validation options with global validation options prioritizing local", () => {
162+
163+
let requestFilter: any;
164+
beforeEach(() => {
165+
requestFilter = undefined;
166+
});
167+
168+
before(() => {
169+
getMetadataArgsStorage().reset();
170+
171+
@JsonController()
172+
class ClassTransformUserController {
173+
174+
@Get("/user")
175+
getUsers(@QueryParam("filter", { validate: { skipMissingProperties: false } }) filter: UserFilter): any {
176+
requestFilter = filter;
177+
const user = new UserModel();
178+
user.id = 1;
179+
user._firstName = "Umed";
180+
user._lastName = "Khudoiberdiev";
181+
return user;
182+
}
183+
184+
}
185+
});
186+
187+
const options: RoutingControllersOptions = {
188+
validation: {
189+
whitelist: true,
190+
skipMissingProperties: true
191+
}
192+
};
193+
194+
let expressApp: any, koaApp: any;
195+
before(done => expressApp = createExpressServer(options).listen(3001, done));
196+
after(done => expressApp.close(done));
197+
before(done => koaApp = createKoaServer(options).listen(3002, done));
198+
after(done => koaApp.close(done));
199+
200+
assertRequest([3001, 3002], "get", "user?filter={\"keyword\": \"aValidKeyword\", \"notKeyword\": \"Um\", \"__somethingPrivate\": \"blablabla\"}", response => {
201+
expect(response).to.have.status(200);
202+
expect(requestFilter).to.have.property("keyword");
203+
expect(requestFilter).to.not.have.property("notKeyword");
204+
});
205+
});
206+
161207
describe("should pass the valid param after validation", () => {
162208

163209
let requestFilter: any;

0 commit comments

Comments
 (0)