refactor: single EventPresenter and ManualEvents shared by /api, /me, inbox, webhook; editable flag

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
nikita.hohlov
2026-09-05 06:01:55 -03:00
parent 2ec71ab710
commit 9163ff97f9
10 changed files with 297 additions and 75 deletions

View File

@@ -0,0 +1,53 @@
<?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 EventPresentationTest extends TestCase
{
use RefreshDatabase;
private array $as = ['X-Remote-User' => 'nikita'];
protected function setUp(): void
{
parent::setUp();
config(['hado.default_tz' => 'UTC']);
CarbonImmutable::setTestNow('2026-09-05T12:00:00Z');
}
protected function tearDown(): void
{
CarbonImmutable::setTestNow();
parent::tearDown();
}
public function test_user_facing_events_say_whether_they_are_editable(): void
{
$this->getJson('/me', $this->as);
$user = User::sole();
$docs = Source::create(['name' => 'docs', 'token_hash' => hash('sha256', 'x')]);
Event::create([
'source_id' => $docs->id, 'user_id' => $user->id, 'source_ref' => 'person:1', 'topic' => 'bd',
'due_mode' => DueMode::Local, 'due_date' => '2026-09-05', 'due_time' => '24:00:00', 'fire_on' => '2026-09-05',
'after_due' => AfterDue::Keep, 'payload' => ['title' => 'ДР'], 'state' => EventState::Today,
'quiet_until' => CarbonImmutable::now()->subDay(),
]);
$this->postJson('/me/events', ['title' => 'Своё', 'due_date' => '2026-10-01'], $this->as)
->assertCreated()->assertJsonPath('editable', true);
$bySource = collect($this->getJson('/me/events', $this->as)->assertOk()->json('events'))->keyBy('source');
$this->assertFalse($bySource['docs']['editable']);
$this->assertTrue($bySource['manual']['editable']);
}
}