feat: action links, telegram webhook and channels API

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-04 07:52:12 -03:00
parent 6138ac7bb0
commit 90d17ec378
8 changed files with 450 additions and 10 deletions

View File

@@ -0,0 +1,66 @@
<?php
namespace Tests\Feature;
use App\Enums\AfterDue;
use App\Enums\ChannelType;
use App\Enums\DeliveryResult;
use App\Enums\DueMode;
use App\Enums\EventState;
use App\Models\Channel;
use App\Models\Delivery;
use App\Models\Event;
use App\Models\Source;
use App\Models\User;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ActionLinksTest extends TestCase
{
use RefreshDatabase;
private Event $event;
protected function setUp(): void
{
parent::setUp();
CarbonImmutable::setTestNow('2026-09-30T11:17:00Z');
$source = Source::create(['name' => 'docs', 'token_hash' => hash('sha256', 'x')]);
$user = User::create(['login' => 'n', 'tz' => 'UTC', 'quiet_start' => '22:00:00', 'quiet_end' => '09:00:00']);
$channel = Channel::create(['user_id' => $user->id, 'type' => ChannelType::Webhook, 'config' => ['deliver_url' => 'u', 'presence_url' => 'p'], 'enabled' => true]);
$this->event = Event::create([
'source_id' => $source->id, 'user_id' => $user->id, 'source_ref' => 'r', 'topic' => '',
'due_mode' => DueMode::Local, 'due_date' => '2026-09-30', 'due_time' => '24:00:00', 'fire_on' => '2026-09-30',
'after_due' => AfterDue::Keep, 'payload' => ['title' => 'T'], 'state' => EventState::Today,
'quiet_until' => CarbonImmutable::parse('2000-01-01Z'),
]);
Delivery::create(['event_id' => $this->event->id, 'channel_id' => $channel->id, 'window_start' => now(), 'action_token' => 'tok', 'result' => DeliveryResult::Ok]);
}
protected function tearDown(): void
{
CarbonImmutable::setTestNow();
parent::tearDown();
}
public function test_ack_by_token(): void
{
$this->postJson('/a/tok/ack')->assertOk()->assertJsonPath('state', 'today');
$this->assertSame('2026-09-30T13:00:00+00:00', $this->event->fresh()->quiet_until->toIso8601String());
}
public function test_done_by_token_then_gone(): void
{
$this->postJson('/a/tok/done')->assertOk()->assertJsonPath('state', 'done');
$this->assertSame(EventState::Done, $this->event->fresh()->state);
$this->postJson('/a/tok/done')->assertStatus(410);
$this->postJson('/a/tok/ack')->assertStatus(410);
}
public function test_unknown_token(): void
{
$this->postJson('/a/nope/done')->assertNotFound();
}
}