seed(RolePermissionSeeder::class); } protected function actingWithRole(string $role): User { $user = User::factory()->create(); $user->syncRoles([$role]); $this->withHeaders($this->apiHeadersFor($user)); return $user; } #[Test] public function the_health_report_lists_problems_first(): void { $this->actingWithRole('editor'); // Published with no Catalan title: one missing translation. Page::factory()->published()->create([ 'title' => ['es' => 'Hola', 'en' => 'Hello'], 'slug' => ['es' => 'hola', 'en' => 'hello'], ]); $response = $this->getJson('/api/v1/health')->assertOk(); $finding = collect($response->json('data'))->firstWhere('key', 'missing-translations'); $this->assertSame('warning', $finding['severity']); $this->assertSame(1, $finding['count']); $this->assertNotSame('ok', $response->json('data.0.severity')); $this->assertGreaterThanOrEqual(1, $response->json('meta.problems')); } #[Test] public function a_check_behind_a_permission_is_left_out(): void { $this->actingWithRole('viewer'); $keys = collect($this->getJson('/api/v1/health')->assertOk()->json('data'))->pluck('key'); // Strangers' submissions are not a viewer's to see, not even counted. $this->assertNotContains('unanswered-submissions', $keys); } #[Test] public function pending_translations_say_which_languages(): void { $this->actingWithRole('editor'); $page = Page::factory()->draft()->create([ 'title' => ['es' => 'Solo en castellano'], 'slug' => ['es' => 'solo'], ]); Page::factory()->draft()->create([ 'title' => ['es' => 'Completa', 'en' => 'Complete', 'ca' => 'Completa'], 'slug' => ['es' => 'completa', 'en' => 'complete', 'ca' => 'completa'], ]); $this->getJson('/api/v1/translations/pending?type=pages') ->assertOk() ->assertJsonCount(1, 'data') ->assertJsonPath('data.0.id', $page->id) ->assertJsonPath('data.0.missing', ['en', 'ca']); $this->getJson('/api/v1/translations/pending?locale=ca') ->assertJsonPath('data.0.missing', ['ca']); // Drafts only, so nothing is on the site yet. $this->getJson('/api/v1/translations/pending?published=1')->assertJsonCount(0, 'data'); } }