@tsed/platform-test-sdk 8.11.1 → 8.11.2-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/lib/esm/components/PlatformTestSdk.js +0 -1
  2. package/lib/esm/errors/CustomBadRequest.js +0 -1
  3. package/lib/esm/errors/CustomInternalError.js +0 -1
  4. package/lib/esm/index.js +0 -1
  5. package/lib/esm/interfaces/PlatformTestingSdkOpts.js +0 -1
  6. package/lib/esm/interfaces/index.js +0 -1
  7. package/lib/esm/modules/feature/FeatureModule.js +0 -1
  8. package/lib/esm/modules/feature/controllers/FeatureController.js +0 -1
  9. package/lib/esm/tests/exports.js +0 -1
  10. package/lib/esm/tests/testAcceptMime.js +0 -1
  11. package/lib/esm/tests/testAuth.js +0 -1
  12. package/lib/esm/tests/testBodyParams.js +0 -1
  13. package/lib/esm/tests/testCache.js +0 -1
  14. package/lib/esm/tests/testChildrenControllers.js +0 -1
  15. package/lib/esm/tests/testCookies.js +0 -1
  16. package/lib/esm/tests/testCustom404.js +0 -1
  17. package/lib/esm/tests/testDeepQueryParams.js +0 -1
  18. package/lib/esm/tests/testErrors.js +0 -1
  19. package/lib/esm/tests/testHandlers.js +0 -1
  20. package/lib/esm/tests/testHeaderParams.js +0 -1
  21. package/lib/esm/tests/testHeaders.js +0 -1
  22. package/lib/esm/tests/testInheritanceController.js +0 -1
  23. package/lib/esm/tests/testLocals.js +0 -1
  24. package/lib/esm/tests/testLocation.js +0 -1
  25. package/lib/esm/tests/testMiddlewares.js +0 -1
  26. package/lib/esm/tests/testModule.js +0 -1
  27. package/lib/esm/tests/testMulter.js +0 -1
  28. package/lib/esm/tests/testPathParams.js +0 -1
  29. package/lib/esm/tests/testQueryParams.js +0 -1
  30. package/lib/esm/tests/testRedirect.js +0 -1
  31. package/lib/esm/tests/testResponse.js +0 -1
  32. package/lib/esm/tests/testResponseFilter.js +0 -1
  33. package/lib/esm/tests/testRouting.js +0 -1
  34. package/lib/esm/tests/testScopeRequest.js +0 -1
  35. package/lib/esm/tests/testSession.js +0 -1
  36. package/lib/esm/tests/testStatics.js +0 -1
  37. package/lib/esm/tests/testStream.js +0 -1
  38. package/lib/esm/tests/testView.js +0 -1
  39. package/package.json +18 -15
  40. package/.barrelsby.json +0 -5
  41. package/lib/esm/components/PlatformTestSdk.js.map +0 -1
  42. package/lib/esm/errors/CustomBadRequest.js.map +0 -1
  43. package/lib/esm/errors/CustomInternalError.js.map +0 -1
  44. package/lib/esm/index.js.map +0 -1
  45. package/lib/esm/interfaces/PlatformTestingSdkOpts.js.map +0 -1
  46. package/lib/esm/interfaces/index.js.map +0 -1
  47. package/lib/esm/modules/feature/FeatureModule.js.map +0 -1
  48. package/lib/esm/modules/feature/controllers/FeatureController.js.map +0 -1
  49. package/lib/esm/tests/exports.js.map +0 -1
  50. package/lib/esm/tests/testAcceptMime.js.map +0 -1
  51. package/lib/esm/tests/testAuth.js.map +0 -1
  52. package/lib/esm/tests/testBodyParams.js.map +0 -1
  53. package/lib/esm/tests/testCache.js.map +0 -1
  54. package/lib/esm/tests/testChildrenControllers.js.map +0 -1
  55. package/lib/esm/tests/testCookies.js.map +0 -1
  56. package/lib/esm/tests/testCustom404.js.map +0 -1
  57. package/lib/esm/tests/testDeepQueryParams.js.map +0 -1
  58. package/lib/esm/tests/testErrors.js.map +0 -1
  59. package/lib/esm/tests/testHandlers.js.map +0 -1
  60. package/lib/esm/tests/testHeaderParams.js.map +0 -1
  61. package/lib/esm/tests/testHeaders.js.map +0 -1
  62. package/lib/esm/tests/testInheritanceController.js.map +0 -1
  63. package/lib/esm/tests/testLocals.js.map +0 -1
  64. package/lib/esm/tests/testLocation.js.map +0 -1
  65. package/lib/esm/tests/testMiddlewares.js.map +0 -1
  66. package/lib/esm/tests/testModule.js.map +0 -1
  67. package/lib/esm/tests/testMulter.js.map +0 -1
  68. package/lib/esm/tests/testPathParams.js.map +0 -1
  69. package/lib/esm/tests/testQueryParams.js.map +0 -1
  70. package/lib/esm/tests/testRedirect.js.map +0 -1
  71. package/lib/esm/tests/testResponse.js.map +0 -1
  72. package/lib/esm/tests/testResponseFilter.js.map +0 -1
  73. package/lib/esm/tests/testRouting.js.map +0 -1
  74. package/lib/esm/tests/testScopeRequest.js.map +0 -1
  75. package/lib/esm/tests/testSession.js.map +0 -1
  76. package/lib/esm/tests/testStatics.js.map +0 -1
  77. package/lib/esm/tests/testStream.js.map +0 -1
  78. package/lib/esm/tests/testView.js.map +0 -1
  79. package/src/components/PlatformTestSdk.ts +0 -30
  80. package/src/data/file.txt +0 -1
  81. package/src/data/response.data.json +0 -3
  82. package/src/data/swagger.json +0 -32
  83. package/src/errors/CustomBadRequest.ts +0 -16
  84. package/src/errors/CustomInternalError.ts +0 -16
  85. package/src/index.ts +0 -40
  86. package/src/interfaces/PlatformTestingSdkOpts.ts +0 -10
  87. package/src/interfaces/index.ts +0 -4
  88. package/src/modules/feature/FeatureModule.ts +0 -10
  89. package/src/modules/feature/controllers/FeatureController.ts +0 -11
  90. package/src/tests/exports.ts +0 -71
  91. package/src/tests/testAcceptMime.ts +0 -99
  92. package/src/tests/testAuth.ts +0 -345
  93. package/src/tests/testBodyParams.ts +0 -525
  94. package/src/tests/testCache.ts +0 -283
  95. package/src/tests/testChildrenControllers.ts +0 -59
  96. package/src/tests/testCookies.ts +0 -41
  97. package/src/tests/testCustom404.ts +0 -35
  98. package/src/tests/testDeepQueryParams.ts +0 -125
  99. package/src/tests/testErrors.ts +0 -233
  100. package/src/tests/testHandlers.ts +0 -94
  101. package/src/tests/testHeaderParams.ts +0 -158
  102. package/src/tests/testHeaders.ts +0 -78
  103. package/src/tests/testInheritanceController.ts +0 -206
  104. package/src/tests/testLocals.ts +0 -53
  105. package/src/tests/testLocation.ts +0 -40
  106. package/src/tests/testMiddlewares.ts +0 -155
  107. package/src/tests/testModule.ts +0 -50
  108. package/src/tests/testMulter.ts +0 -186
  109. package/src/tests/testPathParams.ts +0 -127
  110. package/src/tests/testQueryParams.ts +0 -238
  111. package/src/tests/testRedirect.ts +0 -129
  112. package/src/tests/testResponse.ts +0 -573
  113. package/src/tests/testResponseFilter.ts +0 -106
  114. package/src/tests/testRouting.ts +0 -71
  115. package/src/tests/testScopeRequest.ts +0 -116
  116. package/src/tests/testSession.ts +0 -109
  117. package/src/tests/testStatics.ts +0 -64
  118. package/src/tests/testStream.ts +0 -63
  119. package/src/tests/testView.ts +0 -75
@@ -1,283 +0,0 @@
1
- import {Controller, Inject} from "@tsed/di";
2
- import {PlatformCache, UseCache} from "@tsed/platform-cache";
3
- import {PlatformTest} from "@tsed/platform-http/testing";
4
- import {PathParams, QueryParams} from "@tsed/platform-params";
5
- import {Get, Head, Post, Property} from "@tsed/schema";
6
- import SuperTest from "supertest";
7
- import {afterEach, beforeEach, describe, expect, it} from "vitest";
8
-
9
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
10
-
11
- let increment = 0;
12
-
13
- export function testCache(options: PlatformTestingSdkOpts) {
14
- let request: SuperTest.Agent;
15
-
16
- class MyModel {
17
- @Property()
18
- name: string;
19
- }
20
-
21
- class MyService {
22
- @UseCache({
23
- key: "key"
24
- })
25
- get(id: string) {
26
- return {id: `one:${id}`};
27
- }
28
-
29
- @UseCache({
30
- key(args: any[]) {
31
- return `key:${args[0]}`;
32
- }
33
- })
34
- get2(id: string) {
35
- return {id: `one:${id}`};
36
- }
37
- }
38
-
39
- @Controller("/caches")
40
- class TestCacheController {
41
- @Inject()
42
- myService: MyService;
43
-
44
- @Get("/scenario-1")
45
- @UseCache()
46
- scenario1() {
47
- increment++;
48
- return "hello world " + increment;
49
- }
50
-
51
- @Get("/scenario-2")
52
- @UseCache({ttl: 400})
53
- scenario2() {
54
- return {info: "hello child"};
55
- }
56
-
57
- @Head("/scenario-3")
58
- @UseCache()
59
- scenario3() {
60
- return undefined;
61
- }
62
-
63
- @Post("/scenario-4")
64
- @UseCache()
65
- scenario4() {
66
- return {info: "hello child"};
67
- }
68
-
69
- @Get("/scenario-5/:id")
70
- @UseCache({ttl: 400})
71
- scenario5(@PathParams("id") id: string, @QueryParams() model: MyModel) {
72
- return {info: "hello child", id, ...model};
73
- }
74
-
75
- @Get("/scenario-6/:id")
76
- scenario6(@PathParams("id") id: string) {
77
- return this.myService.get(id);
78
- }
79
-
80
- @Get("/scenario-7/:id")
81
- scenario7(@PathParams("id") id: string) {
82
- return this.myService.get2(id);
83
- }
84
- }
85
-
86
- describe("withCache", () => {
87
- beforeEach(
88
- PlatformTest.bootstrap(options.server, {
89
- ...options,
90
- logger: {},
91
- mount: {
92
- "/rest": [TestCacheController]
93
- },
94
- cache: {
95
- ttl: 300,
96
- store: "memory"
97
- }
98
- })
99
- );
100
- beforeEach(() => {
101
- request = SuperTest(PlatformTest.callback());
102
- });
103
- afterEach(PlatformTest.reset);
104
-
105
- describe("scenario 1: GET /rest/caches/scenario-1", () => {
106
- it("should return data with cached response", async () => {
107
- const response = await request.get("/rest/caches/scenario-1").expect(200);
108
- const response2 = await request.get("/rest/caches/scenario-1").expect(200);
109
-
110
- expect(response.text).toContain("hello world");
111
- expect(response.headers["cache-control"]).toMatch(/max-age=300/);
112
- expect(response.headers["x-cached"]).toBeUndefined();
113
-
114
- expect(response2.text).toContain("hello world");
115
- expect(response2.headers["cache-control"]).toMatch(/max-age=300/);
116
- expect(response2.headers["x-cached"]).toEqual("true");
117
- expect(response2.headers["etag"]).toEqual(response.headers["etag"]);
118
- });
119
-
120
- it("should return 304 when content isn't modified", async () => {
121
- const platformCache = PlatformTest.get<PlatformCache>(PlatformCache);
122
-
123
- const response = await request.get("/rest/caches/scenario-1").expect(200);
124
-
125
- if (response.headers["etag"]) {
126
- // platform koa doesn't support Etag
127
- await request
128
- .get("/rest/caches/scenario-1")
129
- .set("if-none-match", response.headers["etag"] || "")
130
- .expect(304);
131
-
132
- await platformCache.reset();
133
-
134
- await request
135
- .get("/rest/caches/scenario-1")
136
- .set("if-none-match", response.headers["etag"] || "")
137
- .expect(200);
138
- }
139
- });
140
-
141
- it("should return fresh data if cache-control is set to no-cache", async () => {
142
- await request.get("/rest/caches/scenario-1").expect(200);
143
- const response2 = await request.get("/rest/caches/scenario-1").set("cache-control", "no-cache").expect(200);
144
-
145
- expect(response2.text).toContain("hello world");
146
- expect(response2.headers["cache-control"]).toMatch(/max-age=300/);
147
- expect(response2.headers["x-cached"]).toBeUndefined();
148
- expect(response2.headers["etag"]).toEqual(response2.headers["etag"]);
149
- });
150
- });
151
- describe("scenario 2: GET /rest/caches/scenario-2", () => {
152
- it("should return data with cached response", async () => {
153
- const response = await request.get("/rest/caches/scenario-2").expect(200);
154
- const response2 = await request.get("/rest/caches/scenario-2").expect(200);
155
-
156
- expect(response.body).toEqual({info: "hello child"});
157
- expect(response.headers["cache-control"]).toMatch(/max-age=400/);
158
- expect(response.headers["x-cached"]).toBeUndefined();
159
-
160
- expect(response2.body).toEqual({info: "hello child"});
161
- expect(response2.headers["cache-control"]).toMatch(/max-age=400/);
162
- expect(response2.headers["x-cached"]).toEqual("true");
163
- expect(response2.headers["etag"]).toEqual(response.headers["etag"]);
164
- });
165
- });
166
- describe("scenario 4: POST /rest/caches/scenario-4", () => {
167
- it("should not cache POST method", async () => {
168
- const response = await request.post("/rest/caches/scenario-4").expect(200);
169
- const response2 = await request.post("/rest/caches/scenario-4").expect(200);
170
-
171
- expect(response.body).toEqual({
172
- info: "hello child"
173
- });
174
- expect(response.headers["cache-control"]).toBeUndefined();
175
- expect(response.headers["x-cached"]).toBeUndefined();
176
-
177
- expect(response2.body).toEqual({
178
- info: "hello child"
179
- });
180
- expect(response.headers["cache-control"]).toBeUndefined();
181
- expect(response2.headers["x-cached"]).toBeUndefined();
182
- expect(response2.headers["etag"]).toEqual(response.headers["etag"]);
183
- });
184
- });
185
- describe("scenario 5: GET /rest/caches/scenario-5", () => {
186
- it("should return data with then cache response", async () => {
187
- const response = await request.get("/rest/caches/scenario-5/1?name=1").expect(200);
188
- const response2 = await request.get("/rest/caches/scenario-5/1?name=1").expect(200);
189
- const response3 = await request.get("/rest/caches/scenario-5/2?name=2").expect(200);
190
- const response4 = await request.get("/rest/caches/scenario-5/2?name=2").expect(200);
191
- const response5 = await request.get("/rest/caches/scenario-5/2?name=3").expect(200);
192
-
193
- expect(response.body).toEqual({
194
- id: "1",
195
- info: "hello child",
196
- name: "1"
197
- });
198
- expect(response2.body).toEqual({
199
- id: "1",
200
- info: "hello child",
201
- name: "1"
202
- });
203
- expect(response.headers["x-cached"]).toBeUndefined();
204
- expect(response2.headers["x-cached"]).toEqual("true");
205
- expect(response.body).toEqual(response2.body);
206
-
207
- expect(response3.body).toEqual({
208
- id: "2",
209
- info: "hello child",
210
- name: "2"
211
- });
212
- expect(response4.body).toEqual({
213
- id: "2",
214
- info: "hello child",
215
- name: "2"
216
- });
217
- expect(response3.headers["x-cached"]).toBeUndefined();
218
- expect(response4.headers["x-cached"]).toEqual("true");
219
- expect(response3.body).toEqual(response4.body);
220
-
221
- expect(response2.body).not.toEqual(response4);
222
- expect(response5.body).not.toEqual(response4);
223
- });
224
- });
225
- describe("scenario 6: GET /rest/caches/scenario-6", () => {
226
- it("should return data from cached service", async () => {
227
- const response = await request.get("/rest/caches/scenario-6/1").expect(200);
228
- const response2 = await request.get("/rest/caches/scenario-6/2").expect(200);
229
-
230
- expect(response.body).toEqual({id: "one:1"});
231
- expect(response2.body).toEqual({id: "one:1"});
232
- expect(response.headers["x-cached"]).toBeUndefined();
233
- expect(response2.headers["x-cached"]).toBeUndefined();
234
- expect(response.body).toEqual(response2.body);
235
- });
236
- });
237
- describe("scenario 7: GET /rest/caches/scenario-7", () => {
238
- it("should return data from cached service", async () => {
239
- const response = await request.get("/rest/caches/scenario-7/1").expect(200);
240
- const response2 = await request.get("/rest/caches/scenario-7/2").expect(200);
241
- const response3 = await request.get("/rest/caches/scenario-7/2").expect(200);
242
-
243
- expect(response.body).toEqual({id: "one:1"});
244
- expect(response2.body).toEqual({
245
- id: "one:2"
246
- });
247
- expect(response3.body).toEqual({
248
- id: "one:2"
249
- });
250
- expect(response.body).not.toEqual(response2.body);
251
- });
252
- });
253
- });
254
- describe("withoutCache", () => {
255
- beforeEach(
256
- PlatformTest.bootstrap(options.server, {
257
- ...options,
258
- logger: {},
259
- cache: false,
260
- mount: {
261
- "/rest": [TestCacheController]
262
- }
263
- })
264
- );
265
- beforeEach(() => {
266
- request = SuperTest(PlatformTest.callback());
267
- });
268
- afterEach(PlatformTest.reset);
269
-
270
- describe("scenario 1: GET /rest/caches/scenario-1", () => {
271
- it("should return data with cached response", async () => {
272
- const response = await request.get("/rest/caches/scenario-1").expect(200);
273
- const response2 = await request.get("/rest/caches/scenario-1").expect(200);
274
-
275
- expect(response.text).toContain("hello world");
276
- expect(response.headers["x-cached"]).toBeUndefined();
277
-
278
- expect(response2.text).toContain("hello world");
279
- expect(response2.headers["x-cached"]).toBeUndefined();
280
- });
281
- });
282
- });
283
- }
@@ -1,59 +0,0 @@
1
- import {Controller} from "@tsed/di";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
- import {Get} from "@tsed/schema";
4
- import SuperTest from "supertest";
5
- import {afterEach, beforeEach, describe, expect, it} from "vitest";
6
-
7
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
8
-
9
- export function testChildrenControllers(options: PlatformTestingSdkOpts) {
10
- let request: SuperTest.Agent;
11
-
12
- @Controller("/children")
13
- class TestChildController {
14
- @Get("/scenario-2")
15
- get() {
16
- return "hello child";
17
- }
18
- }
19
-
20
- @Controller({
21
- path: "/controllers",
22
- children: [TestChildController]
23
- })
24
- class TestController {
25
- @Get("/scenario-1")
26
- scenario1() {
27
- return "hello world";
28
- }
29
- }
30
-
31
- beforeEach(
32
- PlatformTest.bootstrap(options.server, {
33
- ...options,
34
- mount: {
35
- "/rest": [TestController]
36
- }
37
- })
38
- );
39
- beforeEach(() => {
40
- request = SuperTest(PlatformTest.callback());
41
- });
42
- afterEach(PlatformTest.reset);
43
-
44
- describe("scenario 1: GET /rest/controllers/scenario-1", () => {
45
- it("should return a response from method", async () => {
46
- const response = await request.get("/rest/controllers/scenario-1").expect(200);
47
-
48
- expect(response.text).toEqual("hello world");
49
- });
50
- });
51
-
52
- describe("scenario 2: GET /rest/controllers/children/scenario-2", () => {
53
- it("should return a response from method", async () => {
54
- const response = await request.get("/rest/controllers/children/scenario-2").expect(200);
55
-
56
- expect(response.text).toEqual("hello child");
57
- });
58
- });
59
- }
@@ -1,41 +0,0 @@
1
- import {Controller} from "@tsed/di";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
- import {CookiesParams} from "@tsed/platform-params";
4
- import {Get} from "@tsed/schema";
5
- import SuperTest from "supertest";
6
- import {afterAll, beforeAll, expect, it} from "vitest";
7
-
8
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
9
-
10
- @Controller("/cookies")
11
- export class CookiesCtrl {
12
- /**
13
- * Handle request and get auth from cookies
14
- * @param authorization
15
- */
16
- @Get("/scenario-1")
17
- public scenario1(@CookiesParams("authorization") authorization: string) {
18
- return {authorization};
19
- }
20
- }
21
-
22
- export function testCookies(options: PlatformTestingSdkOpts) {
23
- let request: SuperTest.Agent;
24
- beforeAll(
25
- PlatformTest.bootstrap(options.server, {
26
- ...options,
27
- mount: {
28
- "/rest": [CookiesCtrl]
29
- }
30
- })
31
- );
32
- beforeAll(() => {
33
- request = SuperTest(PlatformTest.callback());
34
- });
35
- afterAll(PlatformTest.reset);
36
- it("Scenario 1: GET /rest/cookies/scenario-1", async () => {
37
- const {body} = await request.get("/rest/cookies/scenario-1").set("Cookie", "authorization=eOIjdkk").expect(200);
38
-
39
- expect(body.authorization).toEqual("eOIjdkk");
40
- });
41
- }
@@ -1,35 +0,0 @@
1
- import {PlatformTest} from "@tsed/platform-http/testing";
2
- import SuperTest from "supertest";
3
- import {afterAll, beforeAll, expect, it} from "vitest";
4
-
5
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
6
-
7
- export function testCustom404(options: PlatformTestingSdkOpts) {
8
- class CustomServer extends options.server {}
9
-
10
- let request: SuperTest.Agent;
11
- beforeAll(
12
- PlatformTest.bootstrap(CustomServer, {
13
- ...options,
14
- mount: {
15
- "/rest": []
16
- }
17
- })
18
- );
19
-
20
- beforeAll(() => {
21
- request = SuperTest(PlatformTest.callback());
22
- });
23
- afterAll(PlatformTest.reset);
24
-
25
- it("Scenario 1: GET /", async () => {
26
- const response: any = await request.get("/").expect(404);
27
-
28
- expect(response.body).toEqual({
29
- name: "NOT_FOUND",
30
- message: 'Resource "/" not found',
31
- status: 404,
32
- errors: []
33
- });
34
- });
35
- }
@@ -1,125 +0,0 @@
1
- import "@tsed/ajv";
2
-
3
- import {Controller} from "@tsed/di";
4
- import {PlatformTest} from "@tsed/platform-http/testing";
5
- import {QueryParams} from "@tsed/platform-params";
6
- import {Default, GenericOf, Generics, Get, Maximum, Minimum, Property} from "@tsed/schema";
7
- import SuperTest from "supertest";
8
- import {afterAll, beforeAll, describe, expect, it} from "vitest";
9
-
10
- import {PlatformTestingSdkOpts} from "../interfaces/index.js";
11
-
12
- class FindQuery {
13
- @Property()
14
- a?: number;
15
-
16
- @Property()
17
- b?: number;
18
- }
19
-
20
- @Generics("T")
21
- class PaginationQuery<T> {
22
- // things about pagination
23
- @Minimum(0)
24
- @Default(0)
25
- offset?: number;
26
-
27
- @Minimum(1)
28
- @Maximum(1000)
29
- @Default(50)
30
- limit?: number;
31
-
32
- @Property("T")
33
- where?: T;
34
- }
35
-
36
- @Controller("/deep-query-params")
37
- class TestDeepQueryParamsCtrl {
38
- @Get("/scenario-1")
39
- testScenario6(@QueryParams() @GenericOf(FindQuery) q: PaginationQuery<FindQuery>, @QueryParams() qs: any) {
40
- return {q};
41
- }
42
-
43
- @Get("/scenario-2")
44
- testScenario7(@QueryParams("q") @GenericOf(FindQuery) q: PaginationQuery<FindQuery>) {
45
- return {q};
46
- }
47
- }
48
-
49
- export function testDeepQueryParams(options: PlatformTestingSdkOpts) {
50
- let request: SuperTest.Agent;
51
-
52
- beforeAll(
53
- PlatformTest.bootstrap(options.server, {
54
- ...options,
55
- ajv: {
56
- verbose: false
57
- },
58
- mount: {
59
- "/rest": [TestDeepQueryParamsCtrl]
60
- }
61
- })
62
- );
63
- beforeAll(() => {
64
- request = SuperTest(PlatformTest.callback());
65
- });
66
- afterAll(PlatformTest.reset);
67
- describe("Scenario1: DeepObject", () => {
68
- const endpoint = "/rest/deep-query-params/scenario-1";
69
- it("should return 0 when query is 0", async () => {
70
- const response = await request.get(`${endpoint}?offset=0&limit=10&where[a]=0&where[b]=1`).expect(200);
71
-
72
- expect(response.body).toEqual({
73
- q: {
74
- limit: 10,
75
- offset: 0,
76
- where: {
77
- a: 0,
78
- b: 1
79
- }
80
- }
81
- });
82
- });
83
- });
84
- describe("Scenario2: DeepObject", () => {
85
- const endpoint = "/rest/deep-query-params/scenario-2";
86
- it("should return the query value", async () => {
87
- const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=0&q[where][b]=1`).expect(200);
88
-
89
- expect(response.body).toEqual({
90
- q: {
91
- limit: 10,
92
- offset: 0,
93
- where: {
94
- a: 0,
95
- b: 1
96
- }
97
- }
98
- });
99
- });
100
- it("should throw a bad request", async () => {
101
- const response = await request.get(`${endpoint}?q[offset]=0&q[limit]=10&q[where][a]=ca&q[where][b]=1`).expect(400);
102
-
103
- expect(response.body).toEqual({
104
- errors: [
105
- {
106
- requestPath: "query",
107
- data: "ca",
108
- dataPath: ".where.a",
109
- instancePath: "/where/a",
110
- keyword: "type",
111
- message: "must be number",
112
- modelName: "PaginationQuery",
113
- params: {
114
- type: "number"
115
- },
116
- schemaPath: "#/properties/where/properties/a/type"
117
- }
118
- ],
119
- message: 'Bad request on parameter "request.query.q".\nPaginationQuery.where.a must be number. Given value: "ca"',
120
- name: "AJV_VALIDATION_ERROR",
121
- status: 400
122
- });
123
- });
124
- });
125
- }