From e7de267aeced52d183c870d14beb3284d58b876b Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Sat, 20 Apr 2024 07:43:15 +0300 Subject: [PATCH 1/2] Frozen balance (demo) #939 --- tests/Units/Domain/CreditWalletTest.php | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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)); + } } From 432aab28cf7a05d769ee8d11aa02e457c77e894a Mon Sep 17 00:00:00 2001 From: Github bot Date: Sat, 20 Apr 2024 04:47:02 +0000 Subject: [PATCH 2/2] autofix --- tests/Units/Domain/CreditWalletTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Units/Domain/CreditWalletTest.php b/tests/Units/Domain/CreditWalletTest.php index 14b1bdc8a..18028788a 100644 --- a/tests/Units/Domain/CreditWalletTest.php +++ b/tests/Units/Domain/CreditWalletTest.php @@ -10,7 +10,6 @@ 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