seed(AuthorizationSeeder::class); WebsiteType::query()->create([ 'codigo' => 'onticket', 'nombre' => 'OnTicket', ]); } public function test_authentication_is_required(): void { $this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/merchandise') ->assertUnauthorized(); } public function test_it_returns_color_and_size_options_for_the_authenticated_tenant(): void { $tenant = $this->createTenant('fiesta'); $otherTenant = $this->createTenant('other'); $this->createAttribute($tenant, 'color', [ ['value' => 'verde', 'label' => 'Verde', 'sort_order' => 2], ['value' => 'blanco', 'label' => 'Blanco', 'sort_order' => 1], ]); $this->createAttribute($tenant, 'talle', [ ['value' => 'S', 'label' => 'S', 'sort_order' => 1], ['value' => 'M', 'label' => 'M', 'sort_order' => 2], ]); $this->createAttribute($otherTenant, 'color', [ ['value' => 'negro', 'label' => 'Negro', 'sort_order' => 1], ]); Sanctum::actingAs(User::factory()->create([ 'rol_codigo' => RoleCode::AdminApp->value, 'tenant_codigo' => $tenant->codigo, ])); $this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/merchandise') ->assertOk() ->assertJsonCount(2, 'data.colors') ->assertJsonCount(2, 'data.sizes') ->assertJsonPath('data.colors.0.value', 'blanco') ->assertJsonPath('data.colors.0.label', 'Blanco') ->assertJsonPath('data.colors.1.value', 'verde') ->assertJsonPath('data.sizes.0.value', 'S') ->assertJsonPath('data.sizes.1.value', 'M') ->assertJsonMissing(['value' => 'negro']); } public function test_a_customer_cannot_get_the_merchandise_form(): void { Sanctum::actingAs(User::factory()->create([ 'rol_codigo' => RoleCode::User->value, ])); $this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/merchandise') ->assertForbidden(); } private function createTenant(string $code): Tenant { return Tenant::query()->create([ 'codigo' => $code, 'nombre' => ucfirst($code), 'dominio' => "{$code}.test", 'website_type_code' => 'onticket', ]); } /** @param array $options */ private function createAttribute(Tenant $tenant, string $code, array $options): void { $attribute = Attribute::query()->create([ 'tenant_codigo' => $tenant->codigo, 'codigo' => $code, 'nombre' => ucfirst($code), 'type' => FieldType::Select, 'is_required' => true, ]); $attribute->options()->createMany($options); } }