|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bavix\Wallet\Test; |
| 4 | + |
| 5 | +use Bavix\Wallet\Models\Transaction; |
| 6 | +use Bavix\Wallet\Test\Models\Buyer; |
| 7 | +use Bavix\Wallet\Test\Models\ItemTax; |
| 8 | + |
| 9 | +class TaxTest extends TestCase |
| 10 | +{ |
| 11 | + |
| 12 | + /** |
| 13 | + * @return void |
| 14 | + */ |
| 15 | + public function testPay(): void |
| 16 | + { |
| 17 | + /** |
| 18 | + * @var Buyer $buyer |
| 19 | + * @var ItemTax $product |
| 20 | + */ |
| 21 | + $buyer = factory(Buyer::class)->create(); |
| 22 | + $product = factory(ItemTax::class)->create([ |
| 23 | + 'quantity' => 1, |
| 24 | + ]); |
| 25 | + |
| 26 | + $balance = (int) ($product->price + |
| 27 | + $product->price * $product->getFeePercent() / 100); |
| 28 | + |
| 29 | + $this->assertEquals($buyer->balance, 0); |
| 30 | + $buyer->deposit($balance); |
| 31 | + |
| 32 | + $this->assertNotEquals($buyer->balance, 0); |
| 33 | + $transfer = $buyer->pay($product); |
| 34 | + $this->assertNotNull($transfer); |
| 35 | + |
| 36 | + /** |
| 37 | + * @var Transaction $withdraw |
| 38 | + * @var Transaction $deposit |
| 39 | + */ |
| 40 | + $withdraw = $transfer->withdraw; |
| 41 | + $deposit = $transfer->deposit; |
| 42 | + |
| 43 | + $this->assertEquals($withdraw->amount, -$balance); |
| 44 | + $this->assertEquals($deposit->amount, $product->getAmountProduct()); |
| 45 | + $this->assertNotEquals($deposit->amount, $withdraw->amount); |
| 46 | + |
| 47 | + $buyer->refund($product); |
| 48 | + $this->assertEquals($buyer->balance, $deposit->amount); |
| 49 | + $this->assertEquals($product->balance, 0); |
| 50 | + |
| 51 | + $buyer->withdraw($buyer->balance); |
| 52 | + $this->assertEquals($buyer->balance, 0); |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments