create(); $category->setTranslation('title', 'fa', 'دسته'); $category->save(); $project = Project::factory()->create(['category_id' => $category->id]); $project->setTranslation('title', 'fa', 'پروژه'); $project->setTranslation('description', 'fa', 'توضیحات'); $project->save(); $response = $this->getJson('/api/website/projects/translation/fa'); $response->assertStatus(200); $response->assertJsonStructure(['projects', 'categories']); } public function test_can_get_single_project() { $category = ProjectCategory::factory()->create(); $project = Project::factory()->create(['category_id' => $category->id]); $response = $this->getJson("/api/website/projects/{$project->id}/translation/en"); $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')); } }