feat(catalog): add event_id to catalog items and backfill existing records
This commit is contained in:
@@ -8,7 +8,9 @@ use App\Domains\Commerce\Catalog\Models\Attribute;
|
||||
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
||||
use App\Shared\Enums\FieldType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Event\Models\Event;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -48,6 +50,7 @@ class CatalogItemControllerTest extends TestCase
|
||||
$response
|
||||
->assertCreated()
|
||||
->assertJsonPath('data.nombre', 'Shirt')
|
||||
->assertJsonMissingPath('data.event_id')
|
||||
->assertJsonMissingPath('data.group_order')
|
||||
->assertJsonPath('data.max_units_per_user', 4)
|
||||
->assertJsonCount(2, 'data.images')
|
||||
@@ -60,6 +63,7 @@ class CatalogItemControllerTest extends TestCase
|
||||
$this->assertSame([0, 1], $item->attachments()->get()->pluck('pivot.orden')->all());
|
||||
$this->assertSame(4, $item->max_units_per_user);
|
||||
$this->assertSame(7, $item->group_order);
|
||||
$this->assertNull($item->event_id);
|
||||
$this->assertSame([0], $variant->attachments()->get()->pluck('pivot.orden')->all());
|
||||
$this->assertDatabaseHas('catalog_items_attachments', [
|
||||
'catalog_item_id' => $item->id,
|
||||
@@ -69,6 +73,27 @@ class CatalogItemControllerTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_event_id_is_an_internal_nullable_catalog_item_link(): void
|
||||
{
|
||||
$this->assertTrue(Schema::hasColumn('catalog_items', 'event_id'));
|
||||
|
||||
$tenant = $this->createTenant('catalog-event-link');
|
||||
$event = Event::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'title' => 'Internal event',
|
||||
]);
|
||||
|
||||
$this->postJson("/api/tenants/{$tenant->codigo}/catalog-items", [
|
||||
'slug' => 'client-event-id',
|
||||
'nombre' => 'Client event ID',
|
||||
'precio' => 100,
|
||||
'real_stock' => 1,
|
||||
'event_id' => $event->id,
|
||||
])->assertUnprocessable()->assertJsonValidationErrors('event_id');
|
||||
|
||||
$this->assertDatabaseMissing('catalog_items', ['slug' => 'client-event-id']);
|
||||
}
|
||||
|
||||
public function test_it_validates_images_before_creating_the_catalog_item(): void
|
||||
{
|
||||
$tenant = $this->createTenant('validation');
|
||||
|
||||
Reference in New Issue
Block a user