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', []); } 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, ]); } }