Skip to content

Commit 42f3480

Browse files
authored
Merge pull request #106 from frouriojs/develop
release v1
2 parents b775cbf + a57c4d4 commit 42f3480

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1390
-1555
lines changed

__test__/index.spec.ts

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import aspida from '@aspida/axios';
33
import aspidaFetch from '@aspida/node-fetch';
44
import axios from 'axios';
5-
import { plainToInstance } from 'class-transformer';
6-
import { validateOrReject } from 'class-validator';
75
import express from 'express';
86
import FormData from 'form-data';
97
import fs from 'fs';
@@ -22,30 +20,13 @@ const client = api(aspida(undefined, { baseURL }));
2220
const fetchClient = api(aspidaFetch(undefined, { baseURL: subBaseURL, throwHttpErrors: true }));
2321
let server: Server;
2422
let subServer: Server;
25-
let subServerPlainToInstanceCallCount = 0;
26-
let subServerValidateOrRejectCallCount = 0;
2723

2824
beforeAll(cb => {
2925
server = frourio(express()).listen(port, () => {
30-
subServer = frourio(express(), {
31-
basePath: subBasePath,
32-
plainToInstance: (cls, object, options): object => {
33-
subServerPlainToInstanceCallCount++;
34-
return plainToInstance(cls, object, options);
35-
},
36-
validateOrReject: (instance, options): Promise<void> => {
37-
subServerValidateOrRejectCallCount++;
38-
return validateOrReject(instance, options);
39-
},
40-
}).listen(subPort, cb);
26+
subServer = frourio(express(), { basePath: subBasePath }).listen(subPort, cb);
4127
});
4228
});
4329

44-
beforeEach(() => {
45-
subServerPlainToInstanceCallCount = 0;
46-
subServerValidateOrRejectCallCount = 0;
47-
});
48-
4930
afterAll(cb => {
5031
rimraf.sync('servers/all/.upload');
5132
server.close(() => {
@@ -167,9 +148,6 @@ test('PUT: JSON', async () => {
167148
});
168149

169150
test('POST: formdata', async () => {
170-
expect(subServerPlainToInstanceCallCount).toBe(0);
171-
expect(subServerValidateOrRejectCallCount).toBe(0);
172-
173151
const port = '3000';
174152
const fileName = 'tsconfig.json';
175153

@@ -184,9 +162,6 @@ test('POST: formdata', async () => {
184162
expect(res1.data.port).toBe(port);
185163
expect(res1.data.fileName).toBe(fileName);
186164

187-
expect(subServerPlainToInstanceCallCount).toBe(0);
188-
expect(subServerValidateOrRejectCallCount).toBe(0);
189-
190165
const form2 = new FormData();
191166
const fileST2 = fs.createReadStream(fileName);
192167
form2.append('port', port);
@@ -197,10 +172,6 @@ test('POST: formdata', async () => {
197172
});
198173
expect(res2.data.port).toBe(port);
199174
expect(res2.data.fileName).toBe(fileName);
200-
201-
// 2 = query + body
202-
expect(subServerPlainToInstanceCallCount).toBe(2);
203-
expect(subServerValidateOrRejectCallCount).toBe(2);
204175
});
205176

206177
test('PUT: zod validations', async () => {
@@ -260,9 +231,7 @@ test('POST: multi file upload', async () => {
260231
form.append('icon', fileST);
261232
form.append('files', fileST);
262233
form.append('files', fileST);
263-
const res = await axios.post(`${baseURL}/multiForm`, form, {
264-
headers: form.getHeaders(),
265-
});
234+
const res = await axios.post(`${baseURL}/multiForm`, form, { headers: form.getHeaders() });
266235

267236
expect(res.data).toEqual({
268237
requiredArr: 0,
@@ -280,12 +249,10 @@ test('POST: 400', async () => {
280249
const fileST = fs.createReadStream(fileName);
281250
form.append('name', 'sample');
282251
form.append('vals', 'dammy');
283-
form.append('icon', fileST);
252+
form.append('files', fileST);
284253

285254
await expect(
286-
axios.post(`${baseURL}/multiForm`, form, {
287-
headers: form.getHeaders(),
288-
})
255+
axios.post(`${baseURL}/multiForm`, form, { headers: form.getHeaders() })
289256
).rejects.toHaveProperty('response.status', 400);
290257
});
291258

@@ -294,10 +261,7 @@ test('POST: nested validation', async () => {
294261
body: {
295262
id: 123,
296263
name: 'foo',
297-
location: {
298-
country: 'JP',
299-
stateProvince: 'Tokyo',
300-
},
264+
location: { country: 'JP', stateProvince: 'Tokyo' },
301265
},
302266
});
303267
expect(res1.status).toBe(204);
@@ -310,10 +274,7 @@ test('POST: nested validation', async () => {
310274
location: {
311275
country: 'JP',
312276
stateProvince: 'Tokyo',
313-
extra1: {
314-
extra1a: 'bar',
315-
extra1b: 'baz',
316-
},
277+
extra1: { extra1a: 'bar', extra1b: 'baz' },
317278
},
318279
extra2: 'qux',
319280
} as any,
@@ -328,10 +289,7 @@ test('POST: 400 (nested validation)', async () => {
328289
body: {
329290
id: '123',
330291
name: 'foo',
331-
location: {
332-
country: 'JP',
333-
stateProvince: 'Tokyo',
334-
},
292+
location: { country: 'JP', stateProvince: 'Tokyo' },
335293
} as any,
336294
})
337295
).rejects.toHaveProperty('response.status', 400);
@@ -349,10 +307,7 @@ test('POST: 400 (nested validation)', async () => {
349307
body: {
350308
id: 123,
351309
name: 'foo',
352-
location: {
353-
country: 'XX',
354-
stateProvince: 'Tokyo',
355-
},
310+
location: { country: 'JPN', stateProvince: 'Tokyo' },
356311
} as any,
357312
})
358313
).rejects.toHaveProperty('response.status', 400);
@@ -363,10 +318,7 @@ test('POST: 400 (nested validation)', async () => {
363318
body: {
364319
id: 123,
365320
name: 'foo',
366-
location: {
367-
country: 'JP',
368-
stateProvince: 1234,
369-
},
321+
location: { country: 'JP', stateProvince: 1234 },
370322
} as any,
371323
})
372324
).rejects.toHaveProperty('response.status', 400);
@@ -389,7 +341,7 @@ test('controller dependency injection', async () => {
389341
}))(express());
390342

391343
await expect(
392-
injectedController.get({
344+
injectedController.get.handler({
393345
query: {
394346
id,
395347
requiredNum: 1,

0 commit comments

Comments
 (0)