Skip to content

test: add image contract tests for getHeritageById#388

Merged
zigzagdev merged 2 commits intochore/integrate-image_url-into-image-tablefrom
chore/image_url-queryservice-test-fix
Mar 29, 2026
Merged

test: add image contract tests for getHeritageById#388
zigzagdev merged 2 commits intochore/integrate-image_url-into-image-tablefrom
chore/image_url-queryservice-test-fix

Conversation

@zigzagdev
Copy link
Copy Markdown
Owner

@zigzagdev zigzagdev commented Mar 29, 2026

What

  • Added seedImages() to setUp for image test data
  • Added test_images_contract() to verify image shape, ordering and is_primary
  • Added test_images_empty_when_no_images() to verify empty array is returned when no images exist

@zigzagdev zigzagdev requested a review from Copilot March 29, 2026 05:00
@zigzagdev zigzagdev self-assigned this Mar 29, 2026
@zigzagdev zigzagdev linked an issue Mar 29, 2026 that may be closed by this pull request
10 tasks
Copy link
Copy Markdown
Owner Author

@zigzagdev zigzagdev left a comment

Choose a reason for hiding this comment

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

Ok

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the World Heritage “get by id” query service tests to better validate the returned image payload and adjusts the Image model so is_primary is treated as a boolean.

Changes:

  • Add dedicated tests for the images payload contract and the “no images” case.
  • Introduce an is_primary boolean cast on the Image Eloquent model.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/app/Packages/Domains/Test/QueryService/WorldHeritageQueryService_getByIdTest.php Splits out image-related assertions into dedicated tests and adds an empty-images scenario.
src/app/Models/Image.php Adds a cast for is_primary to ensure boolean semantics at the model layer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +56 to +60
private function seedImages(): void
{
return
DB::table('world_heritage_site_images')->insert([
[
'world_heritage_site_id' => 1133,
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.
Comment on lines +195 to +199
$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']);
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.
$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.
Comment on lines +25 to +30
public function casts(): array
{
return [
'is_primary' => 'boolean',
];
}
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.
@zigzagdev zigzagdev changed the title Chore/image url queryservice test fix test: add image contract tests for getHeritageById Mar 29, 2026
@zigzagdev zigzagdev merged commit 9dcfd6d into chore/integrate-image_url-into-image-table Mar 29, 2026
29 checks passed
@zigzagdev zigzagdev deleted the chore/image_url-queryservice-test-fix branch March 29, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression tests (import + API contract)

2 participants