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

Commit

Permalink
Fix oauth2 test
Browse files Browse the repository at this point in the history
This will need more testing against an actual oauth project
  • Loading branch information
Dom Harrington committed Oct 27, 2017
1 parent 2a4c308 commit 11b555a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
51 changes: 26 additions & 25 deletions packages/api-explorer-ui/__tests__/CodeSampleResponse.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Results body', () => {
});

test('should not display responseBody if isBinary is true', async () => {
const props2 = {
const binaryResponse = {
result: await parseResponse(
{
log: {
Expand All @@ -134,38 +134,39 @@ describe('Results body', () => {
),
operation: new Operation({}, '/pet', 'post'),
};
const codeSampleResponseTabs = shallow(<CodeSampleResponseTabs {...props2} oas={oas} />);
const codeSampleResponseTabs = shallow(
<CodeSampleResponseTabs {...binaryResponse} oas={oas} />,
);

expect(
codeSampleResponseTabs.containsMatchingElement(<div> A binary file was returned</div>),
codeSampleResponseTabs.containsMatchingElement(<div>A binary file was returned</div>),
).toEqual(true);
});

test('should display message if OAuth is incorrect or expired ', () => {
const props3 = {
result: {
method: 'POST',
requestHeaders: 'Authorization : Bearer api-key',
responseHeaders: 'content-disposition,application/json',
statusCode: [401, 'Unauthorized', 'error'],
responseBody: {
id: 9205436248879918000,
category: { id: 0 },
name: '1',
photoUrls: ['1'],
tags: [],
test('should display message if OAuth is incorrect or expired', async () => {
const oauthInvalidResponse = {
result: await parseResponse(
{
log: {
entries: [
{
request: { url: 'http://petstore.swagger.io/v2/pet', method: 'POST', headers: [] },
},
],
},
},
url: 'http://petstore.swagger.io/v2/pet',
},
operation: new Operation({}, '/pet', 'post'),
new Response('{}', {
headers: { 'content-disposition': 'attachment' },
status: 401,
}),
),
operation: oas.operation('/pet', 'post'),
};
const codeSampleResponseTabs = shallow(<CodeSampleResponseTabs {...props3} oas={oas} />);
const codeSampleResponseTabs = shallow(
<CodeSampleResponseTabs {...oauthInvalidResponse} oas={oas} />,
);

expect(
codeSampleResponseTabs.containsMatchingElement(
<div className="text-center hub-expired-token" />,
),
).toEqual(true);
expect(codeSampleResponseTabs.find('.hub-expired-token').length).toEqual(1);
});
});

Expand Down
9 changes: 3 additions & 6 deletions packages/api-explorer-ui/src/CodeSampleResponse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class CodeSampleResponse extends React.Component {

render() {
const { result, oas, operation } = this.props;
let allSecurities;
try {
allSecurities = operation.prepareSecurity();
} catch (e) {} // eslint-disable-line no-empty
let securities = operation.prepareSecurity();

return (
<div
Expand Down Expand Up @@ -131,9 +128,9 @@ class CodeSampleResponse extends React.Component {

{result.statusCode[0] === 401 && (
<div className="text-center hub-expired-token">
{allSecurities.OAuth2 ? (
{securities.OAuth2 ? (
() => {
if (allSecurities.OAuth2[0].flows.implicit.authorizationUrl) {
if (securities.OAuth2[0].flows.implicit.authorizationUrl) {
return (
<div>
<p>Your OAuth2 token has expired</p>
Expand Down

0 comments on commit 11b555a

Please sign in to comment.