refactor: remove tenant code check and implement middleware for menu validation in controllers
This commit is contained in:
@@ -7,6 +7,7 @@ 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\Menu\Models\Menu;
|
||||
use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
@@ -135,9 +136,39 @@ class AccommodationControllerTest extends TestCase
|
||||
$this->assertDatabaseCount('attribute_options', 0);
|
||||
}
|
||||
|
||||
/** @return array{Tenant, Attribute} */
|
||||
private function configuredTenant(): array
|
||||
public function test_the_tenant_must_have_the_accommodations_menu(): void
|
||||
{
|
||||
[$tenant] = $this->configuredTenant(withMenu: false);
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->postJson('/api/v1/adminapp/tenant/accommodations', [
|
||||
'variants' => [
|
||||
$this->variantPayload('Carpa', null, 10, 35000),
|
||||
],
|
||||
])->assertNotFound();
|
||||
|
||||
$this->assertDatabaseCount('catalog_items', 0);
|
||||
}
|
||||
|
||||
public function test_a_different_tenant_can_use_the_endpoint_when_it_has_the_menu(): void
|
||||
{
|
||||
[$tenant] = $this->configuredTenant('another_tenant');
|
||||
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||
|
||||
$this->postJson('/api/v1/adminapp/tenant/accommodations', [
|
||||
'variants' => [
|
||||
$this->variantPayload('Dormitorio Compartido', null, 30, 25000),
|
||||
],
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.variants.0.value', 'dormitorio_compartido');
|
||||
}
|
||||
|
||||
/** @return array{Tenant, Attribute} */
|
||||
private function configuredTenant(
|
||||
string $tenantCode = 'fiesta_futbol_infantil',
|
||||
bool $withMenu = true,
|
||||
): array {
|
||||
$headerLogo = Attachment::query()->create([
|
||||
'path' => 'test/header.png',
|
||||
'filename' => 'header.png',
|
||||
@@ -151,7 +182,7 @@ class AccommodationControllerTest extends TestCase
|
||||
'mime_type' => 'image/png',
|
||||
]);
|
||||
$tenant = Tenant::query()->create([
|
||||
'codigo' => 'fiesta_futbol_infantil',
|
||||
'codigo' => $tenantCode,
|
||||
'nombre' => 'Fiesta Fútbol Infantil',
|
||||
'dominio' => 'fiesta.test',
|
||||
'primary_color' => '#112233',
|
||||
@@ -171,6 +202,14 @@ class AccommodationControllerTest extends TestCase
|
||||
'is_required' => true,
|
||||
]);
|
||||
|
||||
if ($withMenu) {
|
||||
$menu = Menu::query()->firstOrCreate(
|
||||
['code' => 'adminapp.fiesta-futbol-infantil.alojamientos'],
|
||||
['label' => 'Alojamientos', 'route' => '/admin/alojamientos'],
|
||||
);
|
||||
$tenant->menues()->syncWithoutDetaching([$menu->code]);
|
||||
}
|
||||
|
||||
return [$tenant, $attribute];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user