Skip to content

allow deletion of unconfirmed operations without forceDelete #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -30,9 +30,9 @@
*/
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
Loading