Add tests for ticket validity and event date formatting

- Create TicketValiditySchemaTest to verify database schema for ticket validity.
- Update CatalogModelsTest to include tests for event date attributes and selection options.
- Introduce EventDateTextFormatterTest for formatting event dates in Spanish.
- Refactor EventModelsTest to include validity time relationships.
- Add SaleDetailResourceTest to ensure correct serialization of purchase items.
- Enhance TicketTest with validity time checks and status management.
- Implement ValidityTimeResourceTest to validate resource output for different validity types.
- Add ValidityTimeTest to verify casting and validity checks for validity time types.
This commit is contained in:
2026-08-11 12:41:35 -03:00
parent b294e5c46e
commit 02cf3f3773
166 changed files with 10203 additions and 1849 deletions

View File

@@ -32,14 +32,12 @@ class CatalogItemControllerTest extends TestCase
'slug' => 'shirt',
'nombre' => 'Shirt',
'precio' => 100,
'minimum_use_date' => '2026-08-01 09:00:00',
'maximum_use_date' => '2026-08-31 18:00:00',
'max_units_per_user' => 4,
'attribute_codes' => [$attribute->codigo],
'images' => [$image, $image],
'variants' => [
[
'real_stock' => 5,
'maximum_use_date' => '2026-08-15 18:00:00',
'values' => ['size' => 'M'],
'images' => [$image],
],
@@ -49,27 +47,16 @@ class CatalogItemControllerTest extends TestCase
$response
->assertCreated()
->assertJsonPath('data.nombre', 'Shirt')
->assertJsonPath('data.max_units_per_user', 4)
->assertJsonCount(2, 'data.images')
->assertJsonCount(1, 'data.variants')
->assertJsonCount(1, 'data.variants.0.images')
->assertJsonPath('data.variants.0.minimum_use_date', null)
->assertJsonPath(
'data.variants.0.maximum_use_date',
fn (string $value): bool => str_starts_with($value, '2026-08-15T18:00:00'),
)
->assertJsonPath(
'data.variants.0.effective_minimum_use_date',
fn (string $value): bool => str_starts_with($value, '2026-08-01T09:00:00'),
)
->assertJsonPath(
'data.variants.0.effective_maximum_use_date',
fn (string $value): bool => str_starts_with($value, '2026-08-15T18:00:00'),
);
->assertJsonCount(1, 'data.variants.0.images');
$item = CatalogItem::query()->where('slug', 'shirt')->firstOrFail();
$variant = $item->variants()->firstOrFail();
$this->assertSame([0, 1], $item->attachments()->get()->pluck('pivot.orden')->all());
$this->assertSame(4, $item->max_units_per_user);
$this->assertSame([0], $variant->attachments()->get()->pluck('pivot.orden')->all());
$this->assertDatabaseHas('catalog_items_attachments', [
'catalog_item_id' => $item->id,
@@ -93,6 +80,21 @@ class CatalogItemControllerTest extends TestCase
$this->assertDatabaseMissing('catalog_items', ['slug' => 'invalid-image']);
}
public function test_it_rejects_a_non_positive_user_purchase_limit(): void
{
$tenant = $this->createTenant('purchase-limit-validation');
$this->postJson("/api/tenants/{$tenant->codigo}/catalog-items", [
'slug' => 'invalid-purchase-limit',
'nombre' => 'Invalid purchase limit',
'precio' => 100,
'real_stock' => 10,
'max_units_per_user' => 0,
])->assertUnprocessable()->assertJsonValidationErrors('max_units_per_user');
$this->assertDatabaseMissing('catalog_items', ['slug' => 'invalid-purchase-limit']);
}
private function createTenant(string $code = 'catalog-controller'): Tenant
{
$headerLogo = $this->createAttachment("{$code}-header");