feat: Remove 'in_review' status from purchase workflow; implement logging for status changes and update related tests
This commit is contained in:
@@ -100,7 +100,7 @@ class TelepagosWebhookTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_transfer_webhook_matches_purchase_in_review_by_dni_and_total_amount(): void
|
||||
public function test_transfer_webhook_matches_pending_purchase_by_dni_and_total_amount(): void
|
||||
{
|
||||
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$this->configureTelepagosIntegration($tenant);
|
||||
@@ -122,8 +122,6 @@ class TelepagosWebhookTest extends TestCase
|
||||
'12345678'
|
||||
);
|
||||
|
||||
$matchingPurchase->update(['status' => Purchase::STATUS_IN_REVIEW]);
|
||||
|
||||
$newerPurchase = $this->createPendingTransferPurchase(
|
||||
$tenant,
|
||||
$newerUser->id,
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Logging;
|
||||
use App\Domains\Logging\Enums\ValueChangeActorType;
|
||||
use App\Domains\Logging\Models\Concerns\LogsValueChanges;
|
||||
use App\Domains\Logging\Models\ValueChange;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@@ -37,6 +38,12 @@ class LogsValueChangesTest extends TestCase
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('compras', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('status')->default(Purchase::STATUS_CREATED);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
$migration = require database_path('migrations/2026_08_03_000200_create_value_changes_table.php');
|
||||
$migration->up();
|
||||
}
|
||||
@@ -103,6 +110,27 @@ class LogsValueChangesTest extends TestCase
|
||||
|
||||
$this->assertDatabaseCount('value_changes', 0);
|
||||
}
|
||||
|
||||
public function test_purchase_logs_its_status_changes(): void
|
||||
{
|
||||
$purchase = Purchase::query()->create([
|
||||
'status' => Purchase::STATUS_CREATED,
|
||||
]);
|
||||
|
||||
$purchase->update([
|
||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('value_changes', [
|
||||
'trackable_type' => $purchase->getMorphClass(),
|
||||
'trackable_id' => $purchase->id,
|
||||
'attribute' => 'status',
|
||||
'old_value' => Purchase::STATUS_CREATED,
|
||||
'new_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'actor_type' => ValueChangeActorType::System->value,
|
||||
'user_id' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
#[Fillable(['name', 'price', 'description'])]
|
||||
|
||||
@@ -472,9 +472,18 @@ class StorePurchaseTest extends TestCase
|
||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'payment_method' => 'transfer',
|
||||
]);
|
||||
$this->assertDatabaseHas('value_changes', [
|
||||
'trackable_type' => (new Purchase)->getMorphClass(),
|
||||
'trackable_id' => $purchaseId,
|
||||
'attribute' => 'status',
|
||||
'old_value' => Purchase::STATUS_CREATED,
|
||||
'new_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'actor_type' => 'user',
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_submits_a_pending_purchase_for_review_idempotently(): void
|
||||
public function test_it_keeps_a_submitted_purchase_pending_payment_idempotently(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$user = User::factory()->create();
|
||||
@@ -492,24 +501,24 @@ class StorePurchaseTest extends TestCase
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->postJson($url)
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW)
|
||||
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT)
|
||||
->assertJsonPath('data.expires_at', null);
|
||||
|
||||
$this->assertDatabaseHas('compras', [
|
||||
'id' => $purchase->id,
|
||||
'status' => Purchase::STATUS_IN_REVIEW,
|
||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'expires_at' => null,
|
||||
]);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->postJson($url)
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW);
|
||||
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->postJson("/api/tenants/sonder/compras/{$purchase->id}/complete")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW);
|
||||
->assertJsonPath('data.status', Purchase::STATUS_PENDING_PAYMENT);
|
||||
}
|
||||
|
||||
public function test_it_rejects_review_for_a_purchase_that_is_not_awaiting_payment(): void
|
||||
|
||||
Reference in New Issue
Block a user