create(); $bucket = Bucket::factory()->create([ 'scenario_id' => $scenario->id, 'starting_amount' => 100000, // $1000 in cents 'allocation_type' => BucketAllocationTypeEnum::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 (100000) + draws (50000) - outflows (20000) = 130000 $this->assertEquals(130000, $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' => BucketAllocationTypeEnum::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 (30000) - outflows (10000) = 20000 $this->assertEquals(20000, $bucket->getCurrentBalance()); } }