|
8 | 8 | use Bavix\Wallet\Exceptions\UnconfirmedInvalid;
|
9 | 9 | use Bavix\Wallet\Exceptions\WalletOwnerInvalid;
|
10 | 10 | use Bavix\Wallet\Internal\Exceptions\ExceptionInterface;
|
| 11 | +use Bavix\Wallet\Internal\Service\DatabaseServiceInterface; |
11 | 12 | use Bavix\Wallet\Services\BookkeeperServiceInterface;
|
12 | 13 | use Bavix\Wallet\Services\RegulatorServiceInterface;
|
13 | 14 | use Bavix\Wallet\Test\Infra\Factories\BuyerFactory;
|
14 | 15 | use Bavix\Wallet\Test\Infra\Factories\UserConfirmFactory;
|
| 16 | +use Bavix\Wallet\Test\Infra\Factories\UserFactory; |
15 | 17 | use Bavix\Wallet\Test\Infra\Models\Buyer;
|
| 18 | +use Bavix\Wallet\Test\Infra\Models\User; |
16 | 19 | use Bavix\Wallet\Test\Infra\Models\UserConfirm;
|
17 | 20 | use Bavix\Wallet\Test\Infra\TestCase;
|
18 | 21 |
|
@@ -251,4 +254,45 @@ public function testUserConfirmByWallet(): void
|
251 | 254 | self::assertTrue($userConfirm->wallet->confirm($transaction));
|
252 | 255 | self::assertTrue($transaction->confirmed);
|
253 | 256 | }
|
| 257 | + |
| 258 | + public function testTransactionResetConfirmWalletOwnerInvalid(): void |
| 259 | + { |
| 260 | + $this->expectException(WalletOwnerInvalid::class); |
| 261 | + $this->expectExceptionCode(ExceptionInterface::WALLET_OWNER_INVALID); |
| 262 | + $this->expectExceptionMessageStrict(trans('wallet::errors.owner_invalid')); |
| 263 | + |
| 264 | + /** |
| 265 | + * @var User $user1 |
| 266 | + * @var User $user2 |
| 267 | + */ |
| 268 | + [$user1, $user2] = UserFactory::times(2)->create(); |
| 269 | + $user1->deposit(1000); |
| 270 | + |
| 271 | + self::assertSame(1000, $user1->balanceInt); |
| 272 | + |
| 273 | + $transfer = $user1->transfer($user2, 500); |
| 274 | + $user1->wallet->resetConfirm($transfer->deposit); |
| 275 | + } |
| 276 | + |
| 277 | + public function testTransactionResetConfirmSuccess(): void |
| 278 | + { |
| 279 | + /** |
| 280 | + * @var User $user1 |
| 281 | + * @var User $user2 |
| 282 | + */ |
| 283 | + [$user1, $user2] = UserFactory::times(2)->create(); |
| 284 | + $user1->deposit(1000); |
| 285 | + |
| 286 | + self::assertSame(1000, $user1->balanceInt); |
| 287 | + app(DatabaseServiceInterface::class)->transaction(static function () use ($user1, $user2) { |
| 288 | + $transfer = $user1->transfer($user2, 500); |
| 289 | + self::assertTrue($user2->wallet->resetConfirm($transfer->deposit)); // confirm => false |
| 290 | + }); |
| 291 | + |
| 292 | + self::assertSame(500, (int) $user1->transactions()->sum('amount')); |
| 293 | + self::assertSame(500, (int) $user2->transactions()->sum('amount')); |
| 294 | + |
| 295 | + self::assertSame(500, $user1->balanceInt); |
| 296 | + self::assertSame(0, $user2->balanceInt); |
| 297 | + } |
254 | 298 | }
|
0 commit comments