Skip to content

Commit

Permalink
Make sure mimeType has the type from the operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Nov 13, 2017
1 parent bd27813 commit 918dfb7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
53 changes: 35 additions & 18 deletions packages/api-explorer-ui/__tests__/lib/oas-to-har.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,34 +288,51 @@ describe('header values', () => {
});
});

describe('body values', () => {
const pathOperation = {
path: '/body',
method: 'get',
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
properties: {
a: {
type: 'string',
},
const pathOperation = {
path: '/body',
method: 'get',
requestBody: {
content: {
'application/json': {
schema: {
type: 'object',
properties: {
a: {
type: 'string',
},
},
},
},
},
};
it('should not add on empty unrequired values', () => {
expect(oasToHar({}, pathOperation).log.entries[0].request.postData.text).toEqual(undefined);
});
it('should pass in mimeType', () => {
},
};

describe('mimeType', () => {
it('should default to application/json', () => {
expect(oasToHar({}, pathOperation).log.entries[0].request.postData.mimeType).toEqual(
'application/json',
);
});

it('should fetch mimeType from the operation', () => {
expect(
oasToHar(
{},
Object.assign({}, pathOperation, {
requestBody: {
content: { 'application/xml': pathOperation.requestBody.content['application/json'] },
},
}),
).log.entries[0].request.postData.mimeType,
).toEqual('application/xml');
});
});

describe('body values', () => {
it('should not add on empty unrequired values', () => {
expect(oasToHar({}, pathOperation).log.entries[0].request.postData.text).toEqual(undefined);
});

// TODO extensions[SEND_DEFAULTS]
it.skip('should set defaults if no value provided but is required', () => {
expect(
Expand Down
5 changes: 3 additions & 2 deletions packages/api-explorer-ui/src/lib/oas-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ module.exports = (
// Add content-type header if there are any body values setup above ^^
// or if there is a schema defined
if (har.postData.text || Object.keys(schema.schema).length) {
har.postData.mimeType = getContentType();
const type = getContentType(pathOperation);
har.postData.mimeType = type;
har.headers.push({
name: 'Content-Type',
value: getContentType(pathOperation),
value: type,
});
}

Expand Down

0 comments on commit 918dfb7

Please sign in to comment.