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

Commit

Permalink
test: test API Blueprint with multipart/form-data
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Jul 30, 2018
1 parent 3c11b70 commit a6fd1a5
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/fixtures/api-blueprint/multipart-form-data.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FORMAT: 1A

# Sanbox 'multipart/form-data' API

# POST /data

+ Request (multipart/form-data; boundary=CUSTOM-BOUNDARY)

+ Body

--CUSTOM-BOUNDARY
Content-Disposition: form-data; name="text"
Content-Type: text/plain

test equals to 42
--CUSTOM-BOUNDARY
Content-Disposition: form-data; name="json"
Content-Type: application/json

{"test": 42}

--CUSTOM-BOUNDARY--

+ Response 200 (multipart/form-data; boundary=CUSTOM-BOUNDARY)

+ Body

--CUSTOM-BOUNDARY
Content-Disposition: form-data; name="text"
Content-Type: text/plain

test equals to 42
--CUSTOM-BOUNDARY
Content-Disposition: form-data; name="json"
Content-Type: application/json

{"test": 42}

--CUSTOM-BOUNDARY--
3 changes: 3 additions & 0 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ const fixtures = {
httpHeadersMultiple: fixture({
apiBlueprint: fromFile('./api-blueprint/http-headers-multiple.apib')
}),
multipartFormData: fixture({
apiBlueprint: fromFile('./api-blueprint/multipart-form-data.apib')
}),

// Specific to Swagger
produces: fixture({
Expand Down
48 changes: 48 additions & 0 deletions test/integration/compile-api-blueprint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,52 @@ describe('compile() · API Blueprint', () => {
);
});
});

describe('with \'multipart/form-data\' message bodies', () => {
let compilationResult;
const expectedBody = [
'--CUSTOM-BOUNDARY',
'Content-Disposition: form-data; name="text"',
'Content-Type: text/plain',
'',
'test equals to 42',
'--CUSTOM-BOUNDARY',
'Content-Disposition: form-data; name="json"',
'Content-Type: application/json',
'',
'{"test": 42}',
'',
'--CUSTOM-BOUNDARY--',
''
].join('\r\n');

before(done =>
compileFixture(fixtures.multipartFormData.apiBlueprint, (...args) => {
compilationResult = args[1];
done(args[0]);
})
);

it('produces no annotations and 1 transaction', () =>
assert.jsonSchema(compilationResult, createCompilationResultSchema({
annotations: 0,
transactions: 1
}))
);

context('the transaction', () => {
it('has the expected request body', () =>
assert.deepEqual(
compilationResult.transactions[0].request.body,
expectedBody
)
);
it('has the expected response body', () =>
assert.deepEqual(
compilationResult.transactions[0].response.body,
expectedBody
)
);
});
});
});

0 comments on commit a6fd1a5

Please sign in to comment.