Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update learner credit plan cards to use subsidies #419

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ENTERPRISE_ACCESS_BASE_URL='http://localhost:18270'
LANGUAGE_PREFERENCE_COOKIE_NAME='openedx-language-preference'
LMS_BASE_URL='http://localhost:18000'
LICENSE_MANAGER_URL='http://localhost:18170'
LICENSE_MANAGER_DJANGO_URL='http://localhost:18170'
Comment on lines 17 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for a new LICENSE_MANAGER_DJANGO_URL variable if the value is the same as the existing LICENSE_MANAGER_URL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the LICENSE_MANAGER_URL variable is use for fetching subscriptions data and the LICENSE_MANAGER_DJANGO_URL is used as the django admin url. we ran into an issue with fetching the data when we used the same url. the fetching one should be license-manager.edx.org and the admin django screen is license-manager-internal.edx.org.

SUPPORT_CONFLUENCE='localhost:18450'
SUPPORT_CUSTOMER_REQUEST='localhost:18450'
DISCOVERY_API_BASE_URL='http://localhost:18381'
Expand All @@ -30,6 +31,7 @@ REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
SEGMENT_KEY=null
SITE_NAME='edX'
SUBSIDY_BASE_URL='http://localhost:18280'
SUBSIDY_BASE_DJANGO_URL='http://localhost:18280'
USER_INFO_COOKIE_NAME='edx-user-info'
PUBLISHER_BASE_URL='http://localhost:18400'
APP_ID='support-tools'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const SubscriptionCheckIcon = ({ row }) => {
return null;
};

const PolicyCheckIcon = ({ row }) => {
if (row.original.hasActivePolicies) {
const SubsidyCheckIcon = ({ row }) => {
if (row.original.hasActiveSubsidies) {
return <Icon src={Check} screenReaderText="policy check" />;
}
return null;
Expand Down Expand Up @@ -73,8 +73,8 @@ const CustomerDetailRowSubComponent = ({ row }) => {
},
{
Header: 'Learner Credit',
accessor: 'hasActivePolicies',
Cell: PolicyCheckIcon,
accessor: 'hasActiveSubsidies',
Cell: SubsidyCheckIcon,
},
{
Header: OtherSubsidies,
Expand Down Expand Up @@ -105,10 +105,10 @@ SubscriptionCheckIcon.propTypes = {
}).isRequired,
};

PolicyCheckIcon.propTypes = {
SubsidyCheckIcon.propTypes = {
row: PropTypes.shape({
original: PropTypes.shape({
hasActivePolicies: PropTypes.bool,
hasActiveSubsidies: PropTypes.bool,
}),
}).isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: true,
hasActivePolicies: true,
hasActiveSubsidies: true,
hasActiveOtherSubsidies: true,
},
});
Expand All @@ -53,7 +53,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: false,
hasActivePolicies: true,
hasActiveSubsidies: true,
hasActiveOtherSubsidies: true,
},
});
Expand All @@ -75,7 +75,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: true,
hasActivePolicies: false,
hasActiveSubsidies: false,
hasActiveOtherSubsidies: true,
},
});
Expand All @@ -97,7 +97,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: true,
hasActivePolicies: true,
hasActiveSubsidies: true,
hasActiveOtherSubsidies: false,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import SubscriptionPlanCard from './SubscriptionPlanCard';

const CustomerPlanContainer = ({
slug,
activePolicies,
activeSubsidies,
activeSubscriptions,
countOfActivePlans,
countOfAllPlans,
inactivePolicies,
inactiveSubsidies,
inactiveSubscriptions,
isLoading,
}) => {
Expand All @@ -20,11 +20,11 @@ const CustomerPlanContainer = ({
setShowInactive(true);
}
}, []);
const renderActivePoliciesCard = activePolicies.map(policy => (
<LearnerCreditPlanCard key={policy.uuid} isActive slug={slug} policy={policy} />
const renderActiveSubsidiesCard = activeSubsidies.map(subsidy => (
<LearnerCreditPlanCard key={subsidy.uuid} isActive slug={slug} subsidy={subsidy} />
));
const renderInactivePoliciesCard = inactivePolicies.map(policy => (
<LearnerCreditPlanCard key={policy.uuid} isActive={false} slug={slug} policy={policy} />
const renderInactiveSubsidiesCard = inactiveSubsidies.map(subsidy => (
<LearnerCreditPlanCard key={subsidy.uuid} isActive={false} slug={slug} subsidy={subsidy} />
));
const renderActiveSubscriptions = activeSubscriptions.map(subscription => (
<SubscriptionPlanCard key={subscription.uuid} isActive slug={slug} subscription={subscription} />
Expand Down Expand Up @@ -53,11 +53,11 @@ const CustomerPlanContainer = ({
) : null}
</div>
<hr />
{renderActivePoliciesCard}
{renderActiveSubsidiesCard}
{renderActiveSubscriptions}
{showInactive ? (
<div>
{renderInactivePoliciesCard}
{renderInactiveSubsidiesCard}
{renderInActiveSubscriptions}
</div>
) : null}
Expand All @@ -69,11 +69,10 @@ const CustomerPlanContainer = ({

CustomerPlanContainer.propTypes = {
slug: PropTypes.string.isRequired,
activePolicies: PropTypes.arrayOf(PropTypes.shape({
activeSubsidies: PropTypes.arrayOf(PropTypes.shape({
uuid: PropTypes.string.isRequired,
subsidyActiveDatetime: PropTypes.string.isRequired,
subsidyExpirationDatetime: PropTypes.string.isRequired,
policyType: PropTypes.string.isRequired,
activeDatetime: PropTypes.string.isRequired,
expirationDatetime: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
})).isRequired,
activeSubscriptions: PropTypes.arrayOf(PropTypes.shape({
Expand All @@ -84,11 +83,10 @@ CustomerPlanContainer.propTypes = {
})).isRequired,
countOfActivePlans: PropTypes.number.isRequired,
countOfAllPlans: PropTypes.number.isRequired,
inactivePolicies: PropTypes.arrayOf(PropTypes.shape({
inactiveSubsidies: PropTypes.arrayOf(PropTypes.shape({
uuid: PropTypes.string.isRequired,
subsidyActiveDatetime: PropTypes.string.isRequired,
subsidyExpirationDatetime: PropTypes.string.isRequired,
policyType: PropTypes.string.isRequired,
activeDatetime: PropTypes.string.isRequired,
expirationDatetime: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
})).isRequired,
inactiveSubscriptions: PropTypes.arrayOf(PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { Launch } from '@openedx/paragon/icons';
import { getConfig } from '@edx/frontend-platform';
import { formatDate } from '../data/utils';

const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {
const { ADMIN_PORTAL_BASE_URL, ENTERPRISE_ACCESS_BASE_URL } = getConfig();
const startDate = formatDate(policy.subsidyActiveDatetime);
const endDate = formatDate(policy.subsidyExpirationDatetime);
const createdDate = formatDate(policy.created);
const LearnerCreditPlanCard = ({ isActive, subsidy, slug }) => {
const { ADMIN_PORTAL_BASE_URL, SUBSIDY_BASE_DJANGO_URL } = getConfig();
const startDate = formatDate(subsidy.activeDatetime);
const endDate = formatDate(subsidy.expirationDatetime);
const createdDate = formatDate(subsidy.created);

return (
<Card className="mb-4">
Expand All @@ -25,7 +25,7 @@ const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {
<Button
data-testid="admin-portal-button"
as="a"
href={`${ADMIN_PORTAL_BASE_URL}/${slug}/admin/learner-credit/${policy.uuid}`}
href={`${ADMIN_PORTAL_BASE_URL}/${slug}/admin/learner-credit/`}
target="_blank"
rel="noopener noreferrer"
variant="inverse-primary"
Expand All @@ -34,7 +34,7 @@ const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {
<Button
data-testid="django-button"
as="a"
href={`${ENTERPRISE_ACCESS_BASE_URL}/admin/subsidy_access_policy/${policy.policyType.toLowerCase()}/${policy.uuid}`}
href={`${SUBSIDY_BASE_DJANGO_URL}/admin/subsidy/subsidy/${subsidy.uuid}/change/`}
variant="primary"
target="_blank"
rel="noopener noreferrer"
Expand All @@ -61,11 +61,10 @@ const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {

LearnerCreditPlanCard.propTypes = {
isActive: PropTypes.bool.isRequired,
policy: PropTypes.shape({
subsidy: PropTypes.shape({
uuid: PropTypes.string.isRequired,
subsidyActiveDatetime: PropTypes.string.isRequired,
subsidyExpirationDatetime: PropTypes.string.isRequired,
policyType: PropTypes.string.isRequired,
activeDatetime: PropTypes.string.isRequired,
expirationDatetime: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
}).isRequired,
slug: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getConfig } from '@edx/frontend-platform';
import { formatDate } from '../data/utils';

const SubscriptionPlanCard = ({ isActive, subscription, slug }) => {
const { ADMIN_PORTAL_BASE_URL, LICENSE_MANAGER_URL } = getConfig();
const { ADMIN_PORTAL_BASE_URL, LICENSE_MANAGER_DJANGO_URL } = getConfig();
const startDate = formatDate(subscription.startDate);
const endDate = formatDate(subscription.expirationDate);
const createdDate = formatDate(subscription.created);
Expand All @@ -31,7 +31,7 @@ const SubscriptionPlanCard = ({ isActive, subscription, slug }) => {
</Button>
<Button
as="a"
href={`${LICENSE_MANAGER_URL}/admin/subscriptions/subscriptionplan/${subscription.uuid}/change`}
href={`${LICENSE_MANAGER_DJANGO_URL}/admin/subscriptions/subscriptionplan/${subscription.uuid}/change`}
variant="primary"
target="_blank"
rel="noopener noreferrer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ describe('CustomerPlanContainer', () => {

getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
ENTERPRISE_ACCESS_BASE_URL: 'http:www.enterprise-access.com',
LICENSE_MANAGER_URL: 'http:www.license-manager.com',
SUBSIDY_BASE_DJANGO_URL: 'http:www.enterprise-subsidy.com',
LICENSE_MANAGER_DJANGO_URL: 'http:www.license-manager.com',
}));
const mockProps = {
isLoading: false,
activePolicies: [{
subsidyActiveDatetime: '2024-08-23T20:02:57.651943Z',
activeSubsidies: [{
activeDatetime: '2024-08-23T20:02:57.651943Z',
created: '2024-08-22T20:02:57.651943Z',
subsidyExpirationDatetime: '2024-08-24T20:02:57.651943Z',
expirationDatetime: '2024-08-24T20:02:57.651943Z',
uuid: 'test-uuid',
policyType: 'learnerCredit',
isSubsidyActive: true,
isActive: true,
}],
activeSubscriptions: [{
startDate: '2024-09-01T20:02:57.651943Z',
Expand All @@ -57,13 +56,12 @@ describe('CustomerPlanContainer', () => {
countOfActivePlans: 2,
countOfAllPlans: 3,
inactiveSubscriptions: [],
inactivePolicies: [{
subsidyActiveDatetime: '2024-08-23T20:02:57.651943Z',
inactiveSubsidies: [{
activeDatetime: '2024-08-23T20:02:57.651943Z',
created: '2024-08-23T20:02:57.651943Z',
subsidyExpirationDatetime: '2024-08-23T20:02:57.651943Z',
expirationDatetime: '2024-08-23T20:02:57.651943Z',
uuid: 'test-uuid',
policyType: 'learnerCredit',
isSubsidyActive: false,
isActive: false,
}],
};
render(
Expand All @@ -78,8 +76,8 @@ describe('CustomerPlanContainer', () => {
expect(screen.getByText('LEARNER CREDIT PLAN')).toBeInTheDocument();
expect(screen.getByText('Aug 23, 2024 - Aug 24, 2024')).toBeInTheDocument();
expect(screen.getByText('Created Aug 22, 2024')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-slug/admin/learner-credit/test-uuid');
expect(djangoLinks[0]).toHaveAttribute('href', 'http:www.enterprise-access.com/admin/subsidy_access_policy/learnercredit/test-uuid');
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-slug/admin/learner-credit/');
expect(djangoLinks[0]).toHaveAttribute('href', 'http:www.enterprise-subsidy.com/admin/subsidy/subsidy/test-uuid/change/');
// Subscription Plan
expect(screen.getByText('SUBSCRIPTION PLAN')).toBeInTheDocument();
expect(screen.getByText('Sep 1, 2024 - Sep 2, 2024')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ jest.mock('@edx/frontend-platform', () => ({

const mockData = {
isActive: true,
policy: {
subsidyActiveDatetime: '2024-08-23T20:02:57.651943Z',
subsidy: {
activeDatetime: '2024-08-23T20:02:57.651943Z',
created: '2024-08-23T20:02:57.651943Z',
subsidyExpirationDatetime: '2024-08-23T20:02:57.651943Z',
expirationDatetime: '2024-08-23T20:02:57.651943Z',
uuid: 'test-uuid',
policyType: 'learnerCredit',
},
slug: 'test-customer-slug',
};
Expand All @@ -32,7 +31,7 @@ describe('LearnerCreditPlanCard', () => {
formatDate.mockReturnValue('Aug 23, 2024');
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
ENTERPRISE_ACCESS_BASE_URL: 'http:www.enterprise-access.com',
SUBSIDY_BASE_DJANGO_URL: 'http://www.enterprise-subsidy.com',
}));
render(
<IntlProvider locale="en">
Expand All @@ -42,8 +41,8 @@ describe('LearnerCreditPlanCard', () => {
expect(screen.getByText('LEARNER CREDIT PLAN')).toBeInTheDocument();
expect(screen.getByText('Aug 23, 2024 - Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByText('Created Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/test-uuid');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http:www.enterprise-access.com/admin/subsidy_access_policy/learnercredit/test-uuid');
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http://www.enterprise-subsidy.com/admin/subsidy/subsidy/test-uuid/change/');
});

it('renders inactive LearnerCreditPlanCard data', () => {
Expand All @@ -54,7 +53,7 @@ describe('LearnerCreditPlanCard', () => {
formatDate.mockReturnValue('Aug 23, 2024');
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
ENTERPRISE_ACCESS_BASE_URL: 'http:www.enterprise-access.com',
SUBSIDY_BASE_DJANGO_URL: 'http://www.enterprise-subsidy.com',
}));
render(
<IntlProvider locale="en">
Expand All @@ -65,7 +64,7 @@ describe('LearnerCreditPlanCard', () => {
expect(screen.getByText('LEARNER CREDIT PLAN')).toBeInTheDocument();
expect(screen.getByText('Aug 23, 2024 - Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByText('Created Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/test-uuid');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http:www.enterprise-access.com/admin/subsidy_access_policy/learnercredit/test-uuid');
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http://www.enterprise-subsidy.com/admin/subsidy/subsidy/test-uuid/change/');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('SubscriptionPlanCard', () => {
formatDate.mockReturnValue('Aug 23, 2024');
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
LICENSE_MANAGER_URL: 'http:www.license-manager.com',
LICENSE_MANAGER_DJANGO_URL: 'http:www.license-manager.com',
}));
render(
<IntlProvider locale="en">
Expand All @@ -53,7 +53,7 @@ describe('SubscriptionPlanCard', () => {
};
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
LICENSE_MANAGER_URL: 'http:www.license-manager.com',
LICENSE_MANAGER_DJANGO_URL: 'http:www.license-manager.com',
}));
render(
<IntlProvider locale="en">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
getEnterpriseOffers,
getCouponOrders,
getCustomerSubscriptions,
getSubsidyAccessPolicies,
getSubsidies,
} from '../utils';

const useActiveAssociatedPlans = (enterpriseId) => {
Expand All @@ -15,12 +15,12 @@
try {
const [
customerSubscriptionsResponse,
policiesForCustomerResponse,
subsidiesForCustomerResponse,
enterpriseOffersResponse,
couponOrdersResponse,
] = await Promise.all([
getCustomerSubscriptions(enterpriseId),
getSubsidyAccessPolicies(enterpriseId),
getSubsidies(enterpriseId),
getEnterpriseOffers(enterpriseId),
getCouponOrders(enterpriseId),
]);
Expand All @@ -35,11 +35,11 @@
return null;
});

policiesForCustomerResponse.results.some(policy => {
if (policy.active) {
subsidiesForCustomerResponse.some(subsidy => {

Check warning on line 38 in src/Configuration/Customers/data/hooks/useActiveAssociatedPlans.js

View check run for this annotation

Codecov / codecov/patch

src/Configuration/Customers/data/hooks/useActiveAssociatedPlans.js#L38

Added line #L38 was not covered by tests
if (subsidy.isActive) {
setData(prevState => ({
...prevState,
hasActivePolicies: true,
hasActiveSubsidies: true,
}));
}
return null;
Expand Down
Loading