Skip to content

Commit

Permalink
Frozen balance (demo) #939
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Apr 20, 2024
1 parent 41dac42 commit e7de267
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/Units/Domain/CreditWalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}

0 comments on commit e7de267

Please sign in to comment.