82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Enums\BucketAllocationType;
|
|
use App\Models\Bucket;
|
|
use App\Models\Draw;
|
|
use App\Models\Outflow;
|
|
use App\Models\Scenario;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class BucketTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_current_balance_includes_starting_amount()
|
|
{
|
|
// Arrange
|
|
$scenario = Scenario::factory()->create();
|
|
$bucket = Bucket::factory()->create([
|
|
'scenario_id' => $scenario->id,
|
|
'starting_amount' => 100000, // $1000 in cents
|
|
'allocation_type' => BucketAllocationType::UNLIMITED,
|
|
]);
|
|
|
|
// Create draws and outflows directly
|
|
Draw::create([
|
|
'bucket_id' => $bucket->id,
|
|
'amount' => 50000, // $500 in cents
|
|
'date' => now(),
|
|
'description' => 'Test draw',
|
|
'is_projected' => false,
|
|
]);
|
|
|
|
Outflow::create([
|
|
'stream_id' => null, // We'll make this nullable for test
|
|
'bucket_id' => $bucket->id,
|
|
'amount' => 20000, // $200 in cents
|
|
'date' => now(),
|
|
'description' => 'Test outflow',
|
|
'is_projected' => false,
|
|
]);
|
|
|
|
// Act & Assert
|
|
// starting_amount (1000) + draws (500) - outflows (200) = 1300
|
|
$this->assertEquals(1300.00, $bucket->getCurrentBalance());
|
|
}
|
|
|
|
public function test_current_balance_without_starting_amount_defaults_to_zero()
|
|
{
|
|
// Arrange
|
|
$scenario = Scenario::factory()->create();
|
|
$bucket = Bucket::factory()->create([
|
|
'scenario_id' => $scenario->id,
|
|
'starting_amount' => 0, // $0 in cents
|
|
'allocation_type' => BucketAllocationType::UNLIMITED,
|
|
]);
|
|
|
|
// Create draws and outflows directly
|
|
Draw::create([
|
|
'bucket_id' => $bucket->id,
|
|
'amount' => 30000, // $300 in cents
|
|
'date' => now(),
|
|
'description' => 'Test draw',
|
|
'is_projected' => false,
|
|
]);
|
|
|
|
Outflow::create([
|
|
'stream_id' => null, // We'll make this nullable for test
|
|
'bucket_id' => $bucket->id,
|
|
'amount' => 10000, // $100 in cents
|
|
'date' => now(),
|
|
'description' => 'Test outflow',
|
|
'is_projected' => false,
|
|
]);
|
|
|
|
// Act & Assert
|
|
// starting_amount (0) + draws (300) - outflows (100) = 200
|
|
$this->assertEquals(200.00, $bucket->getCurrentBalance());
|
|
}
|
|
}
|