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:
@@ -48,8 +48,15 @@ class CatalogControllerTest extends TestCase
|
||||
'real_stock' => 4,
|
||||
'reserved_stock' => 1,
|
||||
]);
|
||||
$unavailableInventory = Inventory::query()->create([
|
||||
'real_stock' => 2,
|
||||
'reserved_stock' => 2,
|
||||
]);
|
||||
$variantItem->variants()->create(['inventory_id' => $firstInventory->id]);
|
||||
$variantItem->variants()->create(['inventory_id' => $secondInventory->id]);
|
||||
$unavailableVariant = $variantItem->variants()->create([
|
||||
'inventory_id' => $unavailableInventory->id,
|
||||
]);
|
||||
$cart->featuredItems()->create(['catalog_item_id' => $variantItem->id]);
|
||||
|
||||
$response = $this->getJson("/api/tenants/{$tenant->codigo}/catalog");
|
||||
@@ -67,11 +74,45 @@ class CatalogControllerTest extends TestCase
|
||||
->assertJsonCount(2, '0.items.0.variants')
|
||||
->assertJsonPath('0.items.0.variants.0.stock_tecnico', 4)
|
||||
->assertJsonPath('0.items.0.variants.1.stock_tecnico', 3)
|
||||
->assertJsonMissing(['id' => $unavailableVariant->id, 'stock_tecnico' => 0])
|
||||
->assertJsonPath('1.title', 'Row')
|
||||
->assertJsonPath('1.items.data.0.stock_tecnico', 8)
|
||||
->assertJsonCount(0, '1.items.data.0.variants');
|
||||
}
|
||||
|
||||
public function test_it_excludes_items_when_all_of_their_variants_are_out_of_stock(): void
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-available-variants');
|
||||
$group = $this->createGroup(
|
||||
$tenant,
|
||||
ProductLayout::ColumnWithCart,
|
||||
'Available variants',
|
||||
groupLayout: GroupLayout::SimpleVertical,
|
||||
);
|
||||
|
||||
$unavailableItem = $this->createItem($tenant, 'Unavailable');
|
||||
$unavailableInventory = Inventory::query()->create([
|
||||
'real_stock' => 4,
|
||||
'reserved_stock' => 4,
|
||||
]);
|
||||
$unavailableItem->variants()->create(['inventory_id' => $unavailableInventory->id]);
|
||||
$group->featuredItems()->create(['catalog_item_id' => $unavailableItem->id]);
|
||||
|
||||
$availableItem = $this->createItem($tenant, 'Available');
|
||||
$availableInventory = Inventory::query()->create([
|
||||
'real_stock' => 4,
|
||||
'reserved_stock' => 3,
|
||||
]);
|
||||
$availableItem->variants()->create(['inventory_id' => $availableInventory->id]);
|
||||
$group->featuredItems()->create(['catalog_item_id' => $availableItem->id]);
|
||||
|
||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||
->assertOk()
|
||||
->assertJsonCount(1, '0.items')
|
||||
->assertJsonPath('0.items.0.nombre', 'Available')
|
||||
->assertJsonMissing(['nombre' => 'Unavailable']);
|
||||
}
|
||||
|
||||
public function test_column_with_image_uses_item_image_then_variant_image_then_null(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -45,7 +45,7 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
$this->assertStringContainsString($itemImage->path, $response->json('data.images.0'));
|
||||
}
|
||||
|
||||
public function test_it_selects_the_first_variant_and_returns_its_images_by_default(): void
|
||||
public function test_it_filters_unavailable_variants_and_selects_the_first_available_one(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
$tenant = $this->createTenant('detail-default');
|
||||
@@ -66,14 +66,21 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJsonPath('data.selected_variant.id', $firstVariant->id)
|
||||
->assertJsonPath('data.selected_variant.stock_tecnico', 0)
|
||||
->assertJsonCount(1, 'data.variants')
|
||||
->assertJsonPath('data.variants.0.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.stock_tecnico', 6)
|
||||
->assertJsonCount(1, 'data.selected_variant.images');
|
||||
$response
|
||||
->assertJsonMissingPath('data.stock_tecnico')
|
||||
->assertJsonMissingPath('data.images');
|
||||
$this->assertStringContainsString($firstImage->path, $response->json('data.selected_variant.images.0'));
|
||||
$this->assertStringContainsString($secondImage->path, $response->json('data.selected_variant.images.0'));
|
||||
$this->assertStringNotContainsString($firstImage->path, $response->json('data.selected_variant.images.0'));
|
||||
$this->assertStringNotContainsString($itemImage->path, $response->json('data.selected_variant.images.0'));
|
||||
|
||||
$this->getJson(
|
||||
"/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}?variant_id={$firstVariant->id}"
|
||||
)->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_it_selects_the_requested_variant_and_lists_variant_values_and_stock(): void
|
||||
@@ -117,17 +124,20 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertOk()
|
||||
->assertJsonPath('data.variants.0.id', $firstVariant->id)
|
||||
->assertJsonPath('data.variants.0.stock_tecnico', 4)
|
||||
->assertJsonPath('data.variants.0.values.size', 'S')
|
||||
->assertJsonPath('data.variants.0.values.size.value', 'S')
|
||||
->assertJsonPath('data.variants.0.values.size.label', 'Small')
|
||||
->assertJsonPath('data.variants.1.id', $secondVariant->id)
|
||||
->assertJsonPath('data.variants.1.stock_tecnico', 7)
|
||||
->assertJsonPath('data.variants.1.values.size', 'M')
|
||||
->assertJsonPath('data.variants.1.values.size.value', 'M')
|
||||
->assertJsonPath('data.variants.1.values.size.label', 'Medium')
|
||||
->assertJsonPath('data.attributes.0.codigo', 'size')
|
||||
->assertJsonPath('data.attributes.0.options.0.value', 'S')
|
||||
->assertJsonPath('data.attributes.0.options.1.value', 'M')
|
||||
->assertJsonCount(2, 'data.attributes.0.options')
|
||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.stock_tecnico', 7)
|
||||
->assertJsonPath('data.selected_variant.values.size', 'M')
|
||||
->assertJsonPath('data.selected_variant.values.size.value', 'M')
|
||||
->assertJsonPath('data.selected_variant.values.size.label', 'Medium')
|
||||
->assertJsonCount(1, 'data.selected_variant.images');
|
||||
$response
|
||||
->assertJsonMissingPath('data.stock_tecnico')
|
||||
@@ -170,6 +180,102 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertJsonPath('data.variants.0.stock_tecnico', null);
|
||||
}
|
||||
|
||||
public function test_it_exposes_event_dates_as_a_dynamic_variant_attribute(): void
|
||||
{
|
||||
$tenant = $this->createTenant('detail-event-date');
|
||||
$tenant->update([
|
||||
'event_title' => 'Festival',
|
||||
'event_location' => 'Rosario',
|
||||
]);
|
||||
$eventDate = $tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00',
|
||||
'time_end' => '18:00',
|
||||
]);
|
||||
$unusedEventDate = $tenant->eventDates()->create([
|
||||
'date' => '2026-10-10',
|
||||
'time_start' => '10:00',
|
||||
'time_end' => '19:00',
|
||||
]);
|
||||
$item = $this->createItem($tenant, 'Entry');
|
||||
$attribute = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'event_date',
|
||||
'nombre' => 'Fecha',
|
||||
'is_required' => true,
|
||||
'type' => FieldType::EventDate,
|
||||
]);
|
||||
$item->itemAttributes()->create(['attribute_id' => $attribute->id]);
|
||||
$variant = $this->createVariant($item, 10, 0);
|
||||
$variant->update(['event_date_id' => $eventDate->id]);
|
||||
|
||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.attributes.0.id', $attribute->id)
|
||||
->assertJsonPath('data.attributes.0.codigo', 'event_date')
|
||||
->assertJsonPath('data.attributes.0.type', 'event_date')
|
||||
->assertJsonCount(2, 'data.attributes.0.options')
|
||||
->assertJsonPath('data.attributes.0.options.0.id', $eventDate->id)
|
||||
->assertJsonPath('data.attributes.0.options.0.value', (string) $eventDate->id)
|
||||
->assertJsonPath('data.attributes.0.options.0.label', '09/10/2026')
|
||||
->assertJsonPath('data.attributes.0.options.0.validity_time_id', $eventDate->validity_time_id)
|
||||
->assertJsonPath('data.attributes.0.options.0.validity_time.type', 'fixed_window')
|
||||
->assertJsonPath('data.attributes.0.options.1.id', $unusedEventDate->id)
|
||||
->assertJsonPath('data.attributes.0.options.1.value', (string) $unusedEventDate->id)
|
||||
->assertJsonPath('data.variants.0.values.event_date.value', (string) $eventDate->id)
|
||||
->assertJsonPath(
|
||||
'data.variants.0.values.event_date.label',
|
||||
'09/10/2026',
|
||||
);
|
||||
|
||||
$this->assertDatabaseCount('attribute_options', 0);
|
||||
}
|
||||
|
||||
public function test_it_orders_item_attributes_by_sort_order_and_then_attribute_label(): void
|
||||
{
|
||||
$tenant = $this->createTenant('detail-attribute-order');
|
||||
$item = $this->createItem($tenant, 'Ordered attributes');
|
||||
$variant = $this->createVariant($item, 10, 0);
|
||||
|
||||
$attributes = collect([
|
||||
['code' => 'zeta', 'label' => 'Zeta', 'sort_order' => 2],
|
||||
['code' => 'priority', 'label' => 'Priority', 'sort_order' => 1],
|
||||
['code' => 'alpha', 'label' => 'Alpha', 'sort_order' => 2],
|
||||
])->mapWithKeys(function (array $data) use ($tenant, $item): array {
|
||||
$attribute = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => $data['code'],
|
||||
'nombre' => $data['label'],
|
||||
'type' => FieldType::String,
|
||||
]);
|
||||
$itemAttribute = $item->itemAttributes()->create([
|
||||
'attribute_id' => $attribute->id,
|
||||
'sort_order' => $data['sort_order'],
|
||||
]);
|
||||
|
||||
return [$data['code'] => $itemAttribute];
|
||||
});
|
||||
|
||||
foreach (['zeta', 'priority', 'alpha'] as $code) {
|
||||
$variant->definitions()->create([
|
||||
'item_attribute_id' => $attributes[$code]->id,
|
||||
'value' => $code,
|
||||
]);
|
||||
}
|
||||
|
||||
$response = $this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.attributes.0.codigo', 'priority')
|
||||
->assertJsonPath('data.attributes.0.sort_order', 1)
|
||||
->assertJsonPath('data.attributes.1.codigo', 'alpha')
|
||||
->assertJsonPath('data.attributes.2.codigo', 'zeta');
|
||||
|
||||
$this->assertSame(
|
||||
['priority', 'alpha', 'zeta'],
|
||||
array_keys($response->json('data.variants.0.values')),
|
||||
);
|
||||
}
|
||||
|
||||
private function createItem(
|
||||
Tenant $tenant,
|
||||
string $name,
|
||||
|
||||
@@ -24,6 +24,7 @@ class CatalogSchemaTest extends TestCase
|
||||
$this->assertFalse(Schema::hasTable('bundle_items'));
|
||||
$this->assertTrue(Schema::hasTable('variantes'));
|
||||
$this->assertTrue(Schema::hasTable('item_attributes'));
|
||||
$this->assertTrue(Schema::hasColumn('item_attributes', 'sort_order'));
|
||||
$this->assertTrue(Schema::hasTable('variant_values'));
|
||||
}
|
||||
|
||||
@@ -31,9 +32,8 @@ class CatalogSchemaTest extends TestCase
|
||||
{
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'validity_time_id',
|
||||
'tenant_code',
|
||||
'event_id',
|
||||
'event_product_type',
|
||||
'category_id',
|
||||
'brand_id',
|
||||
'inventory_id',
|
||||
@@ -43,9 +43,10 @@ class CatalogSchemaTest extends TestCase
|
||||
'descripcion',
|
||||
'precio',
|
||||
'inventory_policy',
|
||||
'max_units_per_user',
|
||||
'has_tickets',
|
||||
'maximum_use_date',
|
||||
'minimum_use_date',
|
||||
'ticket_generation_policy',
|
||||
'validity_time_id',
|
||||
], Schema::getColumnListing('catalog_items'));
|
||||
}
|
||||
|
||||
@@ -183,26 +184,25 @@ class CatalogSchemaTest extends TestCase
|
||||
{
|
||||
$this->assertTrue(Schema::hasColumns('variantes', [
|
||||
'event_date_id',
|
||||
'minimum_use_date',
|
||||
'maximum_use_date',
|
||||
]));
|
||||
}
|
||||
|
||||
public function test_events_and_event_dates_are_linked_to_the_catalog(): void
|
||||
public function test_event_configuration_and_dates_belong_to_the_tenant(): void
|
||||
{
|
||||
$this->assertFalse(Schema::hasTable('events'));
|
||||
$this->assertTrue(Schema::hasColumns('tenants', [
|
||||
'event_title',
|
||||
'event_location',
|
||||
'event_date_text',
|
||||
]));
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'tenant_code',
|
||||
'name',
|
||||
'address',
|
||||
], Schema::getColumnListing('events'));
|
||||
$this->assertEqualsCanonicalizing([
|
||||
'id',
|
||||
'event_id',
|
||||
'date',
|
||||
'time_start',
|
||||
'time_end',
|
||||
], Schema::getColumnListing('event_dates'));
|
||||
$this->assertTrue(Schema::hasColumn('tenants', 'active_event_id'));
|
||||
$this->assertFalse(Schema::hasColumn('catalog_items', 'event_id'));
|
||||
$this->assertFalse(Schema::hasColumn('compras', 'event_id'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ use App\Domains\Catalog\Services\CatalogService;
|
||||
use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -94,71 +93,138 @@ class CatalogServiceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_variant_use_dates_override_or_inherit_catalog_item_dates(): void
|
||||
public function test_it_allows_the_same_event_date_with_different_attribute_values(): void
|
||||
{
|
||||
$attribute = $this->createAttribute('day');
|
||||
$itemMinimum = Carbon::parse('2026-08-01 09:00:00');
|
||||
$itemMaximum = Carbon::parse('2026-08-31 18:00:00');
|
||||
$variantMaximum = Carbon::parse('2026-08-15 18:00:00');
|
||||
$sector = $this->createAttribute('sector');
|
||||
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
|
||||
$eventDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00',
|
||||
'time_end' => '18:00',
|
||||
]);
|
||||
|
||||
$item = $this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'dated-variants',
|
||||
'nombre' => 'Dated variants',
|
||||
'slug' => 'entry-by-sector',
|
||||
'nombre' => 'Entry by sector',
|
||||
'precio' => 100,
|
||||
'minimum_use_date' => $itemMinimum,
|
||||
'maximum_use_date' => $itemMaximum,
|
||||
'attribute_codes' => [$attribute->codigo],
|
||||
'attribute_codes' => [$eventDateAttribute->codigo, $sector->codigo],
|
||||
'variants' => [
|
||||
[
|
||||
'real_stock' => 5,
|
||||
'maximum_use_date' => $variantMaximum,
|
||||
'values' => [$attribute->codigo => 'Saturday'],
|
||||
'event_date_id' => $eventDate->id,
|
||||
'values' => ['sector' => 'General'],
|
||||
],
|
||||
[
|
||||
'event_date_id' => $eventDate->id,
|
||||
'values' => ['sector' => 'VIP'],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$variant = $item->variants->firstOrFail();
|
||||
|
||||
$this->assertNull($variant->minimum_use_date);
|
||||
$this->assertTrue($variant->maximum_use_date->equalTo($variantMaximum));
|
||||
$this->assertTrue($variant->getMinimumUseDate()->equalTo($itemMinimum));
|
||||
$this->assertTrue($variant->getMaximumUseDate()->equalTo($variantMaximum));
|
||||
$this->assertCount(2, $item->variants);
|
||||
$this->assertSame(
|
||||
[$eventDate->id, $eventDate->id],
|
||||
$item->variants->pluck('event_date_id')->all(),
|
||||
);
|
||||
$this->assertSame(
|
||||
['event_date', 'sector'],
|
||||
$item->itemAttributes->pluck('attribute.codigo')->all(),
|
||||
);
|
||||
$this->assertSame(
|
||||
FieldType::EventDate,
|
||||
$item->itemAttributes->first()->attribute->type,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_rejects_an_invalid_effective_variant_use_date_range(): void
|
||||
public function test_it_creates_a_variant_with_multiple_event_dates(): void
|
||||
{
|
||||
$attribute = $this->createAttribute('day');
|
||||
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
|
||||
$firstDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '00:00:00',
|
||||
'time_end' => '23:59:59',
|
||||
]);
|
||||
$secondDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-10',
|
||||
'time_start' => '00:00:00',
|
||||
'time_end' => '23:59:59',
|
||||
]);
|
||||
|
||||
$item = $this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'multi-date-pass',
|
||||
'nombre' => 'Multi-date pass',
|
||||
'precio' => 100,
|
||||
'attribute_codes' => [$eventDateAttribute->codigo],
|
||||
'multi_select_attribute_codes' => ['event_date'],
|
||||
'variants' => [[
|
||||
'real_stock' => 5,
|
||||
'event_date_ids' => [$secondDate->id, $firstDate->id],
|
||||
]],
|
||||
]);
|
||||
|
||||
$variant = $item->variants->sole();
|
||||
$this->assertNull($variant->event_date_id);
|
||||
$this->assertSame([$firstDate->id, $secondDate->id], $variant->eventDates->pluck('id')->all());
|
||||
$this->assertSame(
|
||||
[(string) $firstDate->id, (string) $secondDate->id],
|
||||
$variant->selectionValues()->get('event_date'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_creates_multiple_values_for_any_multi_select_attribute(): void
|
||||
{
|
||||
$color = $this->createAttribute('color', FieldType::Select);
|
||||
$color->options()->createMany([
|
||||
['value' => 'Green', 'label' => 'Green', 'sort_order' => 1],
|
||||
['value' => 'White', 'label' => 'White', 'sort_order' => 2],
|
||||
]);
|
||||
|
||||
$item = $this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'multi-color-shirt',
|
||||
'nombre' => 'Multi-color shirt',
|
||||
'precio' => 100,
|
||||
'attribute_codes' => ['color'],
|
||||
'multi_select_attribute_codes' => ['color'],
|
||||
'variants' => [[
|
||||
'real_stock' => 5,
|
||||
'values' => ['color' => ['White', 'Green']],
|
||||
]],
|
||||
]);
|
||||
|
||||
$variant = $item->variants->sole();
|
||||
$this->assertSame(['White', 'Green'], $variant->definitions->pluck('value')->all());
|
||||
$this->assertSame(['White', 'Green'], $variant->selectionValues()->get('color'));
|
||||
}
|
||||
|
||||
public function test_it_rejects_duplicate_variant_combinations(): void
|
||||
{
|
||||
$sector = $this->createAttribute('sector');
|
||||
$eventDateAttribute = $this->createAttribute('event_date', FieldType::EventDate);
|
||||
$eventDate = $this->tenant->eventDates()->create([
|
||||
'date' => '2026-10-09',
|
||||
'time_start' => '09:00',
|
||||
'time_end' => '18:00',
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->service->create([
|
||||
'tenant_code' => $this->tenant->codigo,
|
||||
'slug' => 'invalid-dated-variant',
|
||||
'nombre' => 'Invalid dated variant',
|
||||
'slug' => 'duplicate-entry',
|
||||
'nombre' => 'Duplicate entry',
|
||||
'precio' => 100,
|
||||
'minimum_use_date' => '2026-08-10 09:00:00',
|
||||
'maximum_use_date' => '2026-08-31 18:00:00',
|
||||
'attribute_codes' => [$attribute->codigo],
|
||||
'attribute_codes' => [$eventDateAttribute->codigo, $sector->codigo],
|
||||
'variants' => [
|
||||
[
|
||||
'real_stock' => 5,
|
||||
'maximum_use_date' => '2026-08-09 18:00:00',
|
||||
'values' => [$attribute->codigo => 'Saturday'],
|
||||
],
|
||||
['event_date_id' => $eventDate->id, 'values' => ['sector' => 'VIP']],
|
||||
['event_date_id' => $eventDate->id, 'values' => ['sector' => ' vip ']],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->fail('A validation exception was not thrown.');
|
||||
} catch (ValidationException $exception) {
|
||||
$this->assertArrayHasKey(
|
||||
'variants.0.maximum_use_date',
|
||||
$exception->errors(),
|
||||
);
|
||||
$this->assertArrayHasKey('variants.1', $exception->errors());
|
||||
}
|
||||
|
||||
$this->assertDatabaseMissing('catalog_items', [
|
||||
'slug' => 'invalid-dated-variant',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_rejects_direct_inventory_together_with_variants(): void
|
||||
@@ -283,13 +349,15 @@ class CatalogServiceTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
private function createAttribute(string $code): Attribute
|
||||
{
|
||||
private function createAttribute(
|
||||
string $code,
|
||||
FieldType $type = FieldType::String,
|
||||
): Attribute {
|
||||
return Attribute::query()->create([
|
||||
'tenant_codigo' => $this->tenant->codigo,
|
||||
'codigo' => $code,
|
||||
'nombre' => ucfirst($code),
|
||||
'type' => FieldType::String,
|
||||
'type' => $type,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user