-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43473 from pasyukevich/feature/card-billing-banne…
…r-api-integration
- Loading branch information
Showing
7 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
import {addMonths, format, startOfMonth} from 'date-fns'; | ||
import * as SubscriptionUtils from '@libs/SubscriptionUtils'; | ||
import CONST from '@src/CONST'; | ||
|
||
/** | ||
* Get the next billing date. | ||
* | ||
* @returns - The next billing date in 'yyyy-MM-dd' format. | ||
*/ | ||
function getNextBillingDate(): string { | ||
const today = new Date(); | ||
|
||
const nextBillingDate = startOfMonth(addMonths(today, 1)); | ||
|
||
return format(nextBillingDate, CONST.DATE.MONTH_DAY_YEAR_FORMAT); | ||
} | ||
|
||
function shouldShowPreTrialBillingBanner(): boolean { | ||
return !SubscriptionUtils.isUserOnFreeTrial() && !SubscriptionUtils.hasUserFreeTrialEnded(); | ||
} | ||
|
||
export default { | ||
shouldShowPreTrialBillingBanner, | ||
getNextBillingDate, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import CardSectionUtils from '@src/pages/settings/Subscription/CardSection/utils'; | ||
|
||
describe('getNextBillingDate', () => { | ||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
// Month is zero indexed, so this is July 5th 2024 | ||
jest.setSystemTime(new Date(2024, 6, 5)); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should return the next billing date when initial date is valid', () => { | ||
const expectedNextBillingDate = 'August 1, 2024'; | ||
|
||
expect(CardSectionUtils.getNextBillingDate()).toEqual(expectedNextBillingDate); | ||
}); | ||
|
||
it('should handle end-of-month edge cases correctly', () => { | ||
const nextBillingDate = CardSectionUtils.getNextBillingDate(); | ||
const expectedNextBillingDate = 'August 1, 2024'; | ||
expect(nextBillingDate).toBe(expectedNextBillingDate); | ||
}); | ||
|
||
it('should handle date when it at the current month', () => { | ||
const nextBillingDate = CardSectionUtils.getNextBillingDate(); | ||
const expectedNextBillingDate = 'August 1, 2024'; | ||
expect(nextBillingDate).toBe(expectedNextBillingDate); | ||
}); | ||
|
||
it('should return the next billing date when initial date is invalid', () => { | ||
const expectedNextBillingDate = 'August 1, 2024'; | ||
|
||
expect(CardSectionUtils.getNextBillingDate()).toEqual(expectedNextBillingDate); | ||
}); | ||
}); |