Skip to content

Commit

Permalink
Fix empty response body (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood authored Oct 7, 2021
1 parent c4c6e05 commit 9be6355
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
19 changes: 17 additions & 2 deletions packages/api-explorer/__tests__/ResponseBody.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe('Response body', () => {
}}
oas={oas}
/></IntlProvider>);

const result = responseBody.find(Result);

expect(result).toHaveLength(1);
Expand All @@ -198,7 +198,7 @@ describe('Response body', () => {
}}
oas={oas}
/></IntlProvider>);

expect(responseBody.find(Result)).toHaveLength(0);
});

Expand Down Expand Up @@ -230,6 +230,21 @@ describe('Response body', () => {
expect(responseBody.find(Result)).toHaveLength(0);
});

test('should not display Result if result.responseBody is empty', () => {
const responseBody = mount(<IntlProvider><ResponseBody
operation={oas.operation('/pet', 'post')}
isOauth
oauth={false}
result={{
status: 401,
responseBody: ''
}}
oas={oas}
/></IntlProvider>);

expect(responseBody.find(Result)).toHaveLength(0);
});

test('should display message if OAuth is expired with oauth', () => {
const responseBody = mount(<IntlProvider><ResponseBody {...oauthInvalidResponse} oas={oas} oauth /></IntlProvider>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ Unauthorized.defaultProps = {
isOauth: false,
};

const noBodyValues = [undefined, null, '']

// eslint-disable-next-line react/prop-types
function ResponseBody({ result, isOauth, oauth, isCollapsed}) {
const { status, responseBody } = result;
const hasNoBody = noBodyValues.includes(responseBody)
return (
<div style={{ display: 'block', color: '#fff'}}>
{status === 401 && <Unauthorized isOauth={isOauth} oauth={oauth} />}
{responseBody !== undefined && responseBody !== null ?
<Result result={result} isCollapse={isCollapsed} /> :
renderPlainText('response.noBody', 'The response has no body')
{ hasNoBody ?
renderPlainText('response.noBody', 'The response has no body') :
<Result result={result} isCollapse={isCollapsed} />
}
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions packages/api-explorer/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ module.exports = {
resolve: {
extensions: ['.js', '.json', '.jsx'],
},
node: {
fs: "empty"
}
};

0 comments on commit 9be6355

Please sign in to comment.