|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Bavix\Wallet\Test\Units\Domain; |
| 6 | + |
| 7 | +use Bavix\Wallet\Test\Infra\Factories\UserMultiFactory; |
| 8 | +use Bavix\Wallet\Test\Infra\Models\UserMulti; |
| 9 | +use Bavix\Wallet\Test\Infra\TestCase; |
| 10 | + |
| 11 | +/** |
| 12 | + * @internal |
| 13 | + */ |
| 14 | +class CreditWalletTest extends TestCase |
| 15 | +{ |
| 16 | + public function testCreditLimit(): void |
| 17 | + { |
| 18 | + /** @var UserMulti $user */ |
| 19 | + $user = UserMultiFactory::new()->create(); |
| 20 | + $wallet = $user->createWallet([ |
| 21 | + 'name' => 'Credit USD', |
| 22 | + 'slug' => 'credit-usd', |
| 23 | + 'meta' => ['credit' => 10000, 'currency' => 'USD'], |
| 24 | + ]); |
| 25 | + |
| 26 | + $transaction = $wallet->deposit(1000); |
| 27 | + self::assertNotNull($transaction); |
| 28 | + |
| 29 | + self::assertSame(1000, $wallet->balanceInt); |
| 30 | + self::assertSame(10., (float) $wallet->balanceFloat); |
| 31 | + |
| 32 | + $transaction = $wallet->withdraw(10000); |
| 33 | + self::assertNotNull($transaction); |
| 34 | + self::assertSame(-9000, $wallet->balanceInt); |
| 35 | + } |
| 36 | + |
| 37 | + public function testCreditLimitBalanceZero(): void |
| 38 | + { |
| 39 | + /** @var UserMulti $user */ |
| 40 | + $user = UserMultiFactory::new()->create(); |
| 41 | + $wallet = $user->createWallet([ |
| 42 | + 'name' => 'Credit USD', |
| 43 | + 'slug' => 'credit-usd', |
| 44 | + 'meta' => ['credit' => 10000, 'currency' => 'USD'], |
| 45 | + ]); |
| 46 | + |
| 47 | + self::assertSame(0, $wallet->balanceInt); |
| 48 | + self::assertSame(0., (float) $wallet->balanceFloat); |
| 49 | + |
| 50 | + $transaction = $wallet->withdraw(10000); |
| 51 | + self::assertNotNull($transaction); |
| 52 | + self::assertSame(-10000, $wallet->balanceInt); |
| 53 | + } |
| 54 | +} |
0 commit comments