From 6fdcf40e7979030de923a15d89e66f45f2fdc242 Mon Sep 17 00:00:00 2001 From: Binod Pant Date: Mon, 25 Jan 2021 17:05:18 -0500 Subject: [PATCH] bug: ENT-3997 make discountType check case-safe (#189) * bug: make discountType check case-safe * bug: lower case both variables --- src/components/course/data/hooks.js | 6 ++++-- src/components/course/tests/CourseSidebarPrice.test.jsx | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/course/data/hooks.js b/src/components/course/data/hooks.js index 40209206ad..0d73895267 100644 --- a/src/components/course/data/hooks.js +++ b/src/components/course/data/hooks.js @@ -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); } diff --git a/src/components/course/tests/CourseSidebarPrice.test.jsx b/src/components/course/tests/CourseSidebarPrice.test.jsx index 51d70aac23..84de43ad97 100644 --- a/src/components/course/tests/CourseSidebarPrice.test.jsx +++ b/src/components/course/tests/CourseSidebarPrice.test.jsx @@ -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, };