Refactor ticket validity handling and improve tests

- Updated tests for Accommodation, Entry, Food, Merchandise, and Sale controllers to use soft deletes for variants and ensure proper inventory counts.
- Enhanced ticket generation logic to resolve validity from soft-deleted catalog sources.
- Introduced a new TicketValidityResolver service to manage ticket validity based on event dates and variant definitions.
- Removed unnecessary database assertions and improved the clarity of validity checks in tests.
- Added comprehensive tests for the new TicketValidityResolver service, ensuring correct handling of event dates and multi-select options.
- Cleaned up unused code and assertions in existing tests for better maintainability.
This commit is contained in:
2026-08-14 09:00:51 -03:00
parent bfdaf1c38b
commit 573d4fe5e6
59 changed files with 1185 additions and 679 deletions

View File

@@ -93,6 +93,89 @@ class CatalogServiceTest extends TestCase
}
}
public function test_it_soft_deletes_an_item_and_its_variants_without_removing_their_sources(): void
{
$attribute = $this->createAttribute('size');
$item = $this->service->create([
'tenant_code' => $this->tenant->codigo,
'slug' => 'archived-item',
'nombre' => 'Archived item',
'precio' => 100,
'attribute_codes' => [$attribute->codigo],
'variants' => [[
'real_stock' => 5,
'values' => [$attribute->codigo => 'M'],
]],
]);
$variant = $item->variants->sole();
$this->service->delete($item);
$this->assertSoftDeleted('catalog_items', ['id' => $item->id]);
$this->assertSoftDeleted('variantes', ['id' => $variant->id]);
$this->assertDatabaseHas('inventories', ['id' => $variant->inventory_id]);
$this->assertDatabaseHas('variant_values', [
'variant_id' => $variant->id,
'value' => 'M',
]);
$this->assertNull(CatalogItem::query()->find($item->id));
$this->assertNull(Variant::query()->find($variant->id));
$this->assertNotNull(CatalogItem::withTrashed()->find($item->id));
$this->assertNotNull(Variant::withTrashed()->find($variant->id));
}
public function test_deleting_the_last_variant_soft_deletes_its_catalog_item(): void
{
$attribute = $this->createAttribute('size');
$item = $this->service->create([
'tenant_code' => $this->tenant->codigo,
'slug' => 'last-variant',
'nombre' => 'Last variant',
'precio' => 100,
'attribute_codes' => [$attribute->codigo],
'variants' => [[
'real_stock' => 5,
'values' => [$attribute->codigo => 'M'],
]],
]);
$variant = $item->variants->sole();
$this->service->deleteVariant($variant);
$this->assertSoftDeleted('variantes', ['id' => $variant->id]);
$this->assertSoftDeleted('catalog_items', ['id' => $item->id]);
$this->assertDatabaseHas('inventories', ['id' => $variant->inventory_id]);
}
public function test_deleting_a_variant_keeps_the_item_active_when_an_inherited_price_variant_remains(): void
{
$attribute = $this->createAttribute('size');
$item = $this->service->create([
'tenant_code' => $this->tenant->codigo,
'slug' => 'remaining-variant',
'nombre' => 'Remaining variant',
'precio' => 100,
'attribute_codes' => [$attribute->codigo],
'variants' => [
[
'real_stock' => 5,
'values' => [$attribute->codigo => 'M'],
],
[
'real_stock' => 5,
'values' => [$attribute->codigo => 'L'],
],
],
]);
$deletedVariant = $item->variants->first();
$this->service->deleteVariant($deletedVariant);
$this->assertSoftDeleted('variantes', ['id' => $deletedVariant->id]);
$this->assertFalse($item->fresh()->trashed());
$this->assertSame(1, $item->variants()->count());
}
public function test_it_can_hide_an_item_attribute_from_the_product_selector(): void
{
$attribute = $this->createAttribute('internal_type');