Report site health and pending translations through the API
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
97
tests/Feature/Api/HealthApiTest.php
Normal file
97
tests/Feature/Api/HealthApiTest.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api;
|
||||
|
||||
use App\Models\Page;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RolePermissionSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\FakesPireon;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* The site's health and what is left to translate, through the admin API.
|
||||
*/
|
||||
class HealthApiTest extends TestCase
|
||||
{
|
||||
use FakesPireon, RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user