diff --git a/tests/Units/Domain/CreditWalletTest.php b/tests/Units/Domain/CreditWalletTest.php index da0268a70..14b1bdc8a 100644 --- a/tests/Units/Domain/CreditWalletTest.php +++ b/tests/Units/Domain/CreditWalletTest.php @@ -4,9 +4,13 @@ namespace Bavix\Wallet\Test\Units\Domain; +use Bavix\Wallet\Services\AtomicServiceInterface; +use Bavix\Wallet\Test\Infra\Factories\BuyerFactory; use Bavix\Wallet\Test\Infra\Factories\UserMultiFactory; +use Bavix\Wallet\Test\Infra\Models\Buyer; use Bavix\Wallet\Test\Infra\Models\UserMulti; use Bavix\Wallet\Test\Infra\TestCase; +use Illuminate\Support\Facades\DB; /** * @internal @@ -60,4 +64,28 @@ public function testCreditLimitBalanceZero(): void self::assertNotNull($transaction); self::assertSame(-10000, $wallet->balanceInt); } + + public function testFrozenBalance(): void + { + /** @var Buyer $user */ + $user = BuyerFactory::new()->create(); + + self::assertFalse($user->relationLoaded('wallet')); + self::assertEquals(0, $user->wallet->balanceInt); + + app(AtomicServiceInterface::class)->block($user, function () use ($user) { + $user->deposit(1000); + + $meta = $user->wallet->meta ?? []; + $meta['credit'] = ($meta['credit'] ?? 0) - 1000; + + $user->wallet->meta = $meta; + $user->wallet->saveOrFail(); + }); + + self::assertEquals(1000, $user->wallet->balanceInt); + self::assertEquals(-1000.0, (float) $user->wallet->getCreditAttribute()); + + self::assertFalse($user->canWithdraw(1)); + } }