AgentCommissionSpreadTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Services\Agent\AgentCommissionService;
  4. use PHPUnit\Framework\TestCase;
  5. class AgentCommissionSpreadTest extends TestCase
  6. {
  7. public function test_parent_keeps_the_rate_difference_on_child_volume(): void
  8. {
  9. $this->assertSame('1.0000', AgentCommissionService::rateSpread('5', '4'));
  10. $this->assertSame('0.0000', AgentCommissionService::rateSpread('4', '4'));
  11. $this->assertSame('0.0000', AgentCommissionService::rateSpread('4', '5'));
  12. }
  13. public function test_own_members_use_full_rate_and_child_members_use_spread(): void
  14. {
  15. $ownFlow = AgentCommissionService::amountByRate('1000', '5');
  16. $childFlow = AgentCommissionService::amountByRate('1000', AgentCommissionService::rateSpread('5', '4'));
  17. $this->assertSame('50.0000', $ownFlow);
  18. $this->assertSame('10.0000', $childFlow);
  19. $this->assertSame('60.0000', bcadd($ownFlow, $childFlow, 4));
  20. }
  21. public function test_profit_commission_uses_member_loss_only(): void
  22. {
  23. $this->assertSame('100.0000', AgentCommissionService::profitBase('-100'));
  24. $this->assertSame('0.0000', AgentCommissionService::profitBase('80'));
  25. $own = AgentCommissionService::amountByRate(AgentCommissionService::profitBase('-200'), '5');
  26. $child = AgentCommissionService::amountByRate(
  27. AgentCommissionService::profitBase('-200'),
  28. AgentCommissionService::rateSpread('5', '4')
  29. );
  30. $this->assertSame('10.0000', $own);
  31. $this->assertSame('2.0000', $child);
  32. }
  33. }