feat: update Order History changed to Orders & Subscriptions

This commit is contained in:
Raza Dar
2023-06-15 01:47:06 +05:00
parent c458f4942f
commit 322a79afaa
9 changed files with 92 additions and 2 deletions

1
.env
View File

@@ -40,3 +40,4 @@ ACCOUNT_SETTINGS_URL=''
ACCOUNT_PROFILE_URL=''
ENABLE_NOTICES=''
CAREER_LINK_URL=''
ENABLE_B2C_SUBSCRIPTIONS=false

View File

@@ -47,3 +47,4 @@ ACCOUNT_SETTINGS_URL='http://localhost:1997'
ACCOUNT_PROFILE_URL='http://localhost:1995'
ENABLE_NOTICES=''
CAREER_LINK_URL=''
ENABLE_B2C_SUBSCRIPTIONS=false

View File

@@ -46,3 +46,4 @@ ACCOUNT_SETTINGS_URL='http://account-settings-url.test'
ACCOUNT_PROFILE_URL='http://account-profile-url.test'
ENABLE_NOTICES=''
CAREER_LINK_URL=''
ENABLE_B2C_SUBSCRIPTIONS=false

View File

@@ -16,6 +16,7 @@ const configuration = {
SUPPORT_URL: process.env.SUPPORT_URL || null,
ENABLE_NOTICES: process.env.ENABLE_NOTICES || null,
CAREER_LINK_URL: process.env.CAREER_LINK_URL || null,
ENABLE_B2C_SUBSCRIPTIONS: process.env.ENABLE_B2C_SUBSCRIPTIONS || null,
};
const features = {};

View File

@@ -11,6 +11,7 @@ import urls from 'data/services/lms/urls';
import { reduxHooks } from 'hooks';
import { findCoursesNavDropdownClicked } from '../hooks';
import { showOrdersAndSubscriptionsMenuItem } from '../utils';
import messages from '../messages';
@@ -80,7 +81,9 @@ export const CollapseMenuBody = ({ isOpen }) => {
variant="inverse-primary"
href={getConfig().ORDER_HISTORY_URL}
>
{formatMessage(messages.orderHistory)}
{ showOrdersAndSubscriptionsMenuItem()
? formatMessage(messages.ordersAndSubscriptions)
: formatMessage(messages.orderHistory)}
</Button>
)}
<Button

View File

@@ -8,6 +8,7 @@ import { AvatarButton, Dropdown, Badge } from '@edx/paragon';
import { reduxHooks } from 'hooks';
import messages from '../messages';
import { showOrdersAndSubscriptionsMenuItem } from '../utils';
export const AuthenticatedUserDropdown = () => {
const { formatMessage } = useIntl();
@@ -55,7 +56,9 @@ export const AuthenticatedUserDropdown = () => {
</Dropdown.Item>
{getConfig().ORDER_HISTORY_URL && (
<Dropdown.Item href={getConfig().ORDER_HISTORY_URL}>
{formatMessage(messages.orderHistory)}
{ showOrdersAndSubscriptionsMenuItem()
? formatMessage(messages.ordersAndSubscriptions)
: formatMessage(messages.orderHistory)}
</Dropdown.Item>
)}
<Dropdown.Divider />

View File

@@ -31,6 +31,11 @@ const messages = defineMessages({
defaultMessage: 'Order History',
description: 'The text for the user menu Order History navigation link.',
},
ordersAndSubscriptions: {
id: 'learnerVariantDashboard.menu.ordersAndSubscriptions.label',
defaultMessage: 'Orders & Subscriptions',
description: 'The text for the user menu Orders & Subscriptions navigation link.',
},
signOut: {
id: 'learnerVariantDashboard.menu.signOut.label',
defaultMessage: 'Sign Out',

View File

@@ -0,0 +1,13 @@
import { getConfig } from '@edx/frontend-platform';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
export const isEnterpriseUser = () => {
const authenticatedUser = getAuthenticatedUser();
const userRoleNames = authenticatedUser ? authenticatedUser.roles.map(role => role.split(':')[0]) : [];
return userRoleNames.includes('enterprise_learner');
};
export const showOrdersAndSubscriptionsMenuItem = () => (getConfig().ENABLE_B2C_SUBSCRIPTIONS?.toLowerCase() === 'true' && !isEnterpriseUser());
export default isEnterpriseUser;

View File

@@ -0,0 +1,62 @@
import { getConfig } from '@edx/frontend-platform';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import {
isEnterpriseUser,
showOrdersAndSubscriptionsMenuItem,
} from './utils';
jest.mock('@edx/frontend-platform/auth', () => ({
getAuthenticatedUser: jest.fn(),
}));
jest.mock('@edx/frontend-platform', () => ({
getConfig: jest.fn(),
}));
describe('isEnterpriseUser', () => {
beforeEach(() => {
getAuthenticatedUser.mockReset();
});
test('should return false if authenticatedUser is not enterprise user', () => {
getAuthenticatedUser.mockReturnValueOnce(null);
expect(isEnterpriseUser()).toBe(false);
getAuthenticatedUser.mockReturnValueOnce({ roles: [] });
expect(isEnterpriseUser()).toBe(false);
});
test('should return false if authenticatedUser roles do not include "enterprise_learner"', () => {
getAuthenticatedUser.mockReturnValueOnce({ roles: ['role1', 'role2', 'role3'] });
expect(isEnterpriseUser()).toBe(false);
});
test('should return true if authenticatedUser roles include "enterprise_learner"', () => {
getAuthenticatedUser.mockReturnValueOnce({
roles: ['role1', 'enterprise_learner:role2', 'role3'],
});
expect(isEnterpriseUser()).toBe(true);
});
});
describe('showOrdersAndSubscriptionsMenuItem', () => {
afterEach(() => {
getConfig.mockReset();
getAuthenticatedUser.mockReset();
});
test('should return true when ENABLE_B2C_SUBSCRIPTIONS is true and isEnterpriseUser returns false', () => {
getConfig.mockReturnValueOnce({
ENABLE_B2C_SUBSCRIPTIONS: 'true',
});
getAuthenticatedUser.mockReturnValueOnce({ roles: [] });
expect(showOrdersAndSubscriptionsMenuItem()).toBe(true);
});
test('should return false when ENABLE_B2C_SUBSCRIPTIONS is false and isEnterpriseUser returns false', () => {
getConfig.mockReturnValueOnce({
ENABLE_B2C_SUBSCRIPTIONS: 'false',
});
getAuthenticatedUser.mockReturnValueOnce({ roles: ['role1', 'role2', 'role3'] });
expect(showOrdersAndSubscriptionsMenuItem()).toBe(false);
});
});