Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit a6fd1a5

Browse files
committed
test: test API Blueprint with multipart/form-data
apiaryio/api-blueprint#401
1 parent 3c11b70 commit a6fd1a5

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FORMAT: 1A
2+
3+
# Sanbox 'multipart/form-data' API
4+
5+
# POST /data
6+
7+
+ Request (multipart/form-data; boundary=CUSTOM-BOUNDARY)
8+
9+
+ Body
10+
11+
--CUSTOM-BOUNDARY
12+
Content-Disposition: form-data; name="text"
13+
Content-Type: text/plain
14+
15+
test equals to 42
16+
--CUSTOM-BOUNDARY
17+
Content-Disposition: form-data; name="json"
18+
Content-Type: application/json
19+
20+
{"test": 42}
21+
22+
--CUSTOM-BOUNDARY--
23+
24+
+ Response 200 (multipart/form-data; boundary=CUSTOM-BOUNDARY)
25+
26+
+ Body
27+
28+
--CUSTOM-BOUNDARY
29+
Content-Disposition: form-data; name="text"
30+
Content-Type: text/plain
31+
32+
test equals to 42
33+
--CUSTOM-BOUNDARY
34+
Content-Disposition: form-data; name="json"
35+
Content-Type: application/json
36+
37+
{"test": 42}
38+
39+
--CUSTOM-BOUNDARY--

test/fixtures/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ const fixtures = {
165165
httpHeadersMultiple: fixture({
166166
apiBlueprint: fromFile('./api-blueprint/http-headers-multiple.apib')
167167
}),
168+
multipartFormData: fixture({
169+
apiBlueprint: fromFile('./api-blueprint/multipart-form-data.apib')
170+
}),
168171

169172
// Specific to Swagger
170173
produces: fixture({

test/integration/compile-api-blueprint-test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,52 @@ describe('compile() · API Blueprint', () => {
303303
);
304304
});
305305
});
306+
307+
describe('with \'multipart/form-data\' message bodies', () => {
308+
let compilationResult;
309+
const expectedBody = [
310+
'--CUSTOM-BOUNDARY',
311+
'Content-Disposition: form-data; name="text"',
312+
'Content-Type: text/plain',
313+
'',
314+
'test equals to 42',
315+
'--CUSTOM-BOUNDARY',
316+
'Content-Disposition: form-data; name="json"',
317+
'Content-Type: application/json',
318+
'',
319+
'{"test": 42}',
320+
'',
321+
'--CUSTOM-BOUNDARY--',
322+
''
323+
].join('\r\n');
324+
325+
before(done =>
326+
compileFixture(fixtures.multipartFormData.apiBlueprint, (...args) => {
327+
compilationResult = args[1];
328+
done(args[0]);
329+
})
330+
);
331+
332+
it('produces no annotations and 1 transaction', () =>
333+
assert.jsonSchema(compilationResult, createCompilationResultSchema({
334+
annotations: 0,
335+
transactions: 1
336+
}))
337+
);
338+
339+
context('the transaction', () => {
340+
it('has the expected request body', () =>
341+
assert.deepEqual(
342+
compilationResult.transactions[0].request.body,
343+
expectedBody
344+
)
345+
);
346+
it('has the expected response body', () =>
347+
assert.deepEqual(
348+
compilationResult.transactions[0].response.body,
349+
expectedBody
350+
)
351+
);
352+
});
353+
});
306354
});

0 commit comments

Comments
 (0)