|
4 | 4 |
|
5 | 5 | use Bavix\Wallet\Exceptions\AmountInvalid; |
6 | 6 | use Bavix\Wallet\Exceptions\BalanceIsEmpty; |
| 7 | +use Bavix\Wallet\Models\Transaction; |
7 | 8 | use Bavix\Wallet\Models\Transfer; |
8 | 9 | use Bavix\Wallet\Test\Models\Item; |
| 10 | +use Bavix\Wallet\Test\Models\UserCashier; |
9 | 11 | use Bavix\Wallet\Test\Models\UserMulti; |
10 | 12 | use Illuminate\Database\QueryException; |
11 | 13 | use function compact; |
@@ -406,4 +408,35 @@ public function testPay(): void |
406 | 408 | $this->assertEquals($b->balance, $product->getAmountProduct()); |
407 | 409 | } |
408 | 410 |
|
| 411 | + /** |
| 412 | + * @return void |
| 413 | + */ |
| 414 | + public function testUserCashier(): void |
| 415 | + { |
| 416 | + /** |
| 417 | + * @var UserCashier $user |
| 418 | + */ |
| 419 | + $user = factory(UserCashier::class)->create(); |
| 420 | + $default = $user->wallet; |
| 421 | + |
| 422 | + $this->assertEquals($default->balance, 0); |
| 423 | + |
| 424 | + $transaction = $default->deposit(100); |
| 425 | + $this->assertEquals($transaction->type, Transaction::TYPE_DEPOSIT); |
| 426 | + $this->assertEquals($transaction->amount, 100); |
| 427 | + $this->assertEquals($default->balance, 100); |
| 428 | + |
| 429 | + $newWallet = $user->createWallet(['name' => 'New Wallet']); |
| 430 | + |
| 431 | + $transfer = $default->transfer($newWallet, 100); |
| 432 | + $this->assertEquals($default->balance, 0); |
| 433 | + $this->assertEquals($newWallet->balance, 100); |
| 434 | + |
| 435 | + $this->assertEquals($transfer->withdraw->type, Transaction::TYPE_WITHDRAW); |
| 436 | + $this->assertEquals($transfer->withdraw->amount, -100); |
| 437 | + |
| 438 | + $this->assertEquals($transfer->deposit->type, Transaction::TYPE_DEPOSIT); |
| 439 | + $this->assertEquals($transfer->deposit->amount, 100); |
| 440 | + } |
| 441 | + |
409 | 442 | } |
0 commit comments