feat(attachment): refactor image cropping functionality to use range objects and update related tests

This commit is contained in:
2026-08-18 12:54:47 -03:00
parent 58cc35fd61
commit 9cfd49f233
16 changed files with 496 additions and 54 deletions

View File

@@ -317,6 +317,64 @@ class BootstrapTenantControllerTest extends TestCase
->assertJsonMissingPath('data.extras.banner');
}
public function test_the_bootstrap_returns_only_the_cropped_banner_url(): void
{
Storage::fake('s3');
$tenant = $this->createTenant();
$websiteType = WebsiteType::query()->create([
'codigo' => 'event-store',
'nombre' => 'Eventos',
]);
$tenant->update(['website_type_code' => $websiteType->codigo]);
$heroDefinition = $websiteType->extras()->create([
'codigo' => 'heroConfig',
'nombre' => 'Banner',
'config_schema' => [
'transforms' => [
'background_image_id' => [
'handler' => 'attachment',
'attachment_type' => 'image',
],
],
],
]);
$cropped = Attachment::query()->create([
'key' => (string) Str::uuid(),
'path' => 'tenants/acme/cropped.jpg',
'filename' => 'cropped.jpg',
'type' => AttachmentType::Image,
'mime_type' => 'image/jpeg',
'extension' => 'jpg',
]);
$original = Attachment::query()->create([
'key' => (string) Str::uuid(),
'path' => 'tenants/acme/original.jpg',
'filename' => 'original.jpg',
'type' => AttachmentType::Image,
'mime_type' => 'image/jpeg',
'extension' => 'jpg',
'crop_horizontal' => ['start_percentage' => 10, 'end_percentage' => 90],
'crop_vertical' => ['start_percentage' => 20, 'end_percentage' => 80],
'cropped_attachment_id' => $cropped->id,
]);
$tenant->websiteExtras()->create([
'website_type_extra_id' => $heroDefinition->id,
'config' => ['background_image_id' => $original->id],
'is_enabled' => true,
]);
$response = $this->getJson('/api/tenants/bootstrap?dominio=acme.com&path=%2F')
->assertOk()
->assertJsonMissingPath('data.extras.heroConfig.crop_horizontal')
->assertJsonMissingPath('data.extras.heroConfig.crop_vertical');
$backgroundImage = $response->json('data.extras.heroConfig.background_image_id');
$this->assertIsString($backgroundImage);
$this->assertStringContainsString('cropped.jpg', $backgroundImage);
$this->assertStringNotContainsString('original.jpg', $backgroundImage);
}
public function test_it_returns_not_found_when_the_domain_does_not_exist(): void
{
$response = $this->getJson('/api/tenants/bootstrap?dominio=missing.example&path=%2F');