From 56974f4f2f665bf1d44926a48d3167713f7730d7 Mon Sep 17 00:00:00 2001 From: Michal Muzyk Date: Tue, 2 Jul 2024 15:21:08 +0200 Subject: [PATCH] fix: cr fixes --- src/libs/DateUtils.ts | 2 +- src/pages/settings/Subscription/utils.ts | 9 +-------- tests/unit/DateUtilsTest.ts | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/libs/DateUtils.ts b/src/libs/DateUtils.ts index f2e929fe16c6..8a8888902e92 100644 --- a/src/libs/DateUtils.ts +++ b/src/libs/DateUtils.ts @@ -808,7 +808,7 @@ function doesDateBelongToAPastYear(date: string): boolean { /** * Returns a boolean value indicating whether the card has expired. - * @param expiryMonth month when card expires + * @param expiryMonth month when card expires (starts from 1 so can be any number between 1 and 12) * @param expiryYear year when card expires */ diff --git a/src/pages/settings/Subscription/utils.ts b/src/pages/settings/Subscription/utils.ts index b39d9e54a257..e9649eb3748d 100644 --- a/src/pages/settings/Subscription/utils.ts +++ b/src/pages/settings/Subscription/utils.ts @@ -19,11 +19,4 @@ function getNewSubscriptionRenewalDate(): string { return format(startOfMonth(addMonths(new Date(), 12)), CONST.DATE.MONTH_DAY_YEAR_ABBR_FORMAT); } -function isCardExpired(expiryMonth: number, expiryYear: number): boolean { - const currentYear = new Date().getFullYear(); - const currentMonth = new Date().getMonth() + 1; - - return expiryYear < currentYear || (expiryYear === currentYear && expiryMonth < currentMonth); -} - -export {getNewSubscriptionRenewalDate, formatSubscriptionEndDate, isCardExpired}; +export {getNewSubscriptionRenewalDate, formatSubscriptionEndDate}; diff --git a/tests/unit/DateUtilsTest.ts b/tests/unit/DateUtilsTest.ts index 9df0113168e4..f3abed2e3372 100644 --- a/tests/unit/DateUtilsTest.ts +++ b/tests/unit/DateUtilsTest.ts @@ -265,4 +265,18 @@ describe('DateUtils', () => { expect(lastBusinessDay).toEqual(expectedResult); }); }); + + describe('isCardExpired', () => { + it('should return true when the card is expired', () => { + const cardMonth = 1; + const cardYear = new Date().getFullYear() - 1; + expect(DateUtils.isCardExpired(cardMonth, cardYear)).toBe(true); + }); + + it('should return false when the card is not expired', () => { + const cardMonth = 1; + const cardYear = new Date().getFullYear() + 1; + expect(DateUtils.isCardExpired(cardMonth, cardYear)).toBe(false); + }); + }); });