-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: frequency get remaining iterations method logic fixed for first …
…date inclusive (#18) * first date inclusion logic added * dates fixed * test corrected * RecurringCashFlowServiceTest.php added
- Loading branch information
1 parent
96fe200
commit 8e864dc
Showing
3 changed files
with
71 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
use App\Enums\Frequency; | ||
use App\Models\Account; | ||
use App\Models\RecurringExpense; | ||
use App\Models\RecurringIncome; | ||
use App\Models\User; | ||
use App\Services\RecurringCashFlowService; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
use function PHPUnit\Framework\assertEquals; | ||
|
||
uses(RefreshDatabase::class); | ||
|
||
beforeEach(function () { | ||
$this->user = User::factory()->create(); | ||
$this->actingAs($this->user); | ||
}); | ||
|
||
test('it returns recurring incomes total', function () { | ||
$account = Account::factory()->create(); | ||
|
||
RecurringIncome::factory() | ||
->for($this->user) | ||
->for($account) | ||
->create([ | ||
'amount' => 1000, | ||
'frequency' => Frequency::MONTHLY, | ||
'remaining_recurrences' => 12, | ||
'next_transaction_at' => today()->addDay(), | ||
]); | ||
|
||
$total = RecurringCashFlowService::processRecurringIncomes( | ||
$this->user, | ||
today(), | ||
today()->addYear() | ||
); | ||
|
||
assertEquals(12000, $total); | ||
}); | ||
|
||
test('it returns recurring expenses total', function () { | ||
$account = Account::factory()->create(); | ||
|
||
RecurringExpense::factory() | ||
->for($this->user) | ||
->for($account) | ||
->create([ | ||
'amount' => 1000, | ||
'frequency' => Frequency::MONTHLY, | ||
'remaining_recurrences' => 12, | ||
'next_transaction_at' => today()->addDay(), | ||
]); | ||
|
||
$total = RecurringCashFlowService::processRecurringExpenses( | ||
$this->user, | ||
today(), | ||
today()->addYear() | ||
); | ||
|
||
assertEquals(12000, $total); | ||
}); |
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