Skip to content

Commit

Permalink
fix: cr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMuzyk committed Jul 2, 2024
1 parent 0ee9313 commit 56974f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down
9 changes: 1 addition & 8 deletions src/pages/settings/Subscription/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
14 changes: 14 additions & 0 deletions tests/unit/DateUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 56974f4

Please sign in to comment.