Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/app/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class Image extends Model
'updated_at',
];

public function casts(): array
{
return [
'is_primary' => 'boolean',
];
}
Comment on lines +25 to +30
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casts() should follow the same visibility pattern used by other Eloquent models in this repo (e.g., WorldHeritage uses protected function casts(): array). Making this public unnecessarily exposes an internal model hook; switch it to protected to match Laravel conventions and local style.

Copilot uses AI. Check for mistakes.

public function worldHeritage()
{
return $this->belongsTo(WorldHeritage::class, 'world_heritage_site_id', 'id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
use App\Models\Image;
use App\Packages\Domains\Ports\SignedUrlPort;
use Mockery;

class WorldHeritageQueryService_getByIdTest extends TestCase
{
Expand Down Expand Up @@ -55,51 +53,74 @@ private function refresh(): void
}
}

private function arrayData(): array
private function seedImages(): void
{
return
DB::table('world_heritage_site_images')->insert([
[
'world_heritage_site_id' => 1133,
Comment on lines +56 to +60
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seedImages() is declared but never called in this test class. If the intent is to make image assertions independent of DatabaseSeeder/ImageSeeder, call it in setUp() (and ensure the table is clean before inserting); otherwise remove the unused helper to avoid dead code in tests.

Copilot uses AI. Check for mistakes.
'url' => 'https://example.com/image1.jpg',
'url_hash' => hash('sha256', 'https://example.com/image1.jpg'),
'sort_order' => 0,
'is_primary' => true,
'created_at' => now(),
'updated_at' => now(),
],
[
'id' => 1133,
'official_name' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe",
'name' => "Ancient and Primeval Beech Forests",
'heritage_name_jp' => "カルパティア山脈とヨーロッパ各地の古代及び原生ブナ林",
'country' => 'Slovakia',
'study_region' => 'Europe',
'category' => 'Natural',
'criteria' => ['ix'],
'state_party' => null,
'year_inscribed' => 2007,
'area_hectares' => 99947.81,
'buffer_zone_hectares' => 296275.8,
'is_endangered' => false,
'latitude' => 0.0,
'longitude' => 0.0,
'short_description' => '氷期後のブナの自然拡散史を示すヨーロッパ各地の原生的ブナ林群から成る越境・連続資産。',
'unesco_site_url' => 'https://whc.unesco.org/en/list/1133',
'state_parties_codes' => [
'ALB','AUT','BEL','BIH','BGR','HRV','CZE','FRA','DEU','ITA','MKD','POL','ROU','SVK','SVN','ESP','CHE','UKR'
],
'state_parties_meta' => [
'ALB' => ['is_primary' => false],
'AUT' => ['is_primary' => false],
'BEL' => ['is_primary' => false],
'BIH' => ['is_primary' => false],
'BGR' => ['is_primary' => false],
'HRV' => ['is_primary' => false],
'CZE' => ['is_primary' => false],
'FRA' => ['is_primary' => false],
'DEU' => ['is_primary' => false],
'ITA' => ['is_primary' => false],
'MKD' => ['is_primary' => false],
'POL' => ['is_primary' => false],
'ROU' => ['is_primary' => false],
'SVK' => ['is_primary' => true],
'SVN' => ['is_primary' => false],
'ESP' => ['is_primary' => false],
'CHE' => ['is_primary' => false],
'UKR' => ['is_primary' => false],
]
];
'world_heritage_site_id' => 1133,
'url' => 'https://example.com/image2.jpg',
'url_hash' => hash('sha256', 'https://example.com/image2.jpg'),
'sort_order' => 1,
'is_primary' => false,
'created_at' => now(),
'updated_at' => now(),
],
]);
}

private function arrayData(): array
{
return [
'id' => 1133,
'official_name' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe",
'name' => "Ancient and Primeval Beech Forests",
'heritage_name_jp' => "カルパティア山脈とヨーロッパ各地の古代及び原生ブナ林",
'country' => 'Slovakia',
'study_region' => 'Europe',
'category' => 'Natural',
'criteria' => ['ix'],
'state_party' => null,
'year_inscribed' => 2007,
'area_hectares' => 99947.81,
'buffer_zone_hectares' => 296275.8,
'is_endangered' => false,
'latitude' => 0.0,
'longitude' => 0.0,
'short_description' => '氷期後のブナの自然拡散史を示すヨーロッパ各地の原生的ブナ林群から成る越境・連続資産。',
'unesco_site_url' => 'https://whc.unesco.org/en/list/1133',
'state_parties_codes' => [
'ALB','AUT','BEL','BIH','BGR','HRV','CZE','FRA','DEU','ITA','MKD','POL','ROU','SVK','SVN','ESP','CHE','UKR'
],
'state_parties_meta' => [
'ALB' => ['is_primary' => false],
'AUT' => ['is_primary' => false],
'BEL' => ['is_primary' => false],
'BIH' => ['is_primary' => false],
'BGR' => ['is_primary' => false],
'HRV' => ['is_primary' => false],
'CZE' => ['is_primary' => false],
'FRA' => ['is_primary' => false],
'DEU' => ['is_primary' => false],
'ITA' => ['is_primary' => false],
'MKD' => ['is_primary' => false],
'POL' => ['is_primary' => false],
'ROU' => ['is_primary' => false],
'SVK' => ['is_primary' => true],
'SVN' => ['is_primary' => false],
'ESP' => ['is_primary' => false],
'CHE' => ['is_primary' => false],
'UKR' => ['is_primary' => false],
]
];
}

public function test_queryService_check(): void
Expand Down Expand Up @@ -163,13 +184,39 @@ public function test_check_data_value(): void
$this->assertEquals($this->arrayData()['unesco_site_url'], $result->getUnescoSiteUrl());
$this->assertEquals($expectedCodes, $result->getStatePartyCodes());
$this->assertEquals($orderedExpected, $result->getStatePartiesMeta());
foreach ($result->getImages() as $img) {
}

public function test_images_contract(): void
{
$result = $this->queryService->getHeritageById($this->arrayData()['id']);
$images = $result->getImages();

$this->assertIsArray($images);
$this->assertNotEmpty($images);
$this->assertTrue($images[0]['is_primary']);
$this->assertEquals(0, $images[0]['sort_order']);
$this->assertFalse($images[1]['is_primary']);
$this->assertEquals(1, $images[1]['sort_order']);
Comment on lines +195 to +199
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_images_contract indexes $images[1] but only asserts assertNotEmpty($images), which guarantees at least 1 element. Add an assertion that there are at least 2 images (or guard the second access) so the test fails with a clear message instead of an undefined offset error.

Copilot uses AI. Check for mistakes.

foreach ($images as $img) {
$this->assertArrayHasKey('id', $img);
$this->assertArrayHasKey('url', $img);
$this->assertArrayHasKey('sort_order', $img);
$this->assertArrayHasKey('is_primary', $img);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image contract assertions no longer verify that url is non-empty. Since world_heritage_site_images.url is non-null and import logic filters out empty URLs, consider restoring an assertion that each returned url is a non-empty string to prevent silent regressions.

Suggested change
$this->assertArrayHasKey('is_primary', $img);
$this->assertArrayHasKey('is_primary', $img);
$this->assertIsString($img['url']);
$this->assertNotEmpty($img['url']);

Copilot uses AI. Check for mistakes.
$this->assertIsBool($img['is_primary']);
$this->assertNotEmpty($img['url']);
}
}

public function test_images_empty_when_no_images(): void
{
DB::table('world_heritage_site_images')
->where('world_heritage_site_id', 1133)
->delete();


$result = $this->queryService->getHeritageById(1133);

$this->assertIsArray($result->getImages());
$this->assertEmpty($result->getImages());
}
}
Loading