@tsed/platform-test-sdk 8.0.0 → 8.0.2

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 (42) hide show
  1. package/package.json +15 -14
  2. package/src/components/PlatformTestSdk.ts +30 -0
  3. package/src/data/file.txt +1 -0
  4. package/src/data/response.data.json +3 -0
  5. package/src/data/swagger.json +32 -0
  6. package/src/errors/CustomBadRequest.ts +16 -0
  7. package/src/errors/CustomInternalError.ts +16 -0
  8. package/src/index.ts +40 -0
  9. package/src/interfaces/PlatformTestingSdkOpts.ts +10 -0
  10. package/src/interfaces/index.ts +4 -0
  11. package/src/modules/feature/FeatureModule.ts +10 -0
  12. package/src/modules/feature/controllers/FeatureController.ts +11 -0
  13. package/src/tests/exports.ts +71 -0
  14. package/src/tests/testAcceptMime.ts +99 -0
  15. package/src/tests/testAuth.ts +345 -0
  16. package/src/tests/testBodyParams.ts +488 -0
  17. package/src/tests/testCache.ts +283 -0
  18. package/src/tests/testChildrenControllers.ts +59 -0
  19. package/src/tests/testCookies.ts +41 -0
  20. package/src/tests/testCustom404.ts +35 -0
  21. package/src/tests/testDeepQueryParams.ts +125 -0
  22. package/src/tests/testErrors.ts +233 -0
  23. package/src/tests/testHandlers.ts +94 -0
  24. package/src/tests/testHeaderParams.ts +158 -0
  25. package/src/tests/testHeaders.ts +78 -0
  26. package/src/tests/testInheritanceController.ts +206 -0
  27. package/src/tests/testLocals.ts +53 -0
  28. package/src/tests/testLocation.ts +40 -0
  29. package/src/tests/testMiddlewares.ts +155 -0
  30. package/src/tests/testModule.ts +50 -0
  31. package/src/tests/testMulter.ts +158 -0
  32. package/src/tests/testPathParams.ts +127 -0
  33. package/src/tests/testQueryParams.ts +238 -0
  34. package/src/tests/testRedirect.ts +129 -0
  35. package/src/tests/testResponse.ts +533 -0
  36. package/src/tests/testResponseFilter.ts +106 -0
  37. package/src/tests/testRouting.ts +71 -0
  38. package/src/tests/testScopeRequest.ts +116 -0
  39. package/src/tests/testSession.ts +108 -0
  40. package/src/tests/testStatics.ts +63 -0
  41. package/src/tests/testStream.ts +62 -0
  42. package/src/tests/testView.ts +74 -0
@@ -0,0 +1,533 @@
1
+ import {Controller, getContext} from "@tsed/di";
2
+ import {PlatformResponse, Res} from "@tsed/platform-http";
3
+ import {PlatformTest} from "@tsed/platform-http/testing";
4
+ import {Context, PathParams} from "@tsed/platform-params";
5
+ import {CollectionOf, Enum, ForwardGroups, Get, Groups, Ignore, Name, Post, Property, Required, Returns, Status} from "@tsed/schema";
6
+ import axios from "axios";
7
+ import {of} from "rxjs";
8
+ import {agent} from "superagent";
9
+ import SuperTest from "supertest";
10
+ import {afterAll, beforeAll, describe, expect, it} from "vitest";
11
+
12
+ import {PlatformTestingSdkOpts} from "../interfaces/index.js";
13
+
14
+ class Base {
15
+ @Ignore()
16
+ ignoreMeBase: string;
17
+
18
+ @Property()
19
+ fooBase: string;
20
+ }
21
+
22
+ class MyModel extends Base {
23
+ @Property()
24
+ foo: string;
25
+
26
+ @Ignore()
27
+ ignoreMe: string;
28
+
29
+ @Ignore((value, ctx) => ctx.endpoint)
30
+ ignoreMe2: string;
31
+ }
32
+
33
+ class EmptyModel {
34
+ raw: any;
35
+ affected?: number | null;
36
+ }
37
+
38
+ export enum EnumValue {
39
+ One = "one",
40
+ Two = "two"
41
+ }
42
+
43
+ export class NestedEnum {
44
+ @Required()
45
+ @Enum(EnumValue)
46
+ value: EnumValue;
47
+ }
48
+
49
+ export class TestNestedEnum {
50
+ @Property()
51
+ nested: NestedEnum;
52
+ }
53
+
54
+ export class ModelGroup {
55
+ @Property()
56
+ id: string;
57
+
58
+ @Groups("!creation")
59
+ groups: string;
60
+ }
61
+
62
+ class TeamModel {
63
+ @Required()
64
+ @Name("teamName")
65
+ name: string;
66
+ }
67
+
68
+ class TeamsModel {
69
+ @Required()
70
+ @CollectionOf(TeamModel)
71
+ @ForwardGroups()
72
+ teams: TeamModel[];
73
+ }
74
+
75
+ class AllowedModel {
76
+ @Property()
77
+ id: string;
78
+
79
+ @Property()
80
+ description: string;
81
+
82
+ @Groups("summary")
83
+ prop1: string; // not display by default
84
+
85
+ @Groups("details")
86
+ prop2: string; // not display by default
87
+
88
+ @Groups("admin")
89
+ sensitiveProp: string; // not displayed because it's a sensitive props
90
+ }
91
+
92
+ @Controller("/response")
93
+ class TestResponseParamsCtrl {
94
+ @Get("/scenario1/:id")
95
+ public testScenario1Get(@PathParams("id") id: number) {
96
+ return `hello-${id}`;
97
+ }
98
+
99
+ @Post("/scenario3/:id?")
100
+ @Status(204)
101
+ public testScenario3EmptyResponse(@PathParams("id") id: number, @Context() ctx: Context) {
102
+ if (id) {
103
+ return;
104
+ }
105
+
106
+ ctx.response.status(201);
107
+
108
+ return {
109
+ id: 1
110
+ };
111
+ }
112
+
113
+ @Get("/scenario5")
114
+ async testScenario5Promise() {
115
+ await new Promise((resolve) => {
116
+ resolve(undefined);
117
+ });
118
+
119
+ return {
120
+ id: 1
121
+ };
122
+ }
123
+
124
+ @Get("/scenario6")
125
+ testScenario6Observable() {
126
+ return of({id: 1});
127
+ }
128
+
129
+ @Get("/scenario6b")
130
+ testScenario6bObservable() {
131
+ return Promise.resolve(of({id: 1}));
132
+ }
133
+
134
+ @Get("/scenario9/static")
135
+ public testScenario9Get(): string {
136
+ return "value";
137
+ }
138
+
139
+ @Get("/scenario9/:id")
140
+ public testScenario9WithDynamicParam(@PathParams("id") id: number): string {
141
+ return "value" + id;
142
+ }
143
+
144
+ @Get("/scenario10")
145
+ public testScenario10() {
146
+ const model = new MyModel();
147
+ model.foo = "foo";
148
+ model.ignoreMe = "ignoreMe";
149
+ model.ignoreMe2 = "ignoreMe2";
150
+ model.fooBase = "fooBase";
151
+ model.ignoreMeBase = "ignoreMeBase";
152
+
153
+ return model;
154
+ }
155
+
156
+ @Get("/scenario11")
157
+ testScenario11() {
158
+ const t = new EmptyModel();
159
+
160
+ t.raw = 1;
161
+ t.affected = 1;
162
+
163
+ return t;
164
+ }
165
+
166
+ @Get("/scenario12")
167
+ testScenario12(@Res() res: PlatformResponse) {
168
+ res.attachment("filename");
169
+
170
+ return Buffer.from("Hello");
171
+ }
172
+
173
+ @Get("/scenario13")
174
+ async testScenario13(@Res() res: PlatformResponse) {
175
+ const http = agent();
176
+
177
+ const image_res = await http.get("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
178
+
179
+ res.setHeader("Content-Disposition", "inline;filename=googlelogo_color_272x92dp.png;");
180
+ res.setHeader("X-Content-Type-Options", "nosniff");
181
+ res.setHeader("Content-Type", "image/png");
182
+
183
+ return image_res.body;
184
+ }
185
+
186
+ @Get("/scenario14")
187
+ public scenario14() {
188
+ return {
189
+ jsonexample: 1
190
+ };
191
+ }
192
+
193
+ @Get("/scenario15a")
194
+ testScenario15a() {
195
+ return axios.get(`https://tsed.io/api.json`, {
196
+ responseType: "json"
197
+ });
198
+ }
199
+
200
+ @Get("/scenario15b")
201
+ testScenario15b() {
202
+ return axios.get(`https://api.tsed.io/rest/github/typed/test`, {
203
+ responseType: "json"
204
+ });
205
+ }
206
+
207
+ @Get("/scenario16")
208
+ testScenario16(): Promise<TestNestedEnum> {
209
+ const test = new TestNestedEnum();
210
+ const nested = new NestedEnum();
211
+ nested.value = EnumValue.One;
212
+ test.nested = nested;
213
+
214
+ return Promise.resolve(test);
215
+ }
216
+
217
+ @Get("/scenario17")
218
+ @(Returns(201, ModelGroup).Groups("creation"))
219
+ testScenario17(): Promise<ModelGroup> {
220
+ const model = new ModelGroup();
221
+ model.id = "id";
222
+ model.groups = "groups";
223
+
224
+ return Promise.resolve(model);
225
+ }
226
+
227
+ @Get("/scenario18")
228
+ @Returns(200, TeamsModel)
229
+ testScenario18() {
230
+ const data = new TeamsModel();
231
+ const team: any = {};
232
+ team.name = "name";
233
+ data.teams = [team];
234
+
235
+ return data;
236
+ }
237
+
238
+ @Get("/scenario19")
239
+ @(Returns(200, AllowedModel).Groups("!admin").AllowedGroups("summary", "details"))
240
+ testScenario19(): Promise<AllowedModel> {
241
+ const model = new AllowedModel();
242
+ model.id = "id";
243
+ model.prop1 = "prop1";
244
+ model.description = "description";
245
+ model.prop2 = "prop2";
246
+ model.sensitiveProp = "sensitiveProp";
247
+
248
+ return Promise.resolve(model);
249
+ }
250
+
251
+ @Get("/scenario20")
252
+ testScenario20() {
253
+ const $ctx = getContext();
254
+
255
+ return {id: $ctx?.request.query.id};
256
+ }
257
+ }
258
+
259
+ export function testResponse(options: PlatformTestingSdkOpts) {
260
+ let request: SuperTest.Agent;
261
+
262
+ beforeAll(
263
+ PlatformTest.bootstrap(options.server, {
264
+ ...options,
265
+ mount: {
266
+ "/rest": [TestResponseParamsCtrl]
267
+ }
268
+ })
269
+ );
270
+ beforeAll(() => {
271
+ request = SuperTest(PlatformTest.callback());
272
+ });
273
+ afterAll(PlatformTest.reset);
274
+
275
+ describe("Scenario1: return the id (classic)", () => {
276
+ describe("GET /rest/response/scenario1/:id", () => {
277
+ it("should return the id + test", async () => {
278
+ const response = await request.get("/rest/response/scenario1/10").expect(200);
279
+
280
+ expect(response.text).toEqual("hello-10");
281
+ });
282
+ });
283
+ });
284
+
285
+ describe("Scenario3: when response is empty or created", () => {
286
+ describe("GET /rest/response/scenario3/:id?", () => {
287
+ it("should return nothing with a 204 status", async () => {
288
+ const response = await request.post("/rest/response/scenario3/10").expect(204);
289
+
290
+ expect(response.text).toEqual("");
291
+ });
292
+
293
+ it("should return a body", async () => {
294
+ const response = await request.post("/rest/response/scenario3").expect(201);
295
+
296
+ expect(response.body).toEqual({id: 1});
297
+ });
298
+ });
299
+ });
300
+
301
+ describe("Scenario5: when endpoint response from promise", () => {
302
+ describe("GET /rest/response/scenario5", () => {
303
+ it("should return a body", async () => {
304
+ const response = await request.get("/rest/response/scenario5");
305
+
306
+ expect(response.body).toEqual({id: 1});
307
+ });
308
+ });
309
+ });
310
+
311
+ describe("Scenario6: when endpoint return an observable", () => {
312
+ describe("GET /rest/response/scenario6", () => {
313
+ it("should return a body", async () => {
314
+ const response = await request.get("/rest/response/scenario6");
315
+
316
+ expect(response.body).toEqual({id: 1});
317
+ });
318
+ });
319
+
320
+ describe("GET /rest/response/scenario6b", () => {
321
+ it("should return a body", async () => {
322
+ const response = await request.get("/rest/response/scenario6b");
323
+
324
+ expect(response.body).toEqual({id: 1});
325
+ });
326
+ });
327
+ });
328
+
329
+ describe("Scenario9: routes without parameters must be defined first", () => {
330
+ describe("GET /rest/response/scenario9/static", () => {
331
+ it("should return the test", async () => {
332
+ const response = await request.get("/rest/response/scenario9/static").expect(200);
333
+
334
+ expect(response.text).toEqual("value");
335
+ });
336
+ });
337
+
338
+ describe("GET /rest/response/scenario9/:dynamic", () => {
339
+ it("should return the test + id", async () => {
340
+ const response = await request.get("/rest/response/scenario9/10").expect(200);
341
+
342
+ expect(response.text).toEqual("value10");
343
+ });
344
+ });
345
+
346
+ describe("GET /rest/response/scenario9/:dynamic", () => {
347
+ it("should throw a badRequest when path params isn't set as number", async () => {
348
+ const response = await request.get("/rest/response/scenario9/kkk").expect(400);
349
+
350
+ expect(response.body).toEqual({
351
+ errors: [
352
+ {
353
+ data: "kkk",
354
+ requestPath: "path",
355
+ dataPath: ".id",
356
+ instancePath: "",
357
+ keyword: "type",
358
+ message: "must be number",
359
+ params: {
360
+ type: "number"
361
+ },
362
+ schemaPath: "#/type"
363
+ }
364
+ ],
365
+ message: 'Bad request on parameter "request.path.id".\nValue must be number. Given value: "kkk"',
366
+ name: "AJV_VALIDATION_ERROR",
367
+ status: 400
368
+ });
369
+ });
370
+ });
371
+ });
372
+
373
+ describe("Scenario10: return a model with ignored props", () => {
374
+ it("should return a body", async () => {
375
+ const response = await request.get("/rest/response/scenario10");
376
+
377
+ expect(response.body).toEqual({
378
+ foo: "foo",
379
+ fooBase: "fooBase"
380
+ });
381
+ });
382
+ });
383
+
384
+ describe("Scenario11: return models without props", () => {
385
+ it("should return a body", async () => {
386
+ const response = await request.get("/rest/response/scenario11");
387
+
388
+ expect(response.body).toEqual({
389
+ affected: 1,
390
+ raw: 1
391
+ });
392
+ });
393
+ });
394
+
395
+ describe("Scenario12: Return buffer", () => {
396
+ it("should return a body", async () => {
397
+ const response = await request.get("/rest/response/scenario12");
398
+
399
+ expect(response.headers["content-disposition"]).toEqual('attachment; filename="filename"');
400
+ expect(response.headers["content-type"]).toContain("application/octet-stream");
401
+ expect(response.headers["content-length"]).toEqual("5");
402
+ expect(response.body.toString()).toEqual("Hello");
403
+ });
404
+ });
405
+
406
+ describe("Scenario13: Return buffer", () => {
407
+ it("should return image", async () => {
408
+ const response = await request.get("/rest/response/scenario13");
409
+
410
+ expect(response.headers["content-disposition"]).toEqual("inline;filename=googlelogo_color_272x92dp.png;");
411
+ expect(response.headers["content-type"]).toContain("image/png");
412
+ expect(response.headers["content-length"]).toEqual("5969");
413
+ });
414
+ });
415
+
416
+ describe("Scenario14: Return application/json when Accept is */*", () => {
417
+ it("should return a */* content-type", async () => {
418
+ const response = await request
419
+ .get("/rest/response/scenario14")
420
+ .set("Accept", "*/*")
421
+ .set("Content-Type", "application/json")
422
+ .expect(200);
423
+
424
+ expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
425
+ expect(response.body).toEqual({
426
+ jsonexample: 1
427
+ });
428
+ });
429
+ });
430
+ describe("Scenario15: Use axios as proxy", () => {
431
+ it("should return the response (200)", async () => {
432
+ const response = await request.get("/rest/response/scenario15a").expect(200);
433
+
434
+ expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
435
+ });
436
+
437
+ it("should return the response (401)", async () => {
438
+ const response = await request.get("/rest/response/scenario15b").expect(401);
439
+
440
+ expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
441
+ });
442
+ });
443
+
444
+ describe("Scenario16: Return response with nested enum", () => {
445
+ it("should return the response (200)", async () => {
446
+ const response = await request.get("/rest/response/scenario16").expect(200);
447
+
448
+ expect(response.body).toEqual({nested: {value: "one"}});
449
+ });
450
+ });
451
+
452
+ describe("Scenario17: Return response with groups on 201", () => {
453
+ it("should return the response (200)", async () => {
454
+ const response = await request.get("/rest/response/scenario17").expect(201);
455
+
456
+ expect(response.body).toEqual({id: "id"});
457
+ });
458
+ });
459
+
460
+ describe("Scenario18: Return data with alias", () => {
461
+ it("should return the response (200)", async () => {
462
+ const response = await request.get("/rest/response/scenario18").expect(200);
463
+
464
+ expect(response.body).toEqual({
465
+ teams: [
466
+ {
467
+ teamName: "name"
468
+ }
469
+ ]
470
+ });
471
+ });
472
+ });
473
+
474
+ describe("Scenario19: includes options", () => {
475
+ it("should return the response (200)", async () => {
476
+ const response = await request.get("/rest/response/scenario19").expect(200);
477
+
478
+ expect(response.body).toEqual({
479
+ description: "description",
480
+ id: "id",
481
+ prop1: "prop1",
482
+ prop2: "prop2"
483
+ });
484
+ });
485
+ it("should return the response (200 + [summary])", async () => {
486
+ const response = await request.get("/rest/response/scenario19?includes=summary").expect(200);
487
+
488
+ expect(response.body).toEqual({
489
+ description: "description",
490
+ id: "id",
491
+ prop1: "prop1"
492
+ });
493
+ });
494
+ it("should return the response (200 + [summary, details])", async () => {
495
+ const response = await request.get("/rest/response/scenario19?includes=summary&includes=details").expect(200);
496
+
497
+ expect(response.body).toEqual({
498
+ description: "description",
499
+ id: "id",
500
+ prop2: "prop2",
501
+ prop1: "prop1"
502
+ });
503
+ });
504
+ it("should return the response (200 + [summary, details, admin])", async () => {
505
+ const response = await request.get("/rest/response/scenario19?includes=summary&includes=details&includes=admin").expect(200);
506
+
507
+ expect(response.body).toEqual({
508
+ description: "description",
509
+ id: "id",
510
+ prop2: "prop2",
511
+ prop1: "prop1"
512
+ });
513
+ });
514
+ it("should return the response (200 + 'summary,details,admin')", async () => {
515
+ const response = await request.get("/rest/response/scenario19?includes=summary,details,admin").expect(200);
516
+
517
+ expect(response.body).toEqual({
518
+ description: "description",
519
+ id: "id",
520
+ prop2: "prop2",
521
+ prop1: "prop1"
522
+ });
523
+ });
524
+ });
525
+
526
+ describe("Scenario20: should return query data from Context", () => {
527
+ it("should return the response (200)", async () => {
528
+ const response = await request.get("/rest/response/scenario20?id=id").expect(200);
529
+
530
+ expect(response.body).toEqual({id: "id"});
531
+ });
532
+ });
533
+ }
@@ -0,0 +1,106 @@
1
+ import {Controller} from "@tsed/di";
2
+ import {PlatformContext} from "@tsed/platform-http";
3
+ import {PlatformTest} from "@tsed/platform-http/testing";
4
+ import {ResponseFilter} from "@tsed/platform-response-filter";
5
+ import {Get, Property, Returns} from "@tsed/schema";
6
+ import SuperTest from "supertest";
7
+ import {afterAll, beforeAll, describe, expect, it} from "vitest";
8
+
9
+ import {PlatformTestingSdkOpts} from "../interfaces/index.js";
10
+
11
+ class ResponseFilterModel {
12
+ @Property()
13
+ id: string;
14
+ }
15
+
16
+ @Controller("/response-filter")
17
+ class TestResponseFilterCtrl {
18
+ @Get("/scenario1/:id")
19
+ @(Returns(200, ResponseFilterModel).Description("description"))
20
+ @(Returns(200, String).ContentType("text/xml"))
21
+ public testScenario1() {
22
+ return {id: "id"};
23
+ }
24
+ }
25
+
26
+ @ResponseFilter("text/xml")
27
+ class XmlResponseFilter {
28
+ transform(data: unknown, ctx: PlatformContext) {
29
+ return "<xml>test</xml>";
30
+ }
31
+ }
32
+
33
+ @ResponseFilter("*/*")
34
+ class AnyResponseFilter {
35
+ transform(data: unknown, ctx: PlatformContext) {
36
+ return {data, errors: []};
37
+ }
38
+ }
39
+
40
+ export function testResponseFilter(options: PlatformTestingSdkOpts) {
41
+ let request: SuperTest.Agent;
42
+
43
+ beforeAll(
44
+ PlatformTest.bootstrap(options.server, {
45
+ ...options,
46
+ mount: {
47
+ "/rest": [TestResponseFilterCtrl]
48
+ },
49
+ responseFilters: [XmlResponseFilter, AnyResponseFilter] as never[]
50
+ })
51
+ );
52
+ beforeAll(() => {
53
+ request = SuperTest(PlatformTest.callback());
54
+ });
55
+ afterAll(PlatformTest.reset);
56
+
57
+ describe("Scenario1: when have multiple contentType", () => {
58
+ describe("GET /rest/response/scenario1/:id", () => {
59
+ it("should return the xml format", async () => {
60
+ const response = await request
61
+ .get("/rest/response-filter/scenario1/10")
62
+ .set({
63
+ Accept: "text/xml"
64
+ })
65
+ .expect(200);
66
+
67
+ expect(response.text).toEqual("<xml>test</xml>");
68
+ });
69
+ it("should return the xml format when Accept text/xml and application/json", async () => {
70
+ const response = await request
71
+ .get("/rest/response-filter/scenario1/10")
72
+ .set({
73
+ Accept: "text/xml, application/json"
74
+ })
75
+ .expect(200);
76
+
77
+ expect(response.text).toEqual("<xml>test</xml>");
78
+ });
79
+ it("should return the json format", async () => {
80
+ const response = await request
81
+ .get("/rest/response-filter/scenario1/10")
82
+ .set({
83
+ Accept: "application/json"
84
+ })
85
+ .expect(200);
86
+
87
+ expect(response.body).toEqual({
88
+ data: {
89
+ id: "id"
90
+ },
91
+ errors: []
92
+ });
93
+ });
94
+ it("should return the json format by default", async () => {
95
+ const response = await request.get("/rest/response-filter/scenario1/10").expect(200);
96
+
97
+ expect(response.body).toEqual({
98
+ data: {
99
+ id: "id"
100
+ },
101
+ errors: []
102
+ });
103
+ });
104
+ });
105
+ });
106
+ }
@@ -0,0 +1,71 @@
1
+ import {Controller} from "@tsed/di";
2
+ import {PlatformTest} from "@tsed/platform-http/testing";
3
+ import {Get, Put} from "@tsed/schema";
4
+ import SuperTest from "supertest";
5
+ import {afterAll, afterEach, beforeAll, expect, it, vi} from "vitest";
6
+
7
+ import {PlatformTestingSdkOpts} from "../interfaces/index.js";
8
+
9
+ const stub = vi.fn();
10
+
11
+ @Controller("/routing")
12
+ export class TestRoutingController {
13
+ @Get("/1")
14
+ scenario1() {
15
+ stub("scenario1");
16
+
17
+ return "test1";
18
+ }
19
+
20
+ @Put("") // empty string has an effect on the calls orders
21
+ scenario2() {
22
+ stub("scenario2");
23
+
24
+ return "shouldNotRun";
25
+ }
26
+
27
+ @Get("/3")
28
+ scenario3() {
29
+ stub("scenario3");
30
+
31
+ return "test3";
32
+ }
33
+ }
34
+
35
+ export function testRouting(options: PlatformTestingSdkOpts) {
36
+ let request: SuperTest.Agent;
37
+
38
+ beforeAll(
39
+ PlatformTest.bootstrap(options.server, {
40
+ ...options,
41
+ mount: {
42
+ "/rest": [TestRoutingController]
43
+ }
44
+ })
45
+ );
46
+ beforeAll(() => {
47
+ request = SuperTest(PlatformTest.callback());
48
+ });
49
+ afterAll(PlatformTest.reset);
50
+ afterEach(() => {
51
+ vi.resetAllMocks();
52
+ });
53
+
54
+ it("Scenario1: should call scenario1 only", async () => {
55
+ const {text} = await request.get("/rest/routing/1").expect(200);
56
+ expect(text).toEqual("test1");
57
+ expect(stub).toHaveBeenCalledWith("scenario1");
58
+ });
59
+
60
+ it("Scenario2: should call scenario2 only", async () => {
61
+ const {text} = await request.put("/rest/routing/").expect(200);
62
+ expect(text).toEqual("shouldNotRun");
63
+ expect(stub).toHaveBeenCalledWith("scenario2");
64
+ });
65
+
66
+ it("Scenario3: should call scenario3 only", async () => {
67
+ const {text} = await request.get("/rest/routing/3").expect(200);
68
+ expect(text).toEqual("test3");
69
+ expect(stub).toHaveBeenCalledWith("scenario3");
70
+ });
71
+ }