Filter projects by category id and expose category_id
Deploy Backend / deploy (push) Successful in 2m44s

This commit is contained in:
Parsa Aghayi authored and DevOps committed 2026-10-04 05:32:23 +00:00
1 parent eacd0d73f1
commit c2960c4ed0
2 files changed
+58 -1

No files matched your search

+40
View File
@@ -37,4 +37,44 @@ class ProjectTest extends TestCase
$response->assertStatus(200);
}
/**
* The category tabs on the website filter by category id, because titles are
* translated and fall back to English when a translation is missing.
*/
public function test_can_filter_projects_by_category_id()
{
$first = ProjectCategory::factory()->create();
$first->setTranslation('title', 'en', 'App Design');
$first->save();
$second = ProjectCategory::factory()->create();
$second->setTranslation('title', 'en', 'Backend');
$second->save();
$wanted = Project::factory()->create(['category_id' => $first->id]);
Project::factory()->create(['category_id' => $second->id]);
$response = $this->getJson("/api/website/projects/translation/en?category_id={$first->id}");
$response->assertStatus(200);
$response->assertJsonCount(1, 'projects.data');
$this->assertSame($wanted->id, $response->json('projects.data.0.id'));
$this->assertSame($first->id, $response->json('projects.data.0.category_id'));
}
public function test_projects_expose_their_category_id()
{
$category = ProjectCategory::factory()->create();
$project = Project::factory()->create(['category_id' => $category->id]);
$response = $this->getJson('/api/website/projects/translation/en');
$response->assertStatus(200);
$this->assertSame($category->id, $response->json('projects.data.0.category_id'));
$single = $this->getJson("/api/website/projects/{$project->id}/translation/en");
$single->assertStatus(200);
$this->assertSame($category->id, $single->json('project.category_id'));
}
}