Skip to content

Commit

Permalink
bug: ENT-3997 make discountType check case-safe (#189)
Browse files Browse the repository at this point in the history
* bug: make discountType check case-safe

* bug: lower case both variables
  • Loading branch information
binodpant authored Jan 25, 2021
1 parent 8f9e292 commit 6fdcf40
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/components/course/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ const useCoursePriceForUserSubsidy = ({
const { discountType, discountValue } = userSubsidyApplicableToCourse;
let discountedPrice;

if (discountType === SUBSIDY_DISCOUNT_TYPE_MAP.PERCENTAGE) {
if (discountType
&& discountType.toLowerCase() === SUBSIDY_DISCOUNT_TYPE_MAP.PERCENTAGE.toLowerCase()) {
discountedPrice = listPrice - (listPrice * (discountValue / 100));
}

if (discountType === SUBSIDY_DISCOUNT_TYPE_MAP.ABSOLUTE) {
if (discountType
&& discountType.toLowerCase() === SUBSIDY_DISCOUNT_TYPE_MAP.ABSOLUTE.toLowerCase()) {
discountedPrice = Math.max(listPrice - discountValue, 0);
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/course/tests/CourseSidebarPrice.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ const courseStateWithLicenseSubsidy = {
userSubsidyApplicableToCourse: { subsidyType: LICENSE_SUBSIDY_TYPE },
};

// making discountType uppercase to help validate case-safe check in hooks logic
const FULL_OFFER_SUBSIDY = {
discountType: SUBSIDY_DISCOUNT_TYPE_MAP.PERCENTAGE,
discountType: SUBSIDY_DISCOUNT_TYPE_MAP.PERCENTAGE.toUpperCase(),
discountValue: 100,
subsidyType: OFFER_SUBSIDY_TYPE,
};
Expand Down

0 comments on commit 6fdcf40

Please sign in to comment.