-
Notifications
You must be signed in to change notification settings - Fork 1
fix(backend): Correctly calculate spendable potato #345
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
cleptric
wants to merge
5
commits into
main
Choose a base branch
from
spendable-potatos
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
5 commits
Select commit
Hold shift + click to select a range
b474ead
fix(backend): Correctly calculate spendable potato
cleptric c4c5ebb
wip
cleptric 47a445a
Merge branch 'main' into spendable-potatos
cleptric 97b3787
Merge branch 'main' into spendable-potatos
cleptric e149979
fix(backend): Clamp spendablePotato to non-negative and freeze test time
cleptric 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,83 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Test\Fixture; | ||
|
|
||
| use Cake\TestSuite\Fixture\TestFixture; | ||
|
|
||
| /** | ||
| * PurchasesFixture | ||
| */ | ||
| class PurchasesFixture extends TestFixture | ||
| { | ||
| /** | ||
| * Records | ||
| * | ||
| * @var array<array<string, mixed>> | ||
| */ | ||
| public array $records = [ | ||
| // User 1 purchases | ||
| [ | ||
| 'id' => 1, | ||
| 'user_id' => '00000000-0000-0000-0000-000000000001', | ||
| 'presentee_id' => null, | ||
| 'name' => 'Old Purchase', | ||
| 'description' => 'Purchase from 120 days ago', | ||
| 'image_link' => 'https://example.com/old.jpg', | ||
| 'message' => null, | ||
| 'price' => 100, | ||
| 'code' => null, | ||
| 'created' => '2025-05-15 10:00:00', // ~120 days ago from Sept 12, 2025 | ||
| ], | ||
| [ | ||
| 'id' => 2, | ||
| 'user_id' => '00000000-0000-0000-0000-000000000001', | ||
| 'presentee_id' => null, | ||
| 'name' => 'Recent Purchase 1', | ||
| 'description' => 'Purchase from 30 days ago', | ||
| 'image_link' => 'https://example.com/recent1.jpg', | ||
| 'message' => null, | ||
| 'price' => 200, | ||
| 'code' => null, | ||
| 'created' => '2025-08-13 10:00:00', // ~30 days ago | ||
| ], | ||
| [ | ||
| 'id' => 3, | ||
| 'user_id' => '00000000-0000-0000-0000-000000000001', | ||
| 'presentee_id' => null, | ||
| 'name' => 'Recent Purchase 2', | ||
| 'description' => 'Purchase from 10 days ago', | ||
| 'image_link' => 'https://example.com/recent2.jpg', | ||
| 'message' => null, | ||
| 'price' => 150, | ||
| 'code' => null, | ||
| 'created' => '2025-09-02 10:00:00', // ~10 days ago | ||
| ], | ||
| // User 2 purchases (at spending limit) | ||
| [ | ||
| 'id' => 4, | ||
| 'user_id' => '00000000-0000-0000-0000-000000000002', | ||
| 'presentee_id' => null, | ||
| 'name' => 'Max Purchase 1', | ||
| 'description' => 'Purchase from 60 days ago', | ||
| 'image_link' => 'https://example.com/max1.jpg', | ||
| 'message' => null, | ||
| 'price' => 300, | ||
| 'code' => null, | ||
| 'created' => '2025-07-14 10:00:00', // ~60 days ago | ||
| ], | ||
| [ | ||
| 'id' => 5, | ||
| 'user_id' => '00000000-0000-0000-0000-000000000002', | ||
| 'presentee_id' => null, | ||
| 'name' => 'Max Purchase 2', | ||
| 'description' => 'Purchase from 20 days ago', | ||
| 'image_link' => 'https://example.com/max2.jpg', | ||
| 'message' => null, | ||
| 'price' => 200, | ||
| 'code' => null, | ||
| 'created' => '2025-08-23 10:00:00', // ~20 days ago | ||
| ], | ||
| // User 3 has no purchases | ||
| ]; | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Timezone Mismatch in 90-Day Calculation
The
spendablePotatomethod calculates the 90-day spending window usingDateTime::now()->subDays(90). This implicitly uses the server's default timezone, which can cause incorrect 90-day period calculations against UTC database timestamps. Other methods in this class explicitly handle timezones, making this an inconsistency.