Files
hado/core/tests/Feature/PurgeCommandTest.php
nikita.hohlov affac4ce1a feat: tick planner, delivery job, scheduler and purge
Also: test uses disabled channels instead of deleting them (FK cascade); ChannelRegistry no longer final so tests can extend it (controller ruling).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
2026-09-04 07:38:16 -03:00

43 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Enums\AfterDue;
use App\Enums\DueMode;
use App\Enums\EventState;
use App\Models\Event;
use App\Models\Source;
use App\Models\User;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PurgeCommandTest extends TestCase
{
use RefreshDatabase;
public function test_deletes_old_terminal_events_only(): void
{
config(['hado.retention_days' => 90]);
$source = Source::create(['name' => 'docs', 'token_hash' => hash('sha256', 'x')]);
$user = User::create(['login' => 'n', 'tz' => 'UTC']);
$make = fn (string $topic, EventState $state, string $updatedAt) => tap(Event::create([
'source_id' => $source->id, 'user_id' => $user->id, 'source_ref' => 'r', 'topic' => $topic,
'due_mode' => DueMode::Local, 'due_date' => '2026-01-01', 'due_time' => '24:00:00', 'fire_on' => '2026-01-01',
'after_due' => AfterDue::Keep, 'payload' => ['title' => 'T'], 'state' => $state,
'quiet_until' => CarbonImmutable::parse('2000-01-01Z'),
]), fn (Event $e) => Event::whereKey($e->id)->update(['updated_at' => $updatedAt]));
CarbonImmutable::setTestNow('2026-09-04T12:00:00Z');
$make('old-done', EventState::Done, '2026-05-01 00:00:00');
$make('old-expired', EventState::Expired, '2026-05-01 00:00:00');
$make('fresh-done', EventState::Done, '2026-08-01 00:00:00');
$make('old-live', EventState::Overdue, '2026-05-01 00:00:00');
$this->artisan('hado:purge')->assertSuccessful();
$this->assertSame(['fresh-done', 'old-live'], Event::orderBy('topic')->pluck('topic')->all());
CarbonImmutable::setTestNow();
}
}