feat(catalog): add tenant-scoped product attributes and variant definitions
This commit is contained in:
86
tests/Feature/Catalog/ProductAttributeControllerTest.php
Normal file
86
tests/Feature/Catalog/ProductAttributeControllerTest.php
Normal 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']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user