refactor(tenant): remove legacy presentation configuration and related carousel images
This commit is contained in:
@@ -19,7 +19,6 @@ class BootstrapTenantController extends Controller
|
|||||||
->with([
|
->with([
|
||||||
'headerLogo',
|
'headerLogo',
|
||||||
'footerLogo',
|
'footerLogo',
|
||||||
'mainCarouselImages',
|
|
||||||
'menues',
|
'menues',
|
||||||
'socialMedia',
|
'socialMedia',
|
||||||
'categories' => fn ($query) => $query->orderBy('nombre'),
|
'categories' => fn ($query) => $query->orderBy('nombre'),
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class TenantController extends Controller
|
|||||||
{
|
{
|
||||||
return TenantResource::collection(
|
return TenantResource::collection(
|
||||||
Tenant::query()
|
Tenant::query()
|
||||||
->with(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
->with(['headerLogo', 'footerLogo', 'socialMedia'])
|
||||||
->latest()
|
->latest()
|
||||||
->paginateFromRequest()
|
->paginateFromRequest()
|
||||||
)->response();
|
)->response();
|
||||||
@@ -30,14 +30,14 @@ class TenantController extends Controller
|
|||||||
$tenant = $this->tenantService->create($request->validated());
|
$tenant = $this->tenantService->create($request->validated());
|
||||||
|
|
||||||
return TenantResource::make(
|
return TenantResource::make(
|
||||||
$tenant->loadMissing(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
$tenant->loadMissing(['headerLogo', 'footerLogo', 'socialMedia'])
|
||||||
)->response()->setStatusCode(201);
|
)->response()->setStatusCode(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(Tenant $tenant): TenantResource
|
public function show(Tenant $tenant): TenantResource
|
||||||
{
|
{
|
||||||
return TenantResource::make(
|
return TenantResource::make(
|
||||||
$tenant->loadMissing(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
$tenant->loadMissing(['headerLogo', 'footerLogo', 'socialMedia'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class TenantController extends Controller
|
|||||||
$tenant = $this->tenantService->update($tenant, $request->validated());
|
$tenant = $this->tenantService->update($tenant, $request->validated());
|
||||||
|
|
||||||
return TenantResource::make(
|
return TenantResource::make(
|
||||||
$tenant->loadMissing(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
$tenant->loadMissing(['headerLogo', 'footerLogo', 'socialMedia'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
'footer_bg_color',
|
'footer_bg_color',
|
||||||
'header_logo_id',
|
'header_logo_id',
|
||||||
'footer_logo_id',
|
'footer_logo_id',
|
||||||
'hero_config',
|
|
||||||
'event_config',
|
|
||||||
'website_type_code',
|
'website_type_code',
|
||||||
'search_product_layout',
|
'search_product_layout',
|
||||||
'search_group_layout',
|
'search_group_layout',
|
||||||
@@ -58,8 +56,6 @@ class Tenant extends Model
|
|||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'hero_config' => 'array',
|
|
||||||
'event_config' => 'array',
|
|
||||||
'search_product_layout' => ProductLayout::class,
|
'search_product_layout' => ProductLayout::class,
|
||||||
'search_group_layout' => GroupLayout::class,
|
'search_group_layout' => GroupLayout::class,
|
||||||
'search_items_per_page' => 'integer',
|
'search_items_per_page' => 'integer',
|
||||||
@@ -82,14 +78,6 @@ class Tenant extends Model
|
|||||||
return $this->belongsTo(Attachment::class, 'footer_logo_id');
|
return $this->belongsTo(Attachment::class, 'footer_logo_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return BelongsTo<Attachment, $this>
|
|
||||||
*/
|
|
||||||
public function heroBgImage(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Attachment::class, 'hero_bg_image_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BelongsTo<WebsiteType, $this>
|
* @return BelongsTo<WebsiteType, $this>
|
||||||
*/
|
*/
|
||||||
@@ -98,22 +86,6 @@ class Tenant extends Model
|
|||||||
return $this->belongsTo(WebsiteType::class, 'website_type_code', 'codigo');
|
return $this->belongsTo(WebsiteType::class, 'website_type_code', 'codigo');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return BelongsToMany<Attachment, $this>
|
|
||||||
*/
|
|
||||||
public function mainCarouselImages(): BelongsToMany
|
|
||||||
{
|
|
||||||
return $this->belongsToMany(
|
|
||||||
Attachment::class,
|
|
||||||
'tenant_main_carousel_images',
|
|
||||||
'tenant_id',
|
|
||||||
'attachment_id'
|
|
||||||
)
|
|
||||||
->withPivot('orden')
|
|
||||||
->withTimestamps()
|
|
||||||
->orderByPivot('orden');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function catalogItems(): HasMany
|
public function catalogItems(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(CatalogItem::class, 'tenant_code', 'codigo');
|
return $this->hasMany(CatalogItem::class, 'tenant_code', 'codigo');
|
||||||
|
|||||||
@@ -62,9 +62,6 @@ class StoreTenantRequest extends FormRequest
|
|||||||
'footer_bg_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'footer_bg_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'header_logo' => $logoRule,
|
'header_logo' => $logoRule,
|
||||||
'footer_logo' => $logoRule,
|
'footer_logo' => $logoRule,
|
||||||
'hero_bg_image' => ['nullable', new ImageOrBase64Rule],
|
|
||||||
'main_carousel_images' => ['sometimes', 'array'],
|
|
||||||
'main_carousel_images.*' => ['required', 'distinct', new ImageOrBase64Rule],
|
|
||||||
'social_media' => ['sometimes', 'array'],
|
'social_media' => ['sometimes', 'array'],
|
||||||
'social_media.*.code' => [
|
'social_media.*.code' => [
|
||||||
'required',
|
'required',
|
||||||
@@ -74,16 +71,6 @@ class StoreTenantRequest extends FormRequest
|
|||||||
],
|
],
|
||||||
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
||||||
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
||||||
'hero_config' => ['nullable', 'array'],
|
|
||||||
'hero_config.title_html' => ['nullable', 'string'],
|
|
||||||
'hero_config.description_html' => ['nullable', 'string'],
|
|
||||||
'hero_config.button_text' => ['nullable', 'string'],
|
|
||||||
'hero_config.button_href' => ['nullable', 'string'],
|
|
||||||
'event_config' => ['nullable', 'array'],
|
|
||||||
'event_config.title' => ['nullable', 'string'],
|
|
||||||
'event_config.location' => ['nullable', 'string'],
|
|
||||||
'event_config.dates' => ['nullable', 'array'],
|
|
||||||
'event_config.dates.*' => ['required', 'string'],
|
|
||||||
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
|
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
|
||||||
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
|
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
|
||||||
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
|
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
|
||||||
|
|||||||
@@ -73,9 +73,6 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
'footer_bg_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'footer_bg_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'header_logo' => $logoRule,
|
'header_logo' => $logoRule,
|
||||||
'footer_logo' => $logoRule,
|
'footer_logo' => $logoRule,
|
||||||
'hero_bg_image' => ['nullable', new ImageOrBase64Rule],
|
|
||||||
'main_carousel_images' => ['sometimes', 'array'],
|
|
||||||
'main_carousel_images.*' => ['required', 'distinct', new ImageOrBase64Rule],
|
|
||||||
'social_media' => ['sometimes', 'array'],
|
'social_media' => ['sometimes', 'array'],
|
||||||
'social_media.*.code' => [
|
'social_media.*.code' => [
|
||||||
'required',
|
'required',
|
||||||
@@ -85,16 +82,6 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
],
|
],
|
||||||
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
||||||
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
||||||
'hero_config' => ['nullable', 'array'],
|
|
||||||
'hero_config.title_html' => ['nullable', 'string'],
|
|
||||||
'hero_config.description_html' => ['nullable', 'string'],
|
|
||||||
'hero_config.button_text' => ['nullable', 'string'],
|
|
||||||
'hero_config.button_href' => ['nullable', 'string'],
|
|
||||||
'event_config' => ['nullable', 'array'],
|
|
||||||
'event_config.title' => ['nullable', 'string'],
|
|
||||||
'event_config.location' => ['nullable', 'string'],
|
|
||||||
'event_config.dates' => ['nullable', 'array'],
|
|
||||||
'event_config.dates.*' => ['required', 'string'],
|
|
||||||
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
|
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
|
||||||
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
|
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
|
||||||
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
|
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
|
||||||
|
|||||||
@@ -19,12 +19,6 @@ class TenantResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray(Request $request): array
|
public function toArray(Request $request): array
|
||||||
{
|
{
|
||||||
$heroConfig = $this->hero_config;
|
|
||||||
if (is_array($heroConfig)) {
|
|
||||||
$heroConfig['background_image'] = $this->heroBgImage?->getTemporaryUrl(1440);
|
|
||||||
unset($heroConfig['background_image_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'codigo' => $this->codigo,
|
'codigo' => $this->codigo,
|
||||||
@@ -39,17 +33,9 @@ class TenantResource extends JsonResource
|
|||||||
// 1 day
|
// 1 day
|
||||||
'header_logo' => $this->headerLogo?->getTemporaryUrl(1440),
|
'header_logo' => $this->headerLogo?->getTemporaryUrl(1440),
|
||||||
'footer_logo' => $this->footerLogo?->getTemporaryUrl(1440),
|
'footer_logo' => $this->footerLogo?->getTemporaryUrl(1440),
|
||||||
'hero_config' => $heroConfig,
|
|
||||||
'event_config' => $this->event_config,
|
|
||||||
'search_product_layout' => $this->search_product_layout->value,
|
'search_product_layout' => $this->search_product_layout->value,
|
||||||
'search_group_layout' => $this->search_group_layout->value,
|
'search_group_layout' => $this->search_group_layout->value,
|
||||||
'search_items_per_page' => $this->search_items_per_page,
|
'search_items_per_page' => $this->search_items_per_page,
|
||||||
'main_carousel_images' => $this->whenLoaded(
|
|
||||||
'mainCarouselImages',
|
|
||||||
fn () => $this->mainCarouselImages
|
|
||||||
->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
|
|
||||||
->values()
|
|
||||||
),
|
|
||||||
'social_media' => $this->whenLoaded(
|
'social_media' => $this->whenLoaded(
|
||||||
'socialMedia',
|
'socialMedia',
|
||||||
fn () => $this->socialMedia
|
fn () => $this->socialMedia
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Domains\Tenant\Services;
|
namespace App\Domains\Tenant\Services;
|
||||||
|
|
||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Attachable\Services\AttachmentService;
|
use App\Domains\Attachable\Services\AttachmentService;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
|
|
||||||
class TenantService
|
class TenantService
|
||||||
{
|
{
|
||||||
@@ -24,15 +22,11 @@ class TenantService
|
|||||||
return DB::transaction(function () use ($data): Tenant {
|
return DB::transaction(function () use ($data): Tenant {
|
||||||
$headerLogo = $data['header_logo'] ?? null;
|
$headerLogo = $data['header_logo'] ?? null;
|
||||||
$footerLogo = $data['footer_logo'] ?? null;
|
$footerLogo = $data['footer_logo'] ?? null;
|
||||||
$heroBgImage = $data['hero_bg_image'] ?? null;
|
|
||||||
$mainCarouselImages = $data['main_carousel_images'] ?? [];
|
|
||||||
$socialMedia = $data['social_media'] ?? [];
|
$socialMedia = $data['social_media'] ?? [];
|
||||||
|
|
||||||
unset(
|
unset(
|
||||||
$data['header_logo'],
|
$data['header_logo'],
|
||||||
$data['footer_logo'],
|
$data['footer_logo'],
|
||||||
$data['hero_bg_image'],
|
|
||||||
$data['main_carousel_images'],
|
|
||||||
$data['social_media']
|
$data['social_media']
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -61,21 +55,8 @@ class TenantService
|
|||||||
$data['header_logo_id'] = $headerAttachmentId;
|
$data['header_logo_id'] = $headerAttachmentId;
|
||||||
$data['footer_logo_id'] = $footerAttachmentId;
|
$data['footer_logo_id'] = $footerAttachmentId;
|
||||||
|
|
||||||
if ($heroBgImage) {
|
|
||||||
$attachment = Str::isUuid($heroBgImage)
|
|
||||||
? Attachment::query()->where('key', $heroBgImage)->first()
|
|
||||||
: $this->attachmentService->store($heroBgImage, 'tenants');
|
|
||||||
|
|
||||||
if ($attachment) {
|
|
||||||
$heroConfig = $data['hero_config'] ?? [];
|
|
||||||
$heroConfig['background_image_id'] = $attachment->id;
|
|
||||||
$data['hero_config'] = $heroConfig;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Tenant $tenant */
|
/** @var Tenant $tenant */
|
||||||
$tenant = Tenant::query()->create($data);
|
$tenant = Tenant::query()->create($data);
|
||||||
$this->syncMainCarouselImages($tenant, $mainCarouselImages);
|
|
||||||
$this->syncSocialMedia($tenant, $socialMedia);
|
$this->syncSocialMedia($tenant, $socialMedia);
|
||||||
|
|
||||||
return $tenant;
|
return $tenant;
|
||||||
@@ -92,25 +73,17 @@ class TenantService
|
|||||||
return DB::transaction(function () use ($tenant, $data): Tenant {
|
return DB::transaction(function () use ($tenant, $data): Tenant {
|
||||||
$hasHeaderLogoKey = array_key_exists('header_logo', $data);
|
$hasHeaderLogoKey = array_key_exists('header_logo', $data);
|
||||||
$hasFooterLogoKey = array_key_exists('footer_logo', $data);
|
$hasFooterLogoKey = array_key_exists('footer_logo', $data);
|
||||||
$hasHeroBgImageKey = array_key_exists('hero_bg_image', $data);
|
|
||||||
$hasMainCarouselImagesKey = array_key_exists('main_carousel_images', $data);
|
|
||||||
$hasSocialMediaKey = array_key_exists('social_media', $data);
|
$hasSocialMediaKey = array_key_exists('social_media', $data);
|
||||||
$headerLogo = $data['header_logo'] ?? null;
|
$headerLogo = $data['header_logo'] ?? null;
|
||||||
$footerLogo = $data['footer_logo'] ?? null;
|
$footerLogo = $data['footer_logo'] ?? null;
|
||||||
$heroBgImage = $data['hero_bg_image'] ?? null;
|
|
||||||
$mainCarouselImages = $data['main_carousel_images'] ?? [];
|
|
||||||
$socialMedia = $data['social_media'] ?? [];
|
$socialMedia = $data['social_media'] ?? [];
|
||||||
|
|
||||||
unset(
|
unset(
|
||||||
$data['header_logo'],
|
$data['header_logo'],
|
||||||
$data['footer_logo'],
|
$data['footer_logo'],
|
||||||
$data['hero_bg_image'],
|
|
||||||
$data['main_carousel_images'],
|
|
||||||
$data['social_media']
|
$data['social_media']
|
||||||
);
|
);
|
||||||
|
|
||||||
$oldHeroBgId = $tenant->hero_bg_image_id;
|
|
||||||
|
|
||||||
$tenant->fill($data);
|
$tenant->fill($data);
|
||||||
|
|
||||||
if ($hasHeaderLogoKey) {
|
if ($hasHeaderLogoKey) {
|
||||||
@@ -145,34 +118,8 @@ class TenantService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentHeroConfig = $tenant->hero_config ?? [];
|
|
||||||
if ($hasHeroBgImageKey) {
|
|
||||||
if ($heroBgImage) {
|
|
||||||
$attachment = Str::isUuid($heroBgImage)
|
|
||||||
? Attachment::query()->where('key', $heroBgImage)->first()
|
|
||||||
: $this->attachmentService->store($heroBgImage, 'tenants');
|
|
||||||
|
|
||||||
if ($attachment) {
|
|
||||||
$currentHeroConfig['background_image_id'] = $attachment->id;
|
|
||||||
} else {
|
|
||||||
unset($currentHeroConfig['background_image_id']);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
unset($currentHeroConfig['background_image_id']);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($oldHeroBgId) {
|
|
||||||
$currentHeroConfig['background_image_id'] = $oldHeroBgId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tenant->hero_config = empty($currentHeroConfig) ? null : $currentHeroConfig;
|
|
||||||
|
|
||||||
$tenant->save();
|
$tenant->save();
|
||||||
|
|
||||||
if ($hasMainCarouselImagesKey) {
|
|
||||||
$this->syncMainCarouselImages($tenant, $mainCarouselImages);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($hasSocialMediaKey) {
|
if ($hasSocialMediaKey) {
|
||||||
$this->syncSocialMedia($tenant, $socialMedia);
|
$this->syncSocialMedia($tenant, $socialMedia);
|
||||||
}
|
}
|
||||||
@@ -181,21 +128,6 @@ class TenantService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, mixed> $images
|
|
||||||
*/
|
|
||||||
private function syncMainCarouselImages(Tenant $tenant, array $images): void
|
|
||||||
{
|
|
||||||
$attachments = [];
|
|
||||||
|
|
||||||
foreach (array_values($images) as $order => $image) {
|
|
||||||
$attachment = $this->resolveMainCarouselImage($image, $order);
|
|
||||||
$attachments[$attachment->id] = ['orden' => $order];
|
|
||||||
}
|
|
||||||
|
|
||||||
$tenant->mainCarouselImages()->sync($attachments);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int, array{code: string, url: string, orden?: int}> $socialMedia
|
* @param array<int, array{code: string, url: string, orden?: int}> $socialMedia
|
||||||
*/
|
*/
|
||||||
@@ -213,26 +145,4 @@ class TenantService
|
|||||||
$tenant->socialMedia()->sync($associations);
|
$tenant->socialMedia()->sync($associations);
|
||||||
$tenant->unsetRelation('socialMedia');
|
$tenant->unsetRelation('socialMedia');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function resolveMainCarouselImage(mixed $image, int $order): Attachment
|
|
||||||
{
|
|
||||||
if (is_string($image) && Str::isUuid($image)) {
|
|
||||||
$attachment = Attachment::query()
|
|
||||||
->where('key', $image)
|
|
||||||
->where('type', AttachmentType::Image->value)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($attachment === null) {
|
|
||||||
throw ValidationException::withMessages([
|
|
||||||
"main_carousel_images.{$order}" => [
|
|
||||||
__('api.tenant.invalid_carousel_image'),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $attachment;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->attachmentService->store($image, 'tenants/main-carousel');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('tenant_main_carousel_images');
|
||||||
|
|
||||||
|
Schema::table('tenants', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('hero_bg_image_id');
|
||||||
|
$table->dropColumn(['hero_config', 'event_config']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants', function (Blueprint $table): void {
|
||||||
|
$table->json('hero_config')->nullable();
|
||||||
|
$table->json('event_config')->nullable();
|
||||||
|
$table->unsignedBigInteger('hero_bg_image_id')
|
||||||
|
->virtualAs('hero_config->>"$.background_image_id"')
|
||||||
|
->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::create('tenant_main_carousel_images', function (Blueprint $table): void {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('tenant_id')
|
||||||
|
->constrained('tenants')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->foreignId('attachment_id')
|
||||||
|
->constrained('attachments')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->unsignedInteger('orden')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['tenant_id', 'attachment_id']);
|
||||||
|
$table->index(['tenant_id', 'orden']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -7,18 +7,11 @@ use App\Domains\Tenant\Models\Tenant;
|
|||||||
use App\Domains\Tenant\Services\TenantService;
|
use App\Domains\Tenant\Services\TenantService;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use RuntimeException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class TenantSeeder extends Seeder
|
class TenantSeeder extends Seeder
|
||||||
{
|
{
|
||||||
private const SONDER_MAIN_CAROUSEL_IMAGES = [
|
|
||||||
'01-urban-team.png',
|
|
||||||
'02-running-shoes.png',
|
|
||||||
'03-streetwear.png',
|
|
||||||
'04-football-training.png',
|
|
||||||
'05-activewear-essentials.png',
|
|
||||||
'06-city-runners.png',
|
|
||||||
];
|
|
||||||
|
|
||||||
private const SOCIAL_MEDIA = [
|
private const SOCIAL_MEDIA = [
|
||||||
[
|
[
|
||||||
'code' => 'instagram',
|
'code' => 'instagram',
|
||||||
@@ -44,88 +37,13 @@ class TenantSeeder extends Seeder
|
|||||||
|
|
||||||
public function __construct(protected TenantService $tenantService) {}
|
public function __construct(protected TenantService $tenantService) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
// Check if tenant 'sonder' already exists and delete it to prevent duplicates
|
$this->deleteTenant('sonder');
|
||||||
$existing = Tenant::query()->where('codigo', 'sonder')->first();
|
|
||||||
if ($existing) {
|
|
||||||
$attachmentService = app(AttachmentService::class);
|
|
||||||
if ($existing->headerLogo) {
|
|
||||||
try {
|
|
||||||
$attachmentService->delete($existing->headerLogo);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
// Ignore exception on cleanup
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($existing->footerLogo && $existing->footer_logo_id !== $existing->header_logo_id) {
|
|
||||||
try {
|
|
||||||
$attachmentService->delete($existing->footerLogo);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
// Ignore exception on cleanup
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($existing->mainCarouselImages as $mainCarouselImage) {
|
|
||||||
try {
|
|
||||||
$attachmentService->delete($mainCarouselImage);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
// Ignore exception on cleanup
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$existing->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if domain 'localhost' is already in use by another tenant and delete it
|
Tenant::query()
|
||||||
$existingDomain = Tenant::query()->where('dominio', 'localhost')->first();
|
->where('dominio', 'localhost')
|
||||||
if ($existingDomain) {
|
->delete();
|
||||||
$existingDomain->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$headerImagePath = public_path('images/sonder_header.png');
|
|
||||||
$footerImagePath = public_path('images/sonder_footer.png');
|
|
||||||
|
|
||||||
if (! file_exists($headerImagePath)) {
|
|
||||||
throw new \RuntimeException("Image not found at path: {$headerImagePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! file_exists($footerImagePath)) {
|
|
||||||
throw new \RuntimeException("Image not found at path: {$footerImagePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$headerLogo = new UploadedFile(
|
|
||||||
$headerImagePath,
|
|
||||||
'sonder_header.png',
|
|
||||||
'image/png',
|
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$footerLogo = new UploadedFile(
|
|
||||||
$footerImagePath,
|
|
||||||
'sonder_footer.png',
|
|
||||||
'image/png',
|
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$mainCarouselImages = [];
|
|
||||||
foreach (self::SONDER_MAIN_CAROUSEL_IMAGES as $filename) {
|
|
||||||
$imagePath = public_path("images/sonder-main-carousel/{$filename}");
|
|
||||||
|
|
||||||
if (! file_exists($imagePath)) {
|
|
||||||
throw new \RuntimeException("Image not found at path: {$imagePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$mainCarouselImages[] = new UploadedFile(
|
|
||||||
$imagePath,
|
|
||||||
$filename,
|
|
||||||
'image/png',
|
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->tenantService->create([
|
$this->tenantService->create([
|
||||||
'codigo' => 'sonder',
|
'codigo' => 'sonder',
|
||||||
@@ -137,82 +55,17 @@ class TenantSeeder extends Seeder
|
|||||||
'success_color' => '#198754',
|
'success_color' => '#198754',
|
||||||
'header_bg_color' => '#ffffff',
|
'header_bg_color' => '#ffffff',
|
||||||
'footer_bg_color' => '#313131',
|
'footer_bg_color' => '#313131',
|
||||||
'header_logo' => $headerLogo,
|
'header_logo' => $this->uploadedImage('images/sonder_header.png', 'sonder_header.png'),
|
||||||
'footer_logo' => $footerLogo,
|
'footer_logo' => $this->uploadedImage('images/sonder_footer.png', 'sonder_footer.png'),
|
||||||
'main_carousel_images' => $mainCarouselImages,
|
|
||||||
'social_media' => self::SOCIAL_MEDIA,
|
'social_media' => self::SOCIAL_MEDIA,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Check if tenant 'fiesta_futbol_infantil' already exists
|
$this->deleteTenant('fiesta_futbol_infantil');
|
||||||
$existingFiesta = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first();
|
|
||||||
if ($existingFiesta) {
|
|
||||||
$attachmentService = app(AttachmentService::class);
|
|
||||||
if ($existingFiesta->headerLogo) {
|
|
||||||
try {
|
|
||||||
$attachmentService->delete($existingFiesta->headerLogo);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($existingFiesta->footerLogo && $existingFiesta->footer_logo_id !== $existingFiesta->header_logo_id) {
|
|
||||||
try {
|
|
||||||
$attachmentService->delete($existingFiesta->footerLogo);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($existingFiesta->heroBgImage) {
|
|
||||||
try {
|
|
||||||
$attachmentService->delete($existingFiesta->heroBgImage);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$existingFiesta->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$fiestaDomain = 'fiesta-futbol-infantil.localhost';
|
$fiestaDomain = 'fiesta-futbol-infantil.localhost';
|
||||||
$existingFiestaDomain = Tenant::query()->where('dominio', $fiestaDomain)->first();
|
Tenant::query()
|
||||||
if ($existingFiestaDomain) {
|
->where('dominio', $fiestaDomain)
|
||||||
$existingFiestaDomain->delete();
|
->delete();
|
||||||
}
|
|
||||||
|
|
||||||
$fiestaHeaderImagePath = public_path('images/futbol_infantil_header.png');
|
|
||||||
$fiestaFooterImagePath = public_path('images/futbol_infantil_footer.png');
|
|
||||||
$fiestaHeroBgImagePath = public_path('images/futbol_infantil_hero.jpg');
|
|
||||||
|
|
||||||
if (! file_exists($fiestaHeaderImagePath)) {
|
|
||||||
throw new \RuntimeException("Image not found at path: {$fiestaHeaderImagePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! file_exists($fiestaFooterImagePath)) {
|
|
||||||
throw new \RuntimeException("Image not found at path: {$fiestaFooterImagePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! file_exists($fiestaHeroBgImagePath)) {
|
|
||||||
throw new \RuntimeException("Image not found at path: {$fiestaHeroBgImagePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$fiestaHeaderLogo = new UploadedFile(
|
|
||||||
$fiestaHeaderImagePath,
|
|
||||||
'futbol_infantil_header.png',
|
|
||||||
'image/png',
|
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$fiestaFooterLogo = new UploadedFile(
|
|
||||||
$fiestaFooterImagePath,
|
|
||||||
'futbol_infantil_footer.png',
|
|
||||||
'image/png',
|
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$fiestaHeroBgImage = new UploadedFile(
|
|
||||||
$fiestaHeroBgImagePath,
|
|
||||||
'futbol_infantil_hero.jpg',
|
|
||||||
'image/jpeg',
|
|
||||||
null,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->tenantService->create([
|
$this->tenantService->create([
|
||||||
'codigo' => 'fiesta_futbol_infantil',
|
'codigo' => 'fiesta_futbol_infantil',
|
||||||
@@ -224,21 +77,63 @@ class TenantSeeder extends Seeder
|
|||||||
'success_color' => '#198754',
|
'success_color' => '#198754',
|
||||||
'header_bg_color' => '#ffffff',
|
'header_bg_color' => '#ffffff',
|
||||||
'footer_bg_color' => '#015327',
|
'footer_bg_color' => '#015327',
|
||||||
'header_logo' => $fiestaHeaderLogo,
|
'header_logo' => $this->uploadedImage(
|
||||||
'footer_logo' => $fiestaFooterLogo,
|
'images/futbol_infantil_header.png',
|
||||||
'hero_bg_image' => $fiestaHeroBgImage,
|
'futbol_infantil_header.png',
|
||||||
'hero_config' => [
|
),
|
||||||
'title_html' => '<strong>ASEGURÁ TU LUGAR</strong>',
|
'footer_logo' => $this->uploadedImage(
|
||||||
'description_html' => '<strong>Comprá tu entrada oficial en segundos</strong> de forma 100% segura. Preparate para vivir la experiencia completa.',
|
'images/futbol_infantil_footer.png',
|
||||||
'button_text' => 'Quiero mi entrada',
|
'futbol_infantil_footer.png',
|
||||||
'button_href' => null,
|
),
|
||||||
],
|
|
||||||
'event_config' => [
|
|
||||||
'title' => 'FIESTA NACIONAL DEL FÚTBOL INFANTIL',
|
|
||||||
'location' => 'Sunchales, Santa Fe',
|
|
||||||
'dates' => ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
|
||||||
],
|
|
||||||
'social_media' => self::SOCIAL_MEDIA,
|
'social_media' => self::SOCIAL_MEDIA,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function deleteTenant(string $codigo): void
|
||||||
|
{
|
||||||
|
$tenant = Tenant::query()
|
||||||
|
->where('codigo', $codigo)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($tenant === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$attachmentService = app(AttachmentService::class);
|
||||||
|
|
||||||
|
if ($tenant->headerLogo) {
|
||||||
|
try {
|
||||||
|
$attachmentService->delete($tenant->headerLogo);
|
||||||
|
} catch (Throwable) {
|
||||||
|
// Ignore cleanup errors while recreating demo data.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tenant->footerLogo && $tenant->footer_logo_id !== $tenant->header_logo_id) {
|
||||||
|
try {
|
||||||
|
$attachmentService->delete($tenant->footerLogo);
|
||||||
|
} catch (Throwable) {
|
||||||
|
// Ignore cleanup errors while recreating demo data.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tenant->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function uploadedImage(string $relativePath, string $filename): UploadedFile
|
||||||
|
{
|
||||||
|
$path = public_path($relativePath);
|
||||||
|
|
||||||
|
if (! file_exists($path)) {
|
||||||
|
throw new RuntimeException("Image not found at path: {$path}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new UploadedFile(
|
||||||
|
$path,
|
||||||
|
$filename,
|
||||||
|
'image/png',
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,9 +94,6 @@ return [
|
|||||||
'schema_required' => 'The schema is required for static menus.',
|
'schema_required' => 'The schema is required for static menus.',
|
||||||
'not_found' => 'The specified menu does not exist.',
|
'not_found' => 'The specified menu does not exist.',
|
||||||
],
|
],
|
||||||
'tenant' => [
|
|
||||||
'invalid_carousel_image' => 'The specified image does not exist or is not an image attachment.',
|
|
||||||
],
|
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'forbidden' => 'You do not have permission to perform this action.',
|
'forbidden' => 'You do not have permission to perform this action.',
|
||||||
'not_found' => 'The requested resource was not found.',
|
'not_found' => 'The requested resource was not found.',
|
||||||
|
|||||||
@@ -94,9 +94,6 @@ return [
|
|||||||
'schema_required' => 'El schema es obligatorio para los menús estáticos.',
|
'schema_required' => 'El schema es obligatorio para los menús estáticos.',
|
||||||
'not_found' => 'El menú indicado no existe.',
|
'not_found' => 'El menú indicado no existe.',
|
||||||
],
|
],
|
||||||
'tenant' => [
|
|
||||||
'invalid_carousel_image' => 'La imagen indicada no existe o no es un attachment de tipo imagen.',
|
|
||||||
],
|
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'forbidden' => 'No tienes permiso para realizar esta acción.',
|
'forbidden' => 'No tienes permiso para realizar esta acción.',
|
||||||
'not_found' => 'El recurso solicitado no fue encontrado.',
|
'not_found' => 'El recurso solicitado no fue encontrado.',
|
||||||
|
|||||||
@@ -13,33 +13,6 @@ class TenantSeederTest extends TestCase
|
|||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
public function test_it_loads_the_sonder_main_carousel_images_in_order(): void
|
|
||||||
{
|
|
||||||
Storage::fake('s3');
|
|
||||||
|
|
||||||
$this->seed([
|
|
||||||
SocialMediaSeeder::class,
|
|
||||||
TenantSeeder::class,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail();
|
|
||||||
$images = $tenant->mainCarouselImages()->get();
|
|
||||||
|
|
||||||
$this->assertSame([
|
|
||||||
'01-urban-team.png',
|
|
||||||
'02-running-shoes.png',
|
|
||||||
'03-streetwear.png',
|
|
||||||
'04-football-training.png',
|
|
||||||
'05-activewear-essentials.png',
|
|
||||||
'06-city-runners.png',
|
|
||||||
], $images->pluck('filename')->all());
|
|
||||||
$this->assertSame([0, 1, 2, 3, 4, 5], $images->pluck('pivot.orden')->all());
|
|
||||||
|
|
||||||
foreach ($images as $image) {
|
|
||||||
Storage::disk('s3')->assertExists($image->path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_assigns_social_media_to_both_tenants_in_order(): void
|
public function test_it_assigns_social_media_to_both_tenants_in_order(): void
|
||||||
{
|
{
|
||||||
Storage::fake('s3');
|
Storage::fake('s3');
|
||||||
|
|||||||
@@ -1,191 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Tenant;
|
|
||||||
|
|
||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class TenantMainCarouselImagesTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_a_tenant_has_ordered_main_carousel_images(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant();
|
|
||||||
$firstAttachment = $this->createAttachment('first.png');
|
|
||||||
$secondAttachment = $this->createAttachment('second.png');
|
|
||||||
|
|
||||||
$tenant->mainCarouselImages()->attach([
|
|
||||||
$secondAttachment->id => ['orden' => 2],
|
|
||||||
$firstAttachment->id => ['orden' => 1],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$attachments = $tenant->mainCarouselImages()->get();
|
|
||||||
|
|
||||||
$this->assertCount(2, $attachments);
|
|
||||||
$this->assertTrue($attachments[0]->is($firstAttachment));
|
|
||||||
$this->assertTrue($attachments[1]->is($secondAttachment));
|
|
||||||
$this->assertSame([1, 2], $attachments->pluck('pivot.orden')->all());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_bootstrap_returns_all_main_carousel_image_urls_in_order(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant();
|
|
||||||
$firstAttachment = $this->createAttachment('first.png');
|
|
||||||
$secondAttachment = $this->createAttachment('second.png');
|
|
||||||
|
|
||||||
$tenant->mainCarouselImages()->attach([
|
|
||||||
$secondAttachment->id => ['orden' => 20],
|
|
||||||
$firstAttachment->id => ['orden' => 10],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
|
|
||||||
|
|
||||||
$response
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(2, 'data.main_carousel_images');
|
|
||||||
|
|
||||||
$urls = $response->json('data.main_carousel_images');
|
|
||||||
|
|
||||||
$this->assertStringContainsString($firstAttachment->key, $urls[0]);
|
|
||||||
$this->assertStringContainsString($secondAttachment->key, $urls[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_show_returns_an_empty_main_carousel_images_array_when_the_tenant_has_no_images(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant();
|
|
||||||
|
|
||||||
$this->getJson("/api/tenants/{$tenant->codigo}")
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.main_carousel_images', []);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_store_uploads_and_attaches_main_carousel_images_in_request_order(): void
|
|
||||||
{
|
|
||||||
Storage::fake('s3');
|
|
||||||
|
|
||||||
$headerLogo = $this->createAttachment('header.png');
|
|
||||||
$footerLogo = $this->createAttachment('footer.png');
|
|
||||||
|
|
||||||
$response = $this
|
|
||||||
->withHeader('Accept', 'application/json')
|
|
||||||
->post('/api/tenants', [
|
|
||||||
...$this->tenantPayload(),
|
|
||||||
'header_logo' => $headerLogo->key,
|
|
||||||
'footer_logo' => $footerLogo->key,
|
|
||||||
'main_carousel_images' => [
|
|
||||||
UploadedFile::fake()->image('first-carousel.png', 1200, 300),
|
|
||||||
UploadedFile::fake()->image('second-carousel.png', 1200, 300),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response
|
|
||||||
->assertCreated()
|
|
||||||
->assertJsonCount(2, 'data.main_carousel_images');
|
|
||||||
|
|
||||||
$tenant = Tenant::query()->where('codigo', 'new-acme')->firstOrFail();
|
|
||||||
$images = $tenant->mainCarouselImages()->get();
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
['first-carousel.png', 'second-carousel.png'],
|
|
||||||
$images->pluck('filename')->all()
|
|
||||||
);
|
|
||||||
$this->assertSame([0, 1], $images->pluck('pivot.orden')->all());
|
|
||||||
Storage::disk('s3')->assertExists($images[0]->path);
|
|
||||||
Storage::disk('s3')->assertExists($images[1]->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_update_replaces_and_can_clear_main_carousel_images(): void
|
|
||||||
{
|
|
||||||
$tenant = $this->createTenant();
|
|
||||||
$oldImage = $this->createAttachment('old.png');
|
|
||||||
$firstImage = $this->createAttachment('first.png');
|
|
||||||
$secondImage = $this->createAttachment('second.png');
|
|
||||||
|
|
||||||
$tenant->mainCarouselImages()->attach($oldImage->id, ['orden' => 0]);
|
|
||||||
|
|
||||||
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
|
||||||
'main_carousel_images' => [$secondImage->key, $firstImage->key],
|
|
||||||
])
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonCount(2, 'data.main_carousel_images');
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
[$secondImage->id, $firstImage->id],
|
|
||||||
$tenant->mainCarouselImages()->pluck('attachments.id')->all()
|
|
||||||
);
|
|
||||||
$this->assertDatabaseMissing('tenant_main_carousel_images', [
|
|
||||||
'tenant_id' => $tenant->id,
|
|
||||||
'attachment_id' => $oldImage->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
|
||||||
'main_carousel_images' => [],
|
|
||||||
])
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.main_carousel_images', []);
|
|
||||||
|
|
||||||
$this->assertDatabaseMissing('tenant_main_carousel_images', [
|
|
||||||
'tenant_id' => $tenant->id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<string, string>
|
|
||||||
*/
|
|
||||||
private function tenantPayload(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'codigo' => 'new-acme',
|
|
||||||
'nombre' => 'New Acme',
|
|
||||||
'dominio' => 'new-acme.com',
|
|
||||||
'primary_color' => '#111111',
|
|
||||||
'secondary_color' => '#222222',
|
|
||||||
'danger_color' => '#333333',
|
|
||||||
'success_color' => '#444444',
|
|
||||||
'header_bg_color' => '#ffffff',
|
|
||||||
'footer_bg_color' => '#ffffff',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTenant(): Tenant
|
|
||||||
{
|
|
||||||
$headerLogo = $this->createAttachment('header.png');
|
|
||||||
$footerLogo = $this->createAttachment('footer.png');
|
|
||||||
|
|
||||||
return Tenant::query()->create([
|
|
||||||
'codigo' => 'acme',
|
|
||||||
'nombre' => 'Acme',
|
|
||||||
'dominio' => 'acme.com',
|
|
||||||
'primary_color' => '#111111',
|
|
||||||
'secondary_color' => '#222222',
|
|
||||||
'danger_color' => '#333333',
|
|
||||||
'success_color' => '#444444',
|
|
||||||
'header_bg_color' => '#ffffff',
|
|
||||||
'footer_bg_color' => '#ffffff',
|
|
||||||
'header_logo_id' => $headerLogo->id,
|
|
||||||
'footer_logo_id' => $footerLogo->id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createAttachment(string $filename): Attachment
|
|
||||||
{
|
|
||||||
$key = (string) Str::uuid();
|
|
||||||
|
|
||||||
return Attachment::query()->create([
|
|
||||||
'key' => $key,
|
|
||||||
'path' => "tenants/main-carousel/{$key}.png",
|
|
||||||
'filename' => $filename,
|
|
||||||
'type' => AttachmentType::Image,
|
|
||||||
'mime_type' => 'image/png',
|
|
||||||
'extension' => 'png',
|
|
||||||
'size' => 100,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
20
tests/Feature/Tenant/TenantPresentationConfigRemovalTest.php
Normal file
20
tests/Feature/Tenant/TenantPresentationConfigRemovalTest.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Tenant;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TenantPresentationConfigRemovalTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_legacy_presentation_config_is_not_part_of_tenants(): void
|
||||||
|
{
|
||||||
|
$this->assertFalse(Schema::hasTable('tenant_main_carousel_images'));
|
||||||
|
$this->assertFalse(Schema::hasColumn('tenants', 'hero_bg_image_id'));
|
||||||
|
$this->assertFalse(Schema::hasColumn('tenants', 'hero_config'));
|
||||||
|
$this->assertFalse(Schema::hasColumn('tenants', 'event_config'));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user