diff --git a/src/components/authentication/__tests__/__snapshots__/authentication.test.js.snap b/src/components/authentication/__tests__/__snapshots__/authentication.test.js.snap index 6fb0f2341..c38d29f16 100644 --- a/src/components/authentication/__tests__/__snapshots__/authentication.test.js.snap +++ b/src/components/authentication/__tests__/__snapshots__/authentication.test.js.snap @@ -1,12 +1,12 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Authorization Component should render a connected component: connected 1`] = ` +exports[`Authentication Component should render a connected component: connected 1`] = ` `; -exports[`Authorization Component should render a non-connected component authorized: non-connected authorized 1`] = ` +exports[`Authentication Component should render a non-connected component authorized: non-connected authorized 1`] = ` `; -exports[`Authorization Component should render a non-connected component error: non-connected error 1`] = ` +exports[`Authentication Component should render a non-connected component error: non-connected error 1`] = ` `; -exports[`Authorization Component should render a non-connected component pending: non-connected pending 1`] = ` +exports[`Authentication Component should render a non-connected component pending: non-connected pending 1`] = ` `; -exports[`Authorization Component should return a message on 401 error: 401 error 1`] = ` - - - - - - - - - Subscription Watch - - - - - - - - - - - - - - t(curiosity-auth.authorizedTitle, [object Object]) - - - - - - - - - - - - t(curiosity-auth.authorizedCopy, ...) - - - - - - - +exports[`Authentication Component should return a message on 401 error: 401 error 1`] = ` + `; -exports[`Authorization Component should return a redirect on 403 error: 403 error 1`] = `"403 redirect"`; +exports[`Authentication Component should return a redirect on 418 error: 418 error 1`] = `"418 redirect"`; + +exports[`Authentication Component should return a redirect on a specific 403 error and error code: 403 error 1`] = ` + +`; -exports[`Authorization Component should return a redirect on 418 error: 418 error 1`] = `"418 redirect"`; +exports[`Authentication Component should return a redirect on a specific 403 error and error code: 403 redirect error 1`] = `"403 redirect"`; diff --git a/src/components/authentication/__tests__/authentication.test.js b/src/components/authentication/__tests__/authentication.test.js index a9eae2a1f..d341f0103 100644 --- a/src/components/authentication/__tests__/authentication.test.js +++ b/src/components/authentication/__tests__/authentication.test.js @@ -1,11 +1,11 @@ import React from 'react'; import configureMockStore from 'redux-mock-store'; import { mount, shallow } from 'enzyme'; -import { BrowserRouter } from 'react-router-dom'; import { helpers } from '../../../common/helpers'; import { ConnectedAuthentication, Authentication } from '../authentication'; +import { rhsmApiTypes } from '../../../types'; -describe('Authorization Component', () => { +describe('Authentication Component', () => { const generateEmptyStore = (obj = {}) => configureMockStore()(obj); it('should render a connected component', () => { @@ -59,18 +59,16 @@ describe('Authorization Component', () => { pending: false } }; - const component = mount( - - - lorem - - + const component = shallow( + + lorem + ); expect(component.html()).toMatchSnapshot('418 error'); }); - it('should return a redirect on 403 error', () => { + it('should return a redirect on a specific 403 error and error code', () => { const props = { history: { listen: helpers.noop, @@ -80,19 +78,27 @@ describe('Authorization Component', () => { authorized: false, error: true, status: 403, + errorCodes: [rhsmApiTypes.RHSM_API_RESPONSE_ERROR_DATA_CODE_TYPES.OPTIN], errorMessage: `Forbidden`, pending: false } }; - const component = mount( - - - lorem - - + const component = shallow( + + lorem + ); - expect(component.html()).toMatchSnapshot('403 error'); + expect(component.html()).toMatchSnapshot('403 redirect error'); + + component.setProps({ + session: { + ...props.session, + errorCodes: [] + } + }); + + expect(component).toMatchSnapshot('403 error'); }); it('should return a message on 401 error', () => { @@ -106,15 +112,13 @@ describe('Authorization Component', () => { status: 401 } }; - const component = mount( - - - lorem - - + const component = shallow( + + lorem + ); - expect(component.find('PageLayout')).toMatchSnapshot('401 error'); + expect(component).toMatchSnapshot('401 error'); }); it('should render a non-connected component pending', () => { diff --git a/src/components/authentication/authentication.js b/src/components/authentication/authentication.js index 0cd2c69e0..cf4564213 100644 --- a/src/components/authentication/authentication.js +++ b/src/components/authentication/authentication.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { BinocularsIcon, LockIcon } from '@patternfly/react-icons'; import { connectRouterTranslate, reduxActions } from '../../redux'; +import { rhsmApiTypes } from '../../types'; import { helpers } from '../../common'; import { Redirect, routerHelpers, routerTypes } from '../router/router'; import MessageView from '../messageView/messageView'; @@ -58,7 +59,10 @@ class Authentication extends Component { return ; } - if (session.status === 403 || session.status === 418) { + if ( + (session.errorCodes && session.errorCodes.includes(rhsmApiTypes.RHSM_API_RESPONSE_ERROR_DATA_CODE_TYPES.OPTIN)) || + session.status === 418 + ) { if (helpers.TEST_MODE) { return {session.status} redirect; } @@ -95,6 +99,7 @@ Authentication.propTypes = { session: PropTypes.shape({ authorized: PropTypes.bool, error: PropTypes.bool, + errorCodes: PropTypes.arrayOf(PropTypes.string), errorMessage: PropTypes.string, pending: PropTypes.bool, status: PropTypes.number @@ -117,6 +122,7 @@ Authentication.defaultProps = { session: { authorized: false, error: false, + errorCodes: [], errorMessage: '', pending: false, status: null diff --git a/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap b/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap index 55e4a1551..b250976e6 100644 --- a/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap +++ b/src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap @@ -16,7 +16,7 @@ exports[`I18n Component should generate a predictable pot output snapshot: pot o msgstr \\"\\" \\"Content-Type: text/plain; charset=UTF-8\\\\n\\" -#: src/components/authentication/authentication.js:70 +#: src/components/authentication/authentication.js:74 msgid \\"curiosity-auth.authorizedTitle\\" msgstr \\"\\" @@ -209,12 +209,12 @@ msgstr \\"\\" msgid \\"curiosity-view.rhel\\" msgstr \\"\\" -#: src/components/authentication/authentication.js:71 +#: src/components/authentication/authentication.js:75 msgctxt \\"...\\" msgid \\"curiosity-auth.authorizedCopy\\" msgstr \\"\\" -#: src/components/authentication/authentication.js:58 +#: src/components/authentication/authentication.js:59 msgctxt \\"...\\" msgid \\"curiosity-auth.pending\\" msgstr \\"\\"