feat(tickets): implement AdminAppTicketResource and update ticket collection to use it
This commit is contained in:
@@ -6,7 +6,12 @@ use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Menu\Models\Menu;
|
||||
use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use App\Domains\Ticket\Models\Ticket;
|
||||
@@ -107,6 +112,53 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
->assertJsonPath('total_tickets', 2);
|
||||
}
|
||||
|
||||
public function test_it_returns_structured_variant_properties(): void
|
||||
{
|
||||
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
$this->grantTicketsMenu($tenant);
|
||||
Sanctum::actingAs($admin);
|
||||
|
||||
$item = CatalogItem::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'slug' => 'remera',
|
||||
'nombre' => 'Remera',
|
||||
'precio' => '8000.00',
|
||||
'has_tickets' => true,
|
||||
]);
|
||||
$attribute = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'size',
|
||||
'nombre' => 'Talle',
|
||||
'type' => FieldType::Select,
|
||||
]);
|
||||
$attribute->options()->create(['value' => 'xl', 'label' => 'XL']);
|
||||
$itemAttribute = $item->itemAttributes()->create([
|
||||
'attribute_id' => $attribute->id,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
$variant = Variant::query()->create([
|
||||
'catalog_item_id' => $item->id,
|
||||
'inventory_id' => Inventory::query()->create()->id,
|
||||
]);
|
||||
$variant->definitions()->create([
|
||||
'item_attribute_id' => $itemAttribute->id,
|
||||
'value' => 'xl',
|
||||
]);
|
||||
$ticket = $this->createTicket($tenant, $admin, [
|
||||
'source_catalog_item_id' => $item->id,
|
||||
'source_variant_id' => $variant->id,
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.id', $ticket->id)
|
||||
->assertJsonPath('data.0.variant_properties.0.code', 'size')
|
||||
->assertJsonPath('data.0.variant_properties.0.label', 'Talle')
|
||||
->assertJsonPath('data.0.variant_properties.0.values.0.value', 'xl')
|
||||
->assertJsonPath('data.0.variant_properties.0.values.0.label', 'XL');
|
||||
}
|
||||
|
||||
private function createTenant(string $code): Tenant
|
||||
{
|
||||
$headerLogo = $this->createAttachment("{$code}-header.png");
|
||||
@@ -157,12 +209,13 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
$tenant->menues()->attach($menu->code);
|
||||
}
|
||||
|
||||
private function createTicket(Tenant $tenant, User $user): Ticket
|
||||
/** @param array<string, mixed> $attributes */
|
||||
private function createTicket(Tenant $tenant, User $user, array $attributes = []): Ticket
|
||||
{
|
||||
return Ticket::query()->create([
|
||||
return Ticket::query()->create(array_merge([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'ticket' => (string) Str::uuid(),
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
], $attributes));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user