Files
hado/core/tests/Feature/EventPresentationTest.php

54 lines
1.8 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 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']);
}
}