-
Notifications
You must be signed in to change notification settings - Fork 0
test: add image contract tests for getHeritageById #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||
| { | ||||||||||
|
|
@@ -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
|
||||||||||
| '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 | ||||||||||
|
|
@@ -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
|
||||||||||
|
|
||||||||||
| foreach ($images as $img) { | ||||||||||
| $this->assertArrayHasKey('id', $img); | ||||||||||
| $this->assertArrayHasKey('url', $img); | ||||||||||
| $this->assertArrayHasKey('sort_order', $img); | ||||||||||
| $this->assertArrayHasKey('is_primary', $img); | ||||||||||
|
||||||||||
| $this->assertArrayHasKey('is_primary', $img); | |
| $this->assertArrayHasKey('is_primary', $img); | |
| $this->assertIsString($img['url']); | |
| $this->assertNotEmpty($img['url']); |
There was a problem hiding this comment.
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.,WorldHeritageusesprotected function casts(): array). Making thispublicunnecessarily exposes an internal model hook; switch it toprotectedto match Laravel conventions and local style.