Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
96
tests/Feature/Site/ContentVersionTest.php
Normal file
96
tests/Feature/Site/ContentVersionTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Site;
|
||||
|
||||
use App\Enums\PageStatus;
|
||||
use App\Models\Page;
|
||||
use App\Models\Project;
|
||||
use App\Support\ContentVersion;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* The number that tells the frontend its cache is stale.
|
||||
*
|
||||
* The public API is cached with a long `stale-while-revalidate`, which is
|
||||
* right for an SSR frontend and wrong for an urgent correction. This is how a
|
||||
* fix stops sitting behind a stale copy without a purge webhook or anything to
|
||||
* deploy.
|
||||
*/
|
||||
class ContentVersionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->withHeaders(['Accept-Language' => 'es']);
|
||||
Queue::fake();
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function the_frontend_is_given_a_version(): void
|
||||
{
|
||||
$this->getJson('/api/public/v1/site')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.content_version', ContentVersion::current());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function publishing_something_moves_it(): void
|
||||
{
|
||||
$before = ContentVersion::current();
|
||||
|
||||
Project::factory()->published()->create();
|
||||
|
||||
$this->assertGreaterThan($before, ContentVersion::current());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function a_draft_nobody_can_see_does_not(): void
|
||||
{
|
||||
Project::factory()->draft()->create();
|
||||
|
||||
$before = ContentVersion::current();
|
||||
|
||||
Project::query()->first()->update(['title' => ['es' => 'Otro borrador']]);
|
||||
|
||||
// Editing something invisible invalidates nobody's cache, and bumping
|
||||
// on every keystroke of a half-written page would make the number
|
||||
// meaningless.
|
||||
$this->assertSame($before, ContentVersion::current());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function taking_something_down_moves_it_too(): void
|
||||
{
|
||||
$page = Page::factory()->create([
|
||||
'status' => PageStatus::Published,
|
||||
'published_at' => now()->subDay(),
|
||||
]);
|
||||
|
||||
$before = ContentVersion::current();
|
||||
|
||||
$page->update(['status' => PageStatus::Draft]);
|
||||
|
||||
// Going away is exactly as visible to a reader as arriving.
|
||||
$this->assertGreaterThan($before, ContentVersion::current());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function deleting_published_work_moves_it(): void
|
||||
{
|
||||
$project = Project::factory()->published()->create();
|
||||
|
||||
$before = ContentVersion::current();
|
||||
|
||||
$project->delete();
|
||||
|
||||
$this->assertGreaterThan($before, ContentVersion::current());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user