Skip to content

Commit

Permalink
fix: remove cookie (#1286)
Browse files Browse the repository at this point in the history
-remove marketingEmailsOptIn cookie on successful registration
- fix tests
  • Loading branch information
mubbsharanwar authored Jul 12, 2024
1 parent 3272101 commit 6b983e1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/common-components/RedirectLogistration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Navigate } from 'react-router-dom';
import {
AUTHN_PROGRESSIVE_PROFILING, RECOMMENDATIONS, REDIRECT,
} from '../data/constants';
import { setCookie } from '../data/utils';
import setCookie from '../data/utils/cookies';

const RedirectLogistration = (props) => {
const {
Expand Down
38 changes: 28 additions & 10 deletions src/common-components/tests/SocialAuthProviders.test.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import React from 'react';
import { Provider } from 'react-redux';

import { IntlProvider } from '@edx/frontend-platform/i18n';
import renderer from 'react-test-renderer';
import configureStore from 'redux-mock-store';

import registerIcons from '../RegisterFaIcons';
import SocialAuthProviders from '../SocialAuthProviders';

registerIcons();
const mockStore = configureStore();

describe('SocialAuthProviders', () => {
let props = {};

const initialState = {
register: {
registrationFormData: {
configurableFormFields: {
marketingEmailsOptIn: true,
},
},
},
};
const store = mockStore(initialState);
const reduxWrapper = children => (
<IntlProvider locale="en">
<Provider store={store}>{children}</Provider>
</IntlProvider>
);

const appleProvider = {
id: 'oa2-apple-id',
name: 'Apple',
Expand All @@ -27,20 +46,19 @@ describe('SocialAuthProviders', () => {
loginUrl: '/auth/login/facebook/?auth_entry=login&next=/dashboard',
};

// Skipped tests will be fixed later.
it.skip('should match social auth provider with iconImage snapshot', () => {
it('should match social auth provider with iconImage snapshot', () => {
props = { socialAuthProviders: [appleProvider, facebookProvider] };

const tree = renderer.create(
const tree = renderer.create(reduxWrapper(
<IntlProvider locale="en">
<SocialAuthProviders {...props} />
</IntlProvider>,
).toJSON();
)).toJSON();

expect(tree).toMatchSnapshot();
});

it.skip('should match social auth provider with iconClass snapshot', () => {
it('should match social auth provider with iconClass snapshot', () => {
props = {
socialAuthProviders: [{
...appleProvider,
Expand All @@ -49,16 +67,16 @@ describe('SocialAuthProviders', () => {
}],
};

const tree = renderer.create(
const tree = renderer.create(reduxWrapper(
<IntlProvider locale="en">
<SocialAuthProviders {...props} />
</IntlProvider>,
).toJSON();
)).toJSON();

expect(tree).toMatchSnapshot();
});

it.skip('should match social auth provider with default icon snapshot', () => {
it('should match social auth provider with default icon snapshot', () => {
props = {
socialAuthProviders: [{
...appleProvider,
Expand All @@ -67,11 +85,11 @@ describe('SocialAuthProviders', () => {
}],
};

const tree = renderer.create(
const tree = renderer.create(reduxWrapper(
<IntlProvider locale="en">
<SocialAuthProviders {...props} />
</IntlProvider>,
).toJSON();
)).toJSON();

expect(tree).toMatchSnapshot();
});
Expand Down
8 changes: 8 additions & 0 deletions src/data/utils/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ export default function setCookie(cookieName, cookieValue, cookieExpiry) {
cookies.set(cookieName, cookieValue, options);
}
}

export function removeCookie(cookieName) {
if (cookieName) {
const cookies = new Cookies();
const options = { domain: getConfig().SESSION_COOKIE_DOMAIN, path: '/' };
cookies.remove(cookieName, options);
}
}
2 changes: 1 addition & 1 deletion src/data/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export {
windowScrollTo,
} from './dataUtils';
export { default as AsyncActionType } from './reduxUtils';
export { default as setCookie } from './cookies';
export { default as setCookie, removeCookie } from './cookies';
5 changes: 4 additions & 1 deletion src/register/RegistrationPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
APP_NAME, COMPLETE_STATE, PENDING_STATE, REGISTER_PAGE,
} from '../data/constants';
import {
getAllPossibleQueryParams, getTpaHint, getTpaProvider, isHostAvailableInQueryParams, setCookie,
getAllPossibleQueryParams, getTpaHint, getTpaProvider, isHostAvailableInQueryParams, removeCookie, setCookie,
} from '../data/utils';
import { trackRegistrationPageViewed, trackRegistrationSuccess } from '../tracking/trackers/register';

Expand Down Expand Up @@ -187,6 +187,9 @@ const RegistrationPage = (props) => {

// This is used by the "User Retention Rate Event" on GTM
setCookie(getConfig().USER_RETENTION_COOKIE_NAME, true);

// remove marketingEmailsOptIn cookie that was set on SSO registration flow
removeCookie('marketingEmailsOptIn');
}
}, [registrationResult]);

Expand Down

0 comments on commit 6b983e1

Please sign in to comment.