feat(ticket): add refundable terminal states

This commit is contained in:
2026-09-10 16:10:08 -03:00
parent 1564985259
commit 18f739b712
5 changed files with 208 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ 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 App\Domains\Ticket\Models\Ticket;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
@@ -52,6 +53,16 @@ class LogsValueChangesTest extends TestCase
$table->timestamps();
});
Schema::create('tickets', function (Blueprint $table): void {
$table->id();
$table->string('tenant_code');
$table->uuid('ticket');
$table->dateTime('used_at')->nullable();
$table->dateTime('disabled_at')->nullable();
$table->dateTime('cancelled_at')->nullable();
$table->dateTime('refunded_at')->nullable();
});
$migration = require database_path('migrations/2026_08_03_000200_create_value_changes_table.php');
$migration->up();
$tenantMigration = require database_path('migrations/2026_08_04_000000_add_tenant_code_to_value_changes_table.php');
@@ -144,6 +155,26 @@ class LogsValueChangesTest extends TestCase
'user_id' => null,
]);
}
public function test_ticket_logs_its_status_changes(): void
{
$ticket = Ticket::query()->create([
'tenant_code' => 'test',
'ticket' => '794606d5-5f69-458d-9de7-03494757d626',
]);
$ticket->update(['disabled_at' => now()]);
$this->assertDatabaseHas('value_changes', [
'tenant_code' => 'test',
'trackable_type' => $ticket->getMorphClass(),
'trackable_id' => $ticket->id,
'attribute' => 'disabled_at',
'old_value' => null,
'actor_type' => ValueChangeActorType::System->value,
'user_id' => null,
]);
}
}
#[Fillable(['name', 'price', 'description'])]