Warn about calls closing and content coming off the site

A dashboard widget lists what expires in the next two weeks, and a daily
command reminds whoever edits it a week and a day ahead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 10:16:24 +02:00
parent 366568b793
commit 773d3901c6
15 changed files with 442 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace Tests\Feature\Panel;
use App\Enums\CallStatus;
use App\Filament\Widgets\ExpiringSoon as ExpiringSoonWidget;
use App\Models\Call;
use App\Models\Page;
use App\Notifications\ExpiringSoon;
use App\Support\Expiring;
use Database\Seeders\RolePermissionSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Livewire;
use PHPUnit\Framework\Attributes\Test;
use Tests\FakesPireon;
use Tests\TestCase;
/**
* Calls about to close and content about to come off the site: on the
* dashboard, and as a reminder a week and a day ahead.
*/
class ExpiringSoonTest extends TestCase
{
use FakesPireon, RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed(RolePermissionSeeder::class);
}
#[Test]
public function it_finds_what_closes_or_comes_off_soon_and_nothing_else(): void
{
$closing = Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(3)]);
Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addMonths(2)]);
Call::factory()->create(['status' => CallStatus::Closed, 'closes_at' => now()->addDays(3)]);
$leaving = Page::factory()->published()->create(['unpublish_at' => now()->addDays(5)]);
Page::factory()->draft()->create(['unpublish_at' => now()->addDays(5)]);
$items = Expiring::within(14);
$this->assertSame([[$closing->id, 'closes'], [$leaving->id, 'unpublishes']], $items->map(fn ($i) => [$i['record']->id, $i['event']])->all());
}
#[Test]
public function the_dashboard_shows_it_to_whoever_can_act(): void
{
Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(3), 'title' => ['es' => 'Backend', 'en' => 'Backend']]);
$this->actingAs($this->userWithRoles('editor'));
$this->assertTrue(ExpiringSoonWidget::canView());
Livewire::test(ExpiringSoonWidget::class)->assertSee('Backend');
$this->actingAs($this->userWithRoles('viewer'));
$this->assertFalse(ExpiringSoonWidget::canView());
}
#[Test]
public function editors_are_reminded_a_week_and_a_day_ahead_only(): void
{
Notification::fake();
$editor = $this->userWithRoles('editor');
$viewer = $this->userWithRoles('viewer');
Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(7)]);
Call::factory()->create(['status' => CallStatus::Open, 'closes_at' => now()->addDays(4)]);
$this->artisan('content:expiring')->assertSuccessful();
Notification::assertSentTo($editor, ExpiringSoon::class, fn (ExpiringSoon $n) => $n->items->count() === 1);
Notification::assertNotSentTo($viewer, ExpiringSoon::class);
}
}