forked from Code-4-Community/scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-183] add FM dashboard endpoint #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amywng
wants to merge
7
commits into
main
Choose a base branch
from
acw/SSF-183-fm-dashboard-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab47c44
add fm dashboard endpoint
amywng d058bf5
clean up
amywng 9f37848
add next weekly reminder logic
amywng 6858606
handle non-weekly cases and add tests
amywng 47c708f
Merge branch 'main' into acw/SSF-183-fm-dashboard-endpoint
amywng 3184088
comments
amywng 358f8d0
fixes from volunteer order mgmt frontend pr
amywng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,154 @@ | ||
| import { calculateNextDonationDate } from './recurrence.utils'; | ||
| import { RecurrenceEnum } from './types'; | ||
|
|
||
| describe('calculateNextDonationDate', () => { | ||
| describe('WEEKLY', () => { | ||
| it('advances by 7 days when freq is 1', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 1), | ||
| RecurrenceEnum.WEEKLY, | ||
| 1, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 0, 8)); | ||
| }); | ||
|
|
||
| it('advances by 14 days when freq is 2', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 1), | ||
| RecurrenceEnum.WEEKLY, | ||
| 2, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 0, 15)); | ||
| }); | ||
|
|
||
| it('advances by 21 days when freq is 3', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 2, 10), | ||
| RecurrenceEnum.WEEKLY, | ||
| 3, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 2, 31)); | ||
| }); | ||
|
|
||
| it('rolls over into the next month', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 28), | ||
| RecurrenceEnum.WEEKLY, | ||
| 1, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 1, 4)); | ||
| }); | ||
| }); | ||
|
|
||
| describe('MONTHLY', () => { | ||
| it('advances by 1 month when freq is 1', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 15), | ||
| RecurrenceEnum.MONTHLY, | ||
| 1, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 1, 15)); | ||
| }); | ||
|
|
||
| it('advances by 3 months when freq is 3', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 15), | ||
| RecurrenceEnum.MONTHLY, | ||
| 3, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 3, 15)); | ||
| }); | ||
|
|
||
| it('crosses year boundary correctly', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 10, 15), | ||
| RecurrenceEnum.MONTHLY, | ||
| 3, | ||
| ); | ||
| expect(result).toEqual(new Date(2026, 1, 15)); | ||
| }); | ||
|
|
||
| it('clamps day to 28 before adding months when date is after the 28th', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 31), | ||
| RecurrenceEnum.MONTHLY, | ||
| 1, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 1, 28)); | ||
| }); | ||
| }); | ||
|
|
||
| describe('YEARLY', () => { | ||
| it('advances by 1 year when freq is 1', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 5, 15), | ||
| RecurrenceEnum.YEARLY, | ||
| 1, | ||
| ); | ||
| expect(result).toEqual(new Date(2026, 5, 15)); | ||
| }); | ||
|
|
||
| it('advances by 3 years when freq is 3', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 5, 15), | ||
| RecurrenceEnum.YEARLY, | ||
| 3, | ||
| ); | ||
| expect(result).toEqual(new Date(2028, 5, 15)); | ||
| }); | ||
|
|
||
| it('clamps day to 28 before adding years when date is after the 28th', () => { | ||
| // Feb 29 doesn't exist in 2025, but JS parses it as Mar 1 — clamping still applies | ||
| const r = calculateNextDonationDate( | ||
| new Date(2024, 1, 29), | ||
|
amywng marked this conversation as resolved.
|
||
| RecurrenceEnum.YEARLY, | ||
| 1, | ||
| ); | ||
| expect(r).toEqual(new Date(2025, 1, 28)); | ||
| }); | ||
| }); | ||
|
|
||
| describe('null / default recurrenceFreq', () => { | ||
| it('defaults freq to 1 when null is passed for WEEKLY', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 1), | ||
| RecurrenceEnum.WEEKLY, | ||
| null, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 0, 8)); | ||
| }); | ||
|
|
||
| it('defaults freq to 1 when null is passed for MONTHLY', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 0, 15), | ||
| RecurrenceEnum.MONTHLY, | ||
| null, | ||
| ); | ||
| expect(result).toEqual(new Date(2025, 1, 15)); | ||
| }); | ||
|
|
||
| it('defaults freq to 1 when null is passed for YEARLY', () => { | ||
| const result = calculateNextDonationDate( | ||
| new Date(2025, 5, 15), | ||
| RecurrenceEnum.YEARLY, | ||
| null, | ||
| ); | ||
| expect(result).toEqual(new Date(2026, 5, 15)); | ||
| }); | ||
| }); | ||
|
|
||
| describe('NONE', () => { | ||
| it('returns the same date unchanged', () => { | ||
| const input = new Date(2025, 0, 15); | ||
| const result = calculateNextDonationDate(input, RecurrenceEnum.NONE, 1); | ||
| expect(result).toEqual(input); | ||
| }); | ||
| }); | ||
|
|
||
| it('does not mutate the input date', () => { | ||
| const input = new Date(2025, 0, 1); | ||
| const original = input.getTime(); | ||
| calculateNextDonationDate(input, RecurrenceEnum.WEEKLY, 1); | ||
| expect(input.getTime()).toBe(original); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,39 @@ | ||
| import { RecurrenceEnum } from './types'; | ||
|
|
||
| /** | ||
| * Calculates next single donation date from a given currentDate during recurring donation processing | ||
| * | ||
| * used by handleRecurringDonations to determine the replacement date when an occurrence is processed | ||
| * unlike generateNextDonationDates, this always returns exactly one date and doesn't consider | ||
| * multiple selected days for weekly recurrence | ||
| * | ||
| * for MONTHLY/YEARLY recurrence, dates > 28 are clamped to 28 before adding the interval to | ||
| * prevent date rollover | ||
| * | ||
| * @param currentDate - date to calculate from | ||
| * @param recurrence - recurrence type (WEEKLY, MONTHLY, YEARLY, or NONE) | ||
| * @param recurrenceFreq - how many weeks/months/years to add (defaults to 1) | ||
| * @returns a new Date representing the next occurrence | ||
| */ | ||
| export function calculateNextDonationDate( | ||
| currentDate: Date, | ||
| recurrence: RecurrenceEnum, | ||
| recurrenceFreq: number | null = 1, | ||
| ): Date { | ||
| const freq = recurrenceFreq ?? 1; | ||
| const nextDate = new Date(currentDate); | ||
| switch (recurrence) { | ||
| case RecurrenceEnum.WEEKLY: | ||
| nextDate.setDate(nextDate.getDate() + 7 * freq); | ||
| break; | ||
| case RecurrenceEnum.MONTHLY: | ||
| if (nextDate.getDate() > 28) nextDate.setDate(28); | ||
| nextDate.setMonth(nextDate.getMonth() + freq); | ||
| break; | ||
| case RecurrenceEnum.YEARLY: | ||
| if (nextDate.getDate() > 28) nextDate.setDate(28); | ||
| nextDate.setFullYear(nextDate.getFullYear() + freq); | ||
| break; | ||
| } | ||
| return nextDate; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.