feat(sale): implement modifications filtering and validation for admin sales
This commit is contained in:
@@ -11,6 +11,8 @@ use App\Domains\Cart\Models\CartItem;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Logging\Enums\ValueChangeActorType;
|
||||
use App\Domains\Logging\Models\ValueChange;
|
||||
use App\Domains\Purchase\Events\PurchasePaid;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Purchase\Models\PurchaseItem;
|
||||
@@ -36,6 +38,96 @@ class AdminAppSaleControllerTest extends TestCase
|
||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||
}
|
||||
|
||||
public function test_sale_modifications_use_sale_filters_and_resulting_status(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
$otherTenant = $this->createTenant('other');
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$sale = Purchase::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'nombre_apellido' => 'Ana Pérez',
|
||||
'status' => Purchase::STATUS_CANCELLED,
|
||||
'total' => '10000.00',
|
||||
]);
|
||||
Purchase::query()->whereKey($sale->id)->update([
|
||||
'created_at' => '2026-08-04 10:00:00',
|
||||
]);
|
||||
|
||||
$otherSale = Purchase::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'nombre_apellido' => 'Otro cliente',
|
||||
'status' => Purchase::STATUS_PAID,
|
||||
'total' => '20000.00',
|
||||
]);
|
||||
Purchase::query()->whereKey($otherSale->id)->update([
|
||||
'created_at' => '2026-08-05 10:00:00',
|
||||
]);
|
||||
|
||||
$confirmedChange = ValueChange::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'trackable_type' => $sale->getMorphClass(),
|
||||
'trackable_id' => $sale->id,
|
||||
'attribute' => 'status',
|
||||
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'new_value' => Purchase::STATUS_PAID,
|
||||
'changed_at' => '2026-08-06 10:00:00',
|
||||
'actor_type' => ValueChangeActorType::User,
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
ValueChange::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'trackable_type' => $sale->getMorphClass(),
|
||||
'trackable_id' => $sale->id,
|
||||
'attribute' => 'status',
|
||||
'old_value' => Purchase::STATUS_PAID,
|
||||
'new_value' => Purchase::STATUS_CANCELLED,
|
||||
'changed_at' => '2026-08-07 10:00:00',
|
||||
'actor_type' => ValueChangeActorType::User,
|
||||
'user_id' => $admin->id,
|
||||
]);
|
||||
ValueChange::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'trackable_type' => $otherSale->getMorphClass(),
|
||||
'trackable_id' => $otherSale->id,
|
||||
'attribute' => 'status',
|
||||
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'new_value' => Purchase::STATUS_PAID,
|
||||
'changed_at' => '2026-08-08 10:00:00',
|
||||
'actor_type' => ValueChangeActorType::System,
|
||||
]);
|
||||
ValueChange::query()->create([
|
||||
'tenant_code' => $otherTenant->codigo,
|
||||
'trackable_type' => $sale->getMorphClass(),
|
||||
'trackable_id' => $sale->id,
|
||||
'attribute' => 'status',
|
||||
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'new_value' => Purchase::STATUS_PAID,
|
||||
'changed_at' => '2026-08-09 10:00:00',
|
||||
'actor_type' => ValueChangeActorType::System,
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/sales/modifications?'.http_build_query([
|
||||
'q' => 'Ana',
|
||||
'id' => $sale->id,
|
||||
'sale_date' => '2026-08-04',
|
||||
'status' => Purchase::ADMIN_STATUS_CONFIRMED,
|
||||
]))
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.id', $confirmedChange->id)
|
||||
->assertJsonPath('data.0.new_value', Purchase::STATUS_PAID)
|
||||
->assertJsonPath('data.0.admin_status', Purchase::ADMIN_STATUS_CONFIRMED);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/sales/modifications?status='.
|
||||
Purchase::ADMIN_STATUS_CANCELLED)
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.sale_id', $sale->id)
|
||||
->assertJsonPath('data.0.new_value', Purchase::STATUS_CANCELLED);
|
||||
}
|
||||
|
||||
public function test_sales_list_uses_purchase_item_snapshots_for_every_status(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
|
||||
Reference in New Issue
Block a user