feat(catalog): add tenant-scoped product attributes and variant definitions

This commit is contained in:
2026-06-24 15:08:13 -03:00
parent 689d115a8f
commit c6e5177df1
15 changed files with 630 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
<?php
namespace Tests\Feature\Catalog;
use App\Domains\Tenant\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ProductAttributeControllerTest extends TestCase
{
use RefreshDatabase;
public function test_it_creates_a_select_attribute_with_options(): void
{
Tenant::create([
'codigo' => 'acme',
'nombre' => 'Acme',
'dominio' => 'acme.com',
]);
$response = $this->postJson('/api/product-attributes', [
'tenant_codigo' => 'acme',
'codigo' => 'color',
'nombre' => 'Color',
'is_required' => true,
'type' => 'select',
'metadata_schema' => [
'swatch' => ['type' => 'hex'],
],
'options' => [
[
'label' => 'Red',
'sort_order' => 1,
'metadata' => ['hex' => '#ff0000'],
],
[
'label' => 'Blue',
'sort_order' => 2,
'metadata' => ['hex' => '#0000ff'],
],
],
]);
$response
->assertCreated()
->assertJsonPath('tenant_codigo', 'acme')
->assertJsonPath('codigo', 'color')
->assertJsonPath('type', 'select')
->assertJsonPath('options.0.label', 'Red')
->assertJsonPath('options.1.metadata.hex', '#0000ff');
$this->assertDatabaseHas('productos_attributes', [
'tenant_codigo' => 'acme',
'codigo' => 'color',
'type' => 'select',
]);
$this->assertDatabaseHas('attribute_options', [
'label' => 'Red',
'sort_order' => 1,
]);
}
public function test_it_rejects_options_for_text_attributes(): void
{
Tenant::create([
'codigo' => 'acme',
'nombre' => 'Acme',
'dominio' => 'acme.com',
]);
$response = $this->postJson('/api/product-attributes', [
'tenant_codigo' => 'acme',
'codigo' => 'material',
'nombre' => 'Material',
'type' => 'text',
'options' => [
['label' => 'Cotton'],
],
]);
$response
->assertUnprocessable()
->assertJsonValidationErrors(['options']);
}
}