@tsed/platform-test-sdk 7.73.1 → 7.73.3

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