Skip to content

Commit

Permalink
fix(services, router): remove unused auth header func
Browse files Browse the repository at this point in the history
* services config, clean up
* router, redirect route adjust
  • Loading branch information
cdcabrera committed Jul 30, 2019
1 parent 6402585 commit e4c2bb7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exports[`Router Component should render a basic component: basic 1`] = `
path="/rhel"
/>
<Redirect
from="/"
to="/rhel"
/>
</Switch>
Expand Down
2 changes: 1 addition & 1 deletion src/components/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Router extends React.Component {
}

if (item.redirect === true) {
redirectRoot = <Redirect from="/" to={item.to} />;
redirectRoot = <Redirect to={item.to} />;
}

return (
Expand Down
24 changes: 10 additions & 14 deletions src/services/__tests__/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ describe('ServiceConfig', () => {
});

it('should export a default services config', () => {
expect(service.serviceConfig).toBeDefined();
const configObject = service.serviceConfig();

const configObject = service.serviceConfig(
{
method: 'post',
timeout: 3
},
false
);

expect(configObject.method).toEqual('post');
expect(configObject.timeout).toEqual(3);
expect(Object.keys(configObject.headers).length).toBe(0);
expect(configObject.timeout).toBe(process.env.REACT_APP_AJAX_TIMEOUT);
});

it('should export a default services config without authorization', () => {
const configObject = service.serviceConfig({}, false);
it('should export a customized services config', () => {
const configObject = service.serviceConfig({
method: 'post',
timeout: 3
});

expect(configObject.headers[process.env.REACT_APP_AUTH_HEADER]).toBeUndefined();
expect(configObject.method).toBe('post');
expect(configObject.timeout).toBe(3);
});
});
16 changes: 2 additions & 14 deletions src/services/config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
const authHeader = () => {
const authToken = '';

if (authToken === '') {
return {};
}

return {
[process.env.REACT_APP_AUTH_HEADER]: process.env.REACT_APP_AUTH_HEADER_CONTENT.replace('{0}', ` ${authToken}`)
};
};

const serviceConfig = (passedConfig = {}, auth = false) =>
const serviceConfig = (passedConfig = {}) =>
Object.assign(
{
headers: auth ? authHeader() : {},
headers: {},
timeout: process.env.REACT_APP_AJAX_TIMEOUT
},
passedConfig
Expand Down

0 comments on commit e4c2bb7

Please sign in to comment.