feat(tenant): add hero carousel images and update related services and tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\AdminWebsiteType;
|
||||
use Database\Seeders\SocialMediaSeeder;
|
||||
@@ -47,6 +48,29 @@ class TenantSeederTest extends TestCase
|
||||
foreach ([$tenant->headerLogo, $tenant->footerLogo, $tenant->favicon, $tenant->headerBackgroundImage] as $attachment) {
|
||||
Storage::disk('s3')->assertExists($attachment->path);
|
||||
}
|
||||
|
||||
$carousel = $tenant->websiteExtras()
|
||||
->whereHas('websiteTypeExtra', fn ($query) => $query->where('codigo', 'heroCarousel'))
|
||||
->sole();
|
||||
$imageIds = $carousel->config;
|
||||
$this->assertCount(8, $imageIds);
|
||||
$this->assertSame([
|
||||
'onticket_hero_carousel_1.png',
|
||||
'onticket_hero_carousel_2.png',
|
||||
'onticket_hero_carousel_3.avif',
|
||||
'onticket_hero_carousel_4.jfif',
|
||||
'onticket_hero_carousel_5.jfif',
|
||||
'onticket_hero_carousel_6.jfif',
|
||||
'onticket_hero_carousel_7.avif',
|
||||
'onticket_hero_carousel_8.avif',
|
||||
], array_map(fn (int $id): string => Attachment::query()->findOrFail($id)->filename, $imageIds));
|
||||
|
||||
foreach ($imageIds as $id) {
|
||||
Storage::disk('s3')->assertExists(Attachment::query()->findOrFail($id)->path);
|
||||
}
|
||||
|
||||
$this->seed(TenantSeeder::class);
|
||||
$this->assertSame($imageIds, $carousel->fresh()->config);
|
||||
}
|
||||
|
||||
public function test_it_assigns_social_media_to_both_tenants_in_order(): void
|
||||
|
||||
@@ -89,7 +89,8 @@ class WebsiteTypeSeederTest extends TestCase
|
||||
$this->assertSame('standard', $onTicketStorefront->header_type);
|
||||
$multiEventStorefront = StorefrontWebsiteType::query()->where('codigo', 'onticket_multi_event')->with('extras')->sole();
|
||||
$this->assertSame('immersive', $multiEventStorefront->header_type);
|
||||
$this->assertCount(0, $multiEventStorefront->extras);
|
||||
$this->assertSame(['heroCarousel'], $multiEventStorefront->extras->pluck('codigo')->all());
|
||||
$this->assertSame($shopItStorefront->extras->sole()->config_schema, $multiEventStorefront->extras->sole()->config_schema);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['heroConfig', 'eventConfig', 'additionalInfoConfig'],
|
||||
$onTicketStorefront->extras->pluck('codigo')->all(),
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Domains\Menu\Models\Menu;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\AdminWebsiteType;
|
||||
use App\Domains\Tenant\Models\StorefrontWebsiteType;
|
||||
use Database\Seeders\WebsiteTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -333,6 +334,47 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonMissingPath('data.extras.banner');
|
||||
}
|
||||
|
||||
public function test_it_returns_signed_hero_carousel_urls_from_stored_attachment_ids(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
$this->seed(WebsiteTypeSeeder::class);
|
||||
|
||||
$tenant = $this->createTenant();
|
||||
$tenant->update(['storefront_website_type_code' => 'onticket_multi_event']);
|
||||
$definition = StorefrontWebsiteType::query()
|
||||
->where('codigo', 'onticket_multi_event')
|
||||
->firstOrFail()
|
||||
->extras()
|
||||
->where('codigo', 'heroCarousel')
|
||||
->firstOrFail();
|
||||
|
||||
$images = collect(['first.jpg', 'second.jpg'])->map(fn (string $filename): Attachment => Attachment::query()->create([
|
||||
'key' => (string) Str::uuid(),
|
||||
'path' => "tenants/acme/extras/heroCarousel/{$filename}",
|
||||
'filename' => $filename,
|
||||
'type' => AttachmentType::Image,
|
||||
'mime_type' => 'image/jpeg',
|
||||
'extension' => 'jpg',
|
||||
]));
|
||||
|
||||
$extra = $tenant->websiteExtras()->create([
|
||||
'website_type_extra_id' => $definition->id,
|
||||
'config' => $images->pluck('id')->all(),
|
||||
]);
|
||||
|
||||
$this->assertSame($images->pluck('id')->all(), $extra->fresh()->config);
|
||||
|
||||
$response = $this->getJson('/api/tenants/bootstrap?dominio=acme.com&path=%2F')->assertOk();
|
||||
$response->assertJsonCount(2, 'data.extras.heroCarousel');
|
||||
|
||||
foreach ($images->values() as $index => $image) {
|
||||
$response->assertJsonPath("data.extras.heroCarousel.{$index}", function (string $url) use ($image): bool {
|
||||
return str_contains($url, $image->path)
|
||||
&& (str_contains($url, 'Expires=') || str_contains($url, 'X-Amz-Expires='));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function test_the_bootstrap_returns_only_the_cropped_banner_url(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
|
||||
Reference in New Issue
Block a user