Skip to content

Commit

Permalink
fix: resolve bug with multi-use codes and remove unused code (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz authored May 13, 2024
1 parent a8697f4 commit 36b3558
Show file tree
Hide file tree
Showing 40 changed files with 60 additions and 2,526 deletions.
4 changes: 2 additions & 2 deletions src/components/app/data/hooks/useIsAssignmentsOnlyLearner.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function useIsAssignmentsOnlyLearner() {
},
},
} = useBrowseAndRequest();
const { data: { couponCodeAssignments } } = useCouponCodes();
const { data: { couponCodeRedemptionCount } } = useCouponCodes();
const { data: { hasCurrentEnterpriseOffers } } = useEnterpriseOffers();
const { data: redeemableLearnerCreditPolicies } = useRedeemablePolicies();

Expand All @@ -29,7 +29,7 @@ export default function useIsAssignmentsOnlyLearner() {
subscriptionLicense,
licenseRequests,
couponCodeRequests,
couponCodesCount: couponCodeAssignments.length,
couponCodesCount: couponCodeRedemptionCount,
redeemableLearnerCreditPolicies,
hasCurrentEnterpriseOffers,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,7 @@ describe('useIsAssignmentsOnlyLearner', () => {
},
},
hasCurrentEnterpriseOffers: false,
subscriptionPlan: {
isActive: false,
},
subscriptionPlan: undefined,
subscriptionLicense: undefined,
licenseRequests: [],
couponCodesCount: 1,
Expand Down Expand Up @@ -475,7 +473,10 @@ describe('useIsAssignmentsOnlyLearner', () => {
});
useCouponCodes.mockReturnValue({
data: {
couponCodeAssignments: new Array(couponCodesCount).fill('test-coupon-code-assignments'),
couponCodeAssignments: new Array(couponCodesCount).fill({
redemptionsRemaining: 1,
}),
couponCodeRedemptionCount: couponCodesCount,
},
});
useEnterpriseOffers.mockReturnValue({
Expand Down
3 changes: 3 additions & 0 deletions src/components/app/data/services/subsidies/couponCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { logError } from '@edx/frontend-platform/logging';

import { fetchPaginatedData } from '../utils';
import { hasValidStartExpirationDates } from '../../../../../utils/common';
import { findCouponCodeRedemptionCount } from '../../../../enterprise-user-subsidy/coupons';

// Coupon Codes

Expand Down Expand Up @@ -68,8 +69,10 @@ export async function fetchCouponCodes(enterpriseUuid) {
fetchCouponsOverview(enterpriseUuid),
fetchCouponCodeAssignments(enterpriseUuid),
]);
const couponCodeRedemptionCount = findCouponCodeRedemptionCount(results[1]);
return {
couponsOverview: results[0],
couponCodeAssignments: results[1],
couponCodeRedemptionCount,
};
}
11 changes: 9 additions & 2 deletions src/components/app/data/services/subsidies/couponCodes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ describe('fetchCouponCodes', () => {
const COUPON_CODE_ASSIGNMENTS_URL = getCouponCodeAssignmentsUrl(enterpriseId);
const COUPONS_OVERVIEW_URL = getCouponsOverviewUrl(enterpriseId);
const couponCodeAssignmentsResponse = {
results: [{ id: 123 }],
results: [
{ code: 123, redemptionsRemaining: 1 },
{ code: 456, redemptionsRemaining: 2 },
],
};
const couponsOverviewResponse = {
results: [{ id: 123 }],
Expand All @@ -90,10 +93,14 @@ describe('fetchCouponCodes', () => {
axiosMock.onGet(COUPONS_OVERVIEW_URL).reply(200, couponsOverviewResponse);
const result = await fetchCouponCodes(enterpriseId);

const expectedCouponsCodeAssignmentsResponse = [{ ...couponCodeAssignmentsResponse.results[0], available: false }];
const expectedCouponsCodeAssignmentsResponse = couponCodeAssignmentsResponse.results.map((assignment) => ({
...assignment,
available: false,
}));
expect(result).toEqual({
couponCodeAssignments: expectedCouponsCodeAssignmentsResponse,
couponsOverview: couponsOverviewResponse.results,
couponCodeRedemptionCount: 3,
});
});
});
8 changes: 6 additions & 2 deletions src/components/course/data/courseLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export default function makeCourseLoader(queryClient) {
const redeemableLearnerCreditPolicies = subsidyResponses[0];
const { customerAgreement, subscriptionPlan, subscriptionLicense } = subsidyResponses[1];
const { hasCurrentEnterpriseOffers, currentEnterpriseOffers } = subsidyResponses[2];
const { couponCodeAssignments, couponsOverview } = subsidyResponses[3];
const {
couponCodeAssignments,
couponCodeRedemptionCount,
couponsOverview,
} = subsidyResponses[3];
const licenseRequests = subsidyResponses[4];
const couponCodeRequests = subsidyResponses[5];
const browseAndRequestConfiguration = subsidyResponses[6];
Expand All @@ -99,7 +103,7 @@ export default function makeCourseLoader(queryClient) {
subscriptionLicense,
licenseRequests,
couponCodeRequests,
couponCodesCount: couponCodeAssignments.length,
couponCodesCount: couponCodeRedemptionCount,
redeemableLearnerCreditPolicies,
hasCurrentEnterpriseOffers,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useCouponCodes, useCourseMetadata, useEnterpriseCourseEnrollments } fro
*/
const ToEcomBasketPage = ({ enrollLabel, enrollmentUrl, courseRunPrice }) => {
const { userSubsidyApplicableToCourse } = useUserSubsidyApplicableToCourse();
const { data: { couponCodeAssignments } } = useCouponCodes();
const { data: { couponCodeRedemptionCount } } = useCouponCodes();
const [isModalOpen, setIsModalOpen] = useState(false);
const {
data: {
Expand Down Expand Up @@ -57,7 +57,7 @@ const ToEcomBasketPage = ({ enrollLabel, enrollmentUrl, courseRunPrice }) => {
enrollmentUrl={enrollmentUrl}
courseRunPrice={courseRunPrice}
userSubsidyApplicableToCourse={userSubsidyApplicableToCourse}
couponCodesCount={couponCodeAssignments.length}
couponCodesCount={couponCodeRedemptionCount}
onEnroll={handleEnroll}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const UpgradeCourseButton = ({
const [isModalOpen, setIsModalOpen] = useState(false);

const { data: enterpriseCustomer } = useEnterpriseCustomer();
const { data: { couponCodeAssignments } } = useCouponCodes();
const { data: { couponCodeRedemptionCount } } = useCouponCodes();
const {
subsidyForCourse,
couponUpgradeUrl,
Expand Down Expand Up @@ -57,7 +57,7 @@ const UpgradeCourseButton = ({
enrollmentUrl={couponUpgradeUrl}
courseRunPrice={courseRunPrice}
userSubsidyApplicableToCourse={subsidyForCourse}
couponCodesCount={couponCodeAssignments.length}
couponCodesCount={couponCodeRedemptionCount}
onEnroll={handleEnroll}
/>
</>
Expand Down
155 changes: 0 additions & 155 deletions src/components/enterprise-subsidy-requests/data/hooks.js

This file was deleted.

1 change: 0 additions & 1 deletion src/components/enterprise-subsidy-requests/data/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './hooks';
export * from './service';
37 changes: 0 additions & 37 deletions src/components/enterprise-subsidy-requests/data/service.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { getConfig } from '@edx/frontend-platform/config';

import { SUBSIDY_REQUEST_STATE } from '../../../constants';

export function fetchSubsidyRequestConfiguration(enterpriseUUID) {
const url = `${getConfig().ENTERPRISE_ACCESS_BASE_URL}/api/v1/customer-configurations/${enterpriseUUID}/`;
return getAuthenticatedHttpClient().get(url);
}

export function fetchLicenseRequests({
enterpriseUUID,
userEmail,
state = SUBSIDY_REQUEST_STATE.REQUESTED,
}) {
const queryParams = new URLSearchParams({
enterprise_customer_uuid: enterpriseUUID,
user__email: userEmail,
state,
});
const config = getConfig();
const url = `${config.ENTERPRISE_ACCESS_BASE_URL}/api/v1/license-requests/?${queryParams.toString()}`;
return getAuthenticatedHttpClient().get(url);
}

export function fetchCouponCodeRequests({
enterpriseUUID,
userEmail,
state = SUBSIDY_REQUEST_STATE.REQUESTED,
}) {
const queryParams = new URLSearchParams({
enterprise_customer_uuid: enterpriseUUID,
user__email: userEmail,
state,
});
const config = getConfig();
const url = `${config.ENTERPRISE_ACCESS_BASE_URL}/api/v1/coupon-code-requests/?${queryParams.toString()}`;
return getAuthenticatedHttpClient().get(url);
}

export function postCouponCodeRequest(enterpriseUUID, courseID) {
const options = {
enterprise_customer_uuid: enterpriseUUID,
Expand Down
Loading

0 comments on commit 36b3558

Please sign in to comment.