@tsed/platform-test-sdk 8.7.0 → 8.7.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.
|
@@ -62,6 +62,12 @@ let TestMulterController = class TestMulterController {
|
|
|
62
62
|
file: media.originalname
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
uploadTwoFiles(media, media2) {
|
|
66
|
+
return {
|
|
67
|
+
file1: media.originalname,
|
|
68
|
+
file2: media2.originalname
|
|
69
|
+
};
|
|
70
|
+
}
|
|
65
71
|
};
|
|
66
72
|
__decorate([
|
|
67
73
|
Post("/scenario-1"),
|
|
@@ -92,13 +98,20 @@ __decorate([
|
|
|
92
98
|
__metadata("design:paramtypes", [Object]),
|
|
93
99
|
__metadata("design:returntype", void 0)
|
|
94
100
|
], TestMulterController.prototype, "uploadWithOptions", null);
|
|
101
|
+
__decorate([
|
|
102
|
+
Post("/scenario-4"),
|
|
103
|
+
Status(201),
|
|
104
|
+
__param(0, MultipartFile("media1")),
|
|
105
|
+
__param(1, MultipartFile("media2")),
|
|
106
|
+
__metadata("design:type", Function),
|
|
107
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
108
|
+
__metadata("design:returntype", void 0)
|
|
109
|
+
], TestMulterController.prototype, "uploadTwoFiles", null);
|
|
95
110
|
TestMulterController = __decorate([
|
|
96
111
|
Controller("/multer")
|
|
97
112
|
], TestMulterController);
|
|
98
113
|
export { TestMulterController };
|
|
99
114
|
export function testMulter(options) {
|
|
100
|
-
let request;
|
|
101
|
-
const buffer = Buffer.from("test content");
|
|
102
115
|
const pkg = readPkgUp.sync({
|
|
103
116
|
cwd: import.meta.dirname
|
|
104
117
|
});
|
|
@@ -109,19 +122,19 @@ export function testMulter(options) {
|
|
|
109
122
|
"/rest": [TestMulterController]
|
|
110
123
|
}
|
|
111
124
|
}));
|
|
112
|
-
beforeAll(() => {
|
|
113
|
-
request = SuperTest(PlatformTest.callback());
|
|
114
|
-
});
|
|
125
|
+
beforeAll(() => { });
|
|
115
126
|
afterAll(PlatformTest.reset);
|
|
116
127
|
beforeAll(() => {
|
|
117
128
|
vi.resetAllMocks();
|
|
118
129
|
});
|
|
119
130
|
describe("Scenario 1: POST /rest/multer/scenario-1", () => {
|
|
120
131
|
it("should upload file with multer", async () => {
|
|
132
|
+
const request = SuperTest(PlatformTest.callback());
|
|
121
133
|
const result = await request.post("/rest/multer/scenario-1").attach("media", `${rootDir}/data/file.txt`).expect(201);
|
|
122
134
|
expect(result.text).toEqual("file.txt");
|
|
123
135
|
});
|
|
124
136
|
it("should throw an exception when there is no file", async () => {
|
|
137
|
+
const request = SuperTest(PlatformTest.callback());
|
|
125
138
|
const result = await request.post("/rest/multer/scenario-1").expect(400);
|
|
126
139
|
expect(result.body).toEqual({
|
|
127
140
|
name: "REQUIRED_VALIDATION_ERROR",
|
|
@@ -143,6 +156,7 @@ export function testMulter(options) {
|
|
|
143
156
|
});
|
|
144
157
|
describe("Scenario 2: POST /rest/multer/scenario-2", () => {
|
|
145
158
|
it("should upload file with multer", async () => {
|
|
159
|
+
const request = SuperTest(PlatformTest.callback());
|
|
146
160
|
const result = await request
|
|
147
161
|
.post("/rest/multer/scenario-2")
|
|
148
162
|
.attach("media", `${rootDir}/data/file.txt`)
|
|
@@ -155,6 +169,7 @@ export function testMulter(options) {
|
|
|
155
169
|
});
|
|
156
170
|
describe("Scenario 3: POST /rest/multer/scenario-3", () => {
|
|
157
171
|
it("should upload file with multer", async () => {
|
|
172
|
+
const request = SuperTest(PlatformTest.callback());
|
|
158
173
|
const result = await request.post("/rest/multer/scenario-3").attach("media", `${rootDir}/data/file.txt`).field({}).expect(201);
|
|
159
174
|
expect(result.body).toEqual({
|
|
160
175
|
file: "file.txt"
|
|
@@ -163,5 +178,22 @@ export function testMulter(options) {
|
|
|
163
178
|
expect(fileFilterStub).toBeCalled();
|
|
164
179
|
});
|
|
165
180
|
});
|
|
181
|
+
describe("Scenario 4: POST /rest/multer/scenario-4", () => {
|
|
182
|
+
it("should upload two files using multer", async () => {
|
|
183
|
+
const request = SuperTest(PlatformTest.callback());
|
|
184
|
+
const result = await request
|
|
185
|
+
.post("/rest/multer/scenario-4")
|
|
186
|
+
.attach("media1", `${rootDir}/data/file.txt`)
|
|
187
|
+
.attach("media2", `${rootDir}/data/file.txt`)
|
|
188
|
+
.field({})
|
|
189
|
+
.expect(201);
|
|
190
|
+
expect(result.body).toEqual({
|
|
191
|
+
file1: "file.txt",
|
|
192
|
+
file2: "file.txt"
|
|
193
|
+
});
|
|
194
|
+
// filterFilter is called
|
|
195
|
+
expect(fileFilterStub).toBeCalled();
|
|
196
|
+
});
|
|
197
|
+
});
|
|
166
198
|
}
|
|
167
199
|
//# sourceMappingURL=testMulter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testMulter.js","sourceRoot":"","sources":["../../../src/tests/testMulter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAE,IAAI,EAAC,MAAM,WAAW,CAAC;AAExC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,aAAa,EAAE,aAAa,EAAqB,MAAM,qBAAqB,CAAC;AACrF,OAAO,EAAC,YAAY,EAAC,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAC,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,cAAc,CAAC;AAC5E,OAAO,MAA4B,MAAM,QAAQ,CAAC;AAClD,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAC,MAAM,QAAQ,CAAC;AAIrE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,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AAC,cAAc,CAAC,CAAC,UAAU,EAAE,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -17,5 +17,9 @@ export declare class TestMulterController {
|
|
|
17
17
|
uploadWithOptions(media: PlatformMulterFile): {
|
|
18
18
|
file: string;
|
|
19
19
|
};
|
|
20
|
+
uploadTwoFiles(media: PlatformMulterFile, media2: PlatformMulterFile): {
|
|
21
|
+
file1: string;
|
|
22
|
+
file2: string;
|
|
23
|
+
};
|
|
20
24
|
}
|
|
21
25
|
export declare function testMulter(options: PlatformTestingSdkOpts): void;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/platform-test-sdk",
|
|
3
3
|
"description": "Package to test platform adapter integration with Ts.ED",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.7.
|
|
5
|
+
"version": "8.7.2",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -28,25 +28,25 @@
|
|
|
28
28
|
"Adapter"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tsed/ajv": "8.7.
|
|
32
|
-
"@tsed/core": "8.7.
|
|
33
|
-
"@tsed/di": "8.7.
|
|
34
|
-
"@tsed/json-mapper": "8.7.
|
|
31
|
+
"@tsed/ajv": "8.7.2",
|
|
32
|
+
"@tsed/core": "8.7.2",
|
|
33
|
+
"@tsed/di": "8.7.2",
|
|
34
|
+
"@tsed/json-mapper": "8.7.2",
|
|
35
35
|
"@tsed/logger": "7.0.1",
|
|
36
|
-
"@tsed/platform-cache": "8.7.
|
|
37
|
-
"@tsed/platform-http": "8.7.
|
|
38
|
-
"@tsed/platform-params": "8.7.
|
|
39
|
-
"@tsed/platform-router": "8.7.
|
|
40
|
-
"@tsed/platform-views": "8.7.
|
|
41
|
-
"@tsed/schema": "8.7.
|
|
42
|
-
"@tsed/swagger": "8.7.
|
|
36
|
+
"@tsed/platform-cache": "8.7.2",
|
|
37
|
+
"@tsed/platform-http": "8.7.2",
|
|
38
|
+
"@tsed/platform-params": "8.7.2",
|
|
39
|
+
"@tsed/platform-router": "8.7.2",
|
|
40
|
+
"@tsed/platform-views": "8.7.2",
|
|
41
|
+
"@tsed/schema": "8.7.2",
|
|
42
|
+
"@tsed/swagger": "8.7.2",
|
|
43
43
|
"ajv": "^8.17.1",
|
|
44
44
|
"axios": "1.7.7",
|
|
45
45
|
"read-pkg-up": "7.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@tsed/barrels": "8.7.
|
|
49
|
-
"@tsed/typescript": "8.7.
|
|
48
|
+
"@tsed/barrels": "8.7.2",
|
|
49
|
+
"@tsed/typescript": "8.7.2",
|
|
50
50
|
"eslint": "9.12.0",
|
|
51
51
|
"typescript": "5.4.5"
|
|
52
52
|
},
|
package/src/tests/testMulter.ts
CHANGED
|
@@ -76,13 +76,18 @@ export class TestMulterController {
|
|
|
76
76
|
file: media.originalname
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
+
|
|
80
|
+
@Post("/scenario-4")
|
|
81
|
+
@Status(201)
|
|
82
|
+
uploadTwoFiles(@MultipartFile("media1") media: PlatformMulterFile, @MultipartFile("media2") media2: PlatformMulterFile) {
|
|
83
|
+
return {
|
|
84
|
+
file1: media.originalname,
|
|
85
|
+
file2: media2.originalname
|
|
86
|
+
};
|
|
87
|
+
}
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
export function testMulter(options: PlatformTestingSdkOpts) {
|
|
82
|
-
let request: SuperTest.Agent;
|
|
83
|
-
|
|
84
|
-
const buffer = Buffer.from("test content");
|
|
85
|
-
|
|
86
91
|
const pkg = readPkgUp.sync({
|
|
87
92
|
cwd: import.meta.dirname
|
|
88
93
|
});
|
|
@@ -96,21 +101,21 @@ export function testMulter(options: PlatformTestingSdkOpts) {
|
|
|
96
101
|
}
|
|
97
102
|
})
|
|
98
103
|
);
|
|
99
|
-
beforeAll(() => {
|
|
100
|
-
request = SuperTest(PlatformTest.callback());
|
|
101
|
-
});
|
|
104
|
+
beforeAll(() => {});
|
|
102
105
|
afterAll(PlatformTest.reset);
|
|
103
106
|
beforeAll(() => {
|
|
104
107
|
vi.resetAllMocks();
|
|
105
108
|
});
|
|
106
109
|
describe("Scenario 1: POST /rest/multer/scenario-1", () => {
|
|
107
110
|
it("should upload file with multer", async () => {
|
|
111
|
+
const request = SuperTest(PlatformTest.callback());
|
|
108
112
|
const result = await request.post("/rest/multer/scenario-1").attach("media", `${rootDir}/data/file.txt`).expect(201);
|
|
109
113
|
|
|
110
114
|
expect(result.text).toEqual("file.txt");
|
|
111
115
|
});
|
|
112
116
|
|
|
113
117
|
it("should throw an exception when there is no file", async () => {
|
|
118
|
+
const request = SuperTest(PlatformTest.callback());
|
|
114
119
|
const result = await request.post("/rest/multer/scenario-1").expect(400);
|
|
115
120
|
|
|
116
121
|
expect(result.body).toEqual({
|
|
@@ -133,6 +138,7 @@ export function testMulter(options: PlatformTestingSdkOpts) {
|
|
|
133
138
|
});
|
|
134
139
|
describe("Scenario 2: POST /rest/multer/scenario-2", () => {
|
|
135
140
|
it("should upload file with multer", async () => {
|
|
141
|
+
const request = SuperTest(PlatformTest.callback());
|
|
136
142
|
const result = await request
|
|
137
143
|
.post("/rest/multer/scenario-2")
|
|
138
144
|
.attach("media", `${rootDir}/data/file.txt`)
|
|
@@ -146,6 +152,7 @@ export function testMulter(options: PlatformTestingSdkOpts) {
|
|
|
146
152
|
});
|
|
147
153
|
describe("Scenario 3: POST /rest/multer/scenario-3", () => {
|
|
148
154
|
it("should upload file with multer", async () => {
|
|
155
|
+
const request = SuperTest(PlatformTest.callback());
|
|
149
156
|
const result = await request.post("/rest/multer/scenario-3").attach("media", `${rootDir}/data/file.txt`).field({}).expect(201);
|
|
150
157
|
|
|
151
158
|
expect(result.body).toEqual({
|
|
@@ -156,4 +163,24 @@ export function testMulter(options: PlatformTestingSdkOpts) {
|
|
|
156
163
|
expect(fileFilterStub).toBeCalled();
|
|
157
164
|
});
|
|
158
165
|
});
|
|
166
|
+
|
|
167
|
+
describe("Scenario 4: POST /rest/multer/scenario-4", () => {
|
|
168
|
+
it("should upload two files using multer", async () => {
|
|
169
|
+
const request = SuperTest(PlatformTest.callback());
|
|
170
|
+
const result = await request
|
|
171
|
+
.post("/rest/multer/scenario-4")
|
|
172
|
+
.attach("media1", `${rootDir}/data/file.txt`)
|
|
173
|
+
.attach("media2", `${rootDir}/data/file.txt`)
|
|
174
|
+
.field({})
|
|
175
|
+
.expect(201);
|
|
176
|
+
|
|
177
|
+
expect(result.body).toEqual({
|
|
178
|
+
file1: "file.txt",
|
|
179
|
+
file2: "file.txt"
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// filterFilter is called
|
|
183
|
+
expect(fileFilterStub).toBeCalled();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
159
186
|
}
|