Skip to content

Commit

Permalink
Merge pull request #972 from bavix/971-bavixwalletexceptionsunconfirm…
Browse files Browse the repository at this point in the history
…edinvalid-confirmation-has-already-been-reset

allow deletion of unconfirmed operations without forceDelete
  • Loading branch information
rez1dent3 authored Jul 8, 2024
2 parents bda3ca1 + 270d348 commit 9eae261
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Internal/Observers/TransactionObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ final class TransactionObserver
*/
public function deleting(Transaction $model): bool
{
return $model->wallet->resetConfirm($model);
return $model->wallet->safeResetConfirm($model);
}
}
4 changes: 2 additions & 2 deletions src/Internal/Observers/TransferObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct(
public function deleting(Transfer $model): bool
{
return $this->atomicService->blocks([$model->from, $model->to], function () use ($model) {

Check warning on line 33 in src/Internal/Observers/TransferObserver.php

View workflow job for this annotation

GitHub Actions / units (8.3, testing, array, redis)

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ */ public function deleting(Transfer $model): bool { - return $this->atomicService->blocks([$model->from, $model->to], function () use ($model) { + return $this->atomicService->blocks([$model->to], function () use ($model) { return $model->from->safeResetConfirm($model->withdraw) && $model->to->safeResetConfirm($model->deposit); }); } }
return $model->from->resetConfirm($model->withdraw)
&& $model->to->resetConfirm($model->deposit);
return $model->from->safeResetConfirm($model->withdraw)
&& $model->to->safeResetConfirm($model->deposit);
});
}
}
4 changes: 4 additions & 0 deletions src/Traits/CanConfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function safeConfirm(Transaction $transaction): bool
{
try {
return $this->confirm($transaction);
} catch (ConfirmedInvalid) {
return true;
} catch (ExceptionInterface) {
return false;
}
Expand Down Expand Up @@ -99,6 +101,8 @@ public function safeResetConfirm(Transaction $transaction): bool
{
try {
return $this->resetConfirm($transaction);
} catch (UnconfirmedInvalid) {
return true;
} catch (ExceptionInterface) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Units/Domain/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testSafeUnconfirmed(): void
$transaction = $wallet->deposit(1000, null, false);
self::assertSame(0, $wallet->balanceInt);
self::assertFalse($transaction->confirmed);
self::assertFalse($wallet->safeResetConfirm($transaction));
self::assertTrue($wallet->safeResetConfirm($transaction));
}

public function testWalletOwnerInvalid(): void
Expand Down
5 changes: 0 additions & 5 deletions tests/Units/Domain/SoftDeletesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Bavix\Wallet\Test\Units\Domain;

use Bavix\Wallet\Exceptions\UnconfirmedInvalid;
use Bavix\Wallet\Test\Infra\Factories\BuyerFactory;
use Bavix\Wallet\Test\Infra\Models\Buyer;
use Bavix\Wallet\Test\Infra\TestCase;
Expand Down Expand Up @@ -87,8 +86,6 @@ public function testTransactionDelete(): void

public function testTransactionDeleteIfNotConfirmed(): void
{
$this->expectException(UnconfirmedInvalid::class);

/** @var Buyer $buyer */
$buyer = BuyerFactory::new()->create();
self::assertFalse($buyer->relationLoaded('wallet'));
Expand Down Expand Up @@ -141,8 +138,6 @@ public function testTransferDelete(): void

public function testTransferDeleteIfNotConfirmed(): void
{
$this->expectException(UnconfirmedInvalid::class);

/** @var Buyer $user1 */
/** @var Buyer $user2 */
[$user1, $user2] = BuyerFactory::times(2)->create();
Expand Down

0 comments on commit 9eae261

Please sign in to comment.