Skip to content

Commit 33ab1a3

Browse files
committed
style: fix formatting
1 parent f1b0caa commit 33ab1a3

1 file changed

Lines changed: 80 additions & 80 deletions

File tree

test/multipart-ajv-file.test.js

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,121 @@
1-
"use strict";
1+
'use strict'
22

3-
const Fastify = require("fastify");
4-
const FormData = require("form-data");
5-
const http = require("node:http");
6-
const multipart = require("..");
7-
const { once } = require("node:events");
8-
const fs = require("node:fs");
9-
const path = require("node:path");
10-
const test = require("node:test");
3+
const Fastify = require('fastify')
4+
const FormData = require('form-data')
5+
const http = require('node:http')
6+
const multipart = require('..')
7+
const { once } = require('node:events')
8+
const fs = require('node:fs')
9+
const path = require('node:path')
10+
const test = require('node:test')
1111

12-
const filePath = path.join(__dirname, "../README.md");
12+
const filePath = path.join(__dirname, '../README.md')
1313

14-
test("show modify the generated schema", async (t) => {
15-
t.plan(6);
14+
test('show modify the generated schema', async (t) => {
15+
t.plan(6)
1616

1717
const fastify = Fastify({
1818
ajv: {
19-
plugins: [multipart.ajvFilePlugin],
20-
},
21-
});
19+
plugins: [multipart.ajvFilePlugin]
20+
}
21+
})
2222

23-
t.after(() => fastify.close());
23+
t.after(() => fastify.close())
2424

25-
await fastify.register(multipart, { attachFieldsToBody: true });
26-
await fastify.register(require("@fastify/swagger"), {
27-
mode: "dynamic",
25+
await fastify.register(multipart, { attachFieldsToBody: true })
26+
await fastify.register(require('@fastify/swagger'), {
27+
mode: 'dynamic',
2828

2929
openapi: {
30-
openapi: "3.1.0",
31-
},
32-
});
30+
openapi: '3.1.0'
31+
}
32+
})
3333

3434
fastify.post(
35-
"/",
35+
'/',
3636
{
3737
schema: {
38-
operationId: "test",
39-
consumes: ["multipart/form-data"],
38+
operationId: 'test',
39+
consumes: ['multipart/form-data'],
4040
body: {
41-
type: "object",
41+
type: 'object',
4242
properties: {
43-
field: { isFile: true },
44-
},
45-
},
46-
},
43+
field: { isFile: true }
44+
}
45+
}
46+
}
4747
},
4848
async function (_req, reply) {
49-
reply.code(200).send();
50-
},
51-
);
49+
reply.code(200).send()
50+
}
51+
)
5252

53-
await fastify.ready();
53+
await fastify.ready()
5454

55-
const post = fastify.swagger().paths["/"].post;
56-
t.assert.strictEqual(post.operationId, "test");
55+
const post = fastify.swagger().paths['/'].post
56+
t.assert.strictEqual(post.operationId, 'test')
5757
// requestBody.required is not asserted because @fastify/swagger v9.7.0
5858
// introduced it (fastify/fastify-swagger#903), making it version-dependent.
5959
t.assert.deepStrictEqual(post.requestBody.content, {
60-
"multipart/form-data": {
60+
'multipart/form-data': {
6161
schema: {
62-
type: "object",
62+
type: 'object',
6363
properties: {
64-
field: { type: "string", format: "binary" },
65-
},
66-
},
67-
},
68-
});
64+
field: { type: 'string', format: 'binary' }
65+
}
66+
}
67+
}
68+
})
6969
t.assert.deepStrictEqual(post.responses, {
70-
200: { description: "Default Response" },
71-
});
70+
200: { description: 'Default Response' }
71+
})
7272

73-
await fastify.listen({ port: 0 });
73+
await fastify.listen({ port: 0 })
7474

7575
// request without file
7676
{
77-
const form = new FormData();
77+
const form = new FormData()
7878
const req = http.request({
79-
protocol: "http:",
80-
hostname: "localhost",
79+
protocol: 'http:',
80+
hostname: 'localhost',
8181
port: fastify.server.address().port,
82-
path: "/",
82+
path: '/',
8383
headers: form.getHeaders(),
84-
method: "POST",
85-
});
86-
87-
form.append("field", JSON.stringify({}), {
88-
contentType: "application/json",
89-
});
90-
form.pipe(req);
91-
92-
const [res] = await once(req, "response");
93-
res.resume();
94-
await once(res, "end");
95-
t.assert.strictEqual(res.statusCode, 400); // body/field should be a file
84+
method: 'POST'
85+
})
86+
87+
form.append('field', JSON.stringify({}), {
88+
contentType: 'application/json'
89+
})
90+
form.pipe(req)
91+
92+
const [res] = await once(req, 'response')
93+
res.resume()
94+
await once(res, 'end')
95+
t.assert.strictEqual(res.statusCode, 400) // body/field should be a file
9696
}
9797

9898
// request with file
9999
{
100-
const form = new FormData();
100+
const form = new FormData()
101101
const req = http.request({
102-
protocol: "http:",
103-
hostname: "localhost",
102+
protocol: 'http:',
103+
hostname: 'localhost',
104104
port: fastify.server.address().port,
105-
path: "/",
105+
path: '/',
106106
headers: form.getHeaders(),
107-
method: "POST",
108-
});
109-
110-
form.append("field", fs.createReadStream(filePath), {
111-
contentType: "multipart/form-data",
112-
});
113-
form.pipe(req);
114-
115-
const [res] = await once(req, "response");
116-
res.resume();
117-
await once(res, "end");
118-
t.assert.strictEqual(res.statusCode, 200);
107+
method: 'POST'
108+
})
109+
110+
form.append('field', fs.createReadStream(filePath), {
111+
contentType: 'multipart/form-data'
112+
})
113+
form.pipe(req)
114+
115+
const [res] = await once(req, 'response')
116+
res.resume()
117+
await once(res, 'end')
118+
t.assert.strictEqual(res.statusCode, 200)
119119
}
120-
t.assert.ok("res ended successfully");
121-
});
120+
t.assert.ok('res ended successfully')
121+
})

0 commit comments

Comments
 (0)