Skip to content

Commit

Permalink
chore: PR feedback 2
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Oct 8, 2024
1 parent 476afd9 commit 8329e2e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { queryCanRedeem } from '../queries';
import useEnterpriseCustomer from './useEnterpriseCustomer';
import useLateEnrollmentBufferDays from './useLateEnrollmentBufferDays';

const getContentListPrice = ({ courseRuns }) => {
const getContentListPriceRange = ({ courseRuns }) => {
const flatContentPrice = courseRuns.flatMap(run => run.listPrice?.usd).filter(x => !!x);
// Find the max and min prices
if (!flatContentPrice.length) {
return null;
return [];

Check warning on line 13 in src/components/app/data/hooks/useCourseRedemptionEligibility.js

View check run for this annotation

Codecov / codecov/patch

src/components/app/data/hooks/useCourseRedemptionEligibility.js#L13

Added line #L13 was not covered by tests
}
const maxPrice = Math.max(...flatContentPrice);
const minPrice = Math.min(...flatContentPrice);
Expand All @@ -32,7 +32,7 @@ export function transformCourseRedemptionEligibility({
const otherSubsidyAccessPolicy = canRedeemData.find(
r => r.redeemableSubsidyAccessPolicy,
)?.redeemableSubsidyAccessPolicy;
const listPrice = getContentListPrice({ courseRuns: canRedeemData });
const listPrice = getContentListPriceRange({ courseRuns: canRedeemData });
const hasSuccessfulRedemption = courseRunKey
? !!canRedeemData.find(r => r.contentKey === courseRunKey)?.hasSuccessfulRedemption
: canRedeemData.some(r => r.hasSuccessfulRedemption);
Expand Down
2 changes: 1 addition & 1 deletion src/components/course/CourseSidebarPrice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const CourseSidebarPrice = () => {
const discountedPriceDisplay = `${getContentPriceDisplay(coursePrice.discountedList)} ${currency}`;
return (
<>
<div className={classNames({ 'mb-2': coursePrice.discountedList > 0 || showOrigPrice })}>
<div className={classNames({ 'mb-2': sumOfArray(coursePrice.discountedList) > 0 || showOrigPrice })}>
{/* discountedList > 0 means partial discount */}
{showOrigPrice && <>{crossedOutOriginalPrice}{' '}</>}
{sumOfArray(coursePrice.discountedList) > 0 && (
Expand Down
4 changes: 2 additions & 2 deletions src/components/course/data/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ export function useCoursePacingType(courseRun) {

/**
* @typedef {Object} CoursePrice
* @property {number} listRange The list price.
* @property {number} discountedList The discountedList price.
* @property {number[]} listRange The list price.
* @property {number[]} discountedListRange The discountedListRange price.
*/

/**
Expand Down
2 changes: 2 additions & 0 deletions src/components/course/data/tests/hooks.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,8 @@ describe('useCourseListPrice', () => {
beforeEach(() => {
jest.clearAllMocks();
useCourseRedemptionEligibility.mockReturnValue({ data: { listPrice: mockListPrice } });
// NOTE: `useCourseMetadata`'s mocked return value assumes the returned value
// from the `select` function passed to the hook.
useCourseMetadata.mockReturnValue({ data: mockListPrice || getCoursePrice(baseCourseMetadataValue) });
});
it('should return the list price if one exist', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/components/course/data/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,14 @@ export function getProgramIcon(type) {
}
}

export const numberWithPrecision = (number, precision = 2) => number.toFixed(precision);

/**
* Displays content price with precision as a range or singular price
* @param priceRange
* @returns {*|string}
*/
export const getContentPriceDisplay = (priceRange) => {
if (!priceRange?.length) {
return numberWithPrecision(ZERO_PRICE);
return formatPrice(ZERO_PRICE);

Check warning on line 163 in src/components/course/data/utils.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/course/data/utils.jsx#L163

Added line #L163 was not covered by tests
}
const minPrice = Math.min(...priceRange);
const maxPrice = Math.max(...priceRange);
Expand Down

0 comments on commit 8329e2e

Please sign in to comment.