Portale als Kacheln zeigen und Kalenderabrufe je Kanal protokollieren
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m41s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m41s
This commit is contained in:
1 parent
98eabaeb0c
commit
511faa64d2
12 files changed
+337
-98
No files matched your search
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Actions\ConfigureChannel;
|
||||
use App\Actions\RotateChannelToken;
|
||||
use App\Filament\Resources\Channels\Pages\ListChannels;
|
||||
use App\Models\Channel;
|
||||
use App\Models\ChannelExportRequest;
|
||||
use App\Models\Property;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use App\Tenancy\TenantContext;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Filament\Actions\Testing\TestAction;
|
||||
use Filament\Infolists\Components\RepeatableEntry;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ChannelExportRequestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_feed_receipt_is_tracked_per_channel_without_claiming_portal_processing(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$channel = Channel::factory()->for($property)->create();
|
||||
$this->withHeader('User-Agent', 'Synthetic-Portal/1.0')->get($channel->exportUrl())->assertOk();
|
||||
$entry = $channel->exportRequests()->sole();
|
||||
$this->assertSame([$property->tenant_id, 'GET', 'Synthetic-Portal/1.0', 200, 'live'], [$entry->tenant_id, $entry->method, $entry->user_agent, $entry->response_status, $entry->export_state]);
|
||||
$this->assertSame('2026-10-27 12:00:00', $entry->requested_at->format('Y-m-d H:i:s'));
|
||||
$this->assertSame($entry->requested_at->toDateTimeString(), $channel->fresh()->last_export_requested_at->toDateTimeString());
|
||||
$this->assertNull($channel->fresh()->portal_verified_at);
|
||||
$this->assertNull($channel->fresh()->last_success_at);
|
||||
$this->assertStringNotContainsString($channel->export_token, $entry->toJson());
|
||||
$this->assertArrayNotHasKey('ip_address', $entry->toArray());
|
||||
}
|
||||
|
||||
public function test_head_and_paused_export_are_recorded_as_receipts_without_changing_the_frozen_feed(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$channel = Channel::factory()->for($property)->create();
|
||||
$body = $this->get($channel->exportUrl())->assertOk()->getContent();
|
||||
app(ConfigureChannel::class)->handle($property, ['export_enabled' => false], $channel);
|
||||
$this->travel(2)->minutes();
|
||||
$this->head($channel->exportUrl())->assertOk();
|
||||
$entry = $channel->exportRequests()->first();
|
||||
$this->assertSame(['HEAD', 'frozen', 200], [$entry->method, $entry->export_state, $entry->response_status]);
|
||||
$this->assertSame($body, $channel->fresh()->export_snapshot);
|
||||
$this->assertSame(2, $channel->exportRequests()->count());
|
||||
}
|
||||
|
||||
public function test_paused_feed_without_snapshot_records_503_and_invalid_token_is_not_a_channel_request(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$channel = app(ConfigureChannel::class)->handle($property, ['name' => 'Unbekanntes Portal', 'connector' => 'ical']);
|
||||
$this->get($channel->exportUrl())->assertStatus(503);
|
||||
$this->get('/kalender/not-a-valid-token.ics')->assertNotFound();
|
||||
$this->assertSame(1, ChannelExportRequest::count());
|
||||
$this->assertSame([503, 'unavailable'], [$channel->exportRequests()->sole()->response_status, $channel->exportRequests()->sole()->export_state]);
|
||||
}
|
||||
|
||||
public function test_history_is_bounded_independently_for_each_channel_without_a_scheduler(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$a = Channel::factory()->for($property)->create();
|
||||
$b = Channel::factory()->for($property)->create();
|
||||
config(['channels.export_request_history_limit' => 2]);
|
||||
$this->withHeader('User-Agent', 'First')->get($a->exportUrl())->assertOk();
|
||||
$this->withHeader('User-Agent', 'Other')->get($b->exportUrl())->assertOk();
|
||||
$this->withHeader('User-Agent', 'Second')->get($a->exportUrl())->assertOk();
|
||||
$this->withHeader('User-Agent', 'Third')->get($a->exportUrl())->assertOk();
|
||||
$this->assertSame(['Third', 'Second'], $a->exportRequests()->pluck('user_agent')->all());
|
||||
$this->assertSame(['Other'], $b->exportRequests()->pluck('user_agent')->all());
|
||||
}
|
||||
|
||||
public function test_old_and_new_tokens_during_rotation_share_one_channel_history(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$channel = Channel::factory()->for($property)->create();
|
||||
$oldLink = $channel->exportUrl();
|
||||
$rotated = app(RotateChannelToken::class)->handle($channel);
|
||||
$this->get($oldLink)->assertOk();
|
||||
$this->get($rotated->exportUrl())->assertOk();
|
||||
$this->assertSame(2, $channel->exportRequests()->count());
|
||||
$this->assertSame([$channel->id], ChannelExportRequest::pluck('channel_id')->unique()->all());
|
||||
}
|
||||
|
||||
public function test_card_shows_sync_status_and_received_request_separately_and_history_requires_explicit_action(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$channel = Channel::factory()->for($property)->create(['last_synced_at' => now()->subMinutes(10), 'last_success_at' => now()->subMinutes(10)]);
|
||||
$this->withHeader('User-Agent', 'Unverified-Client/9')->get($channel->exportUrl())->assertOk();
|
||||
$this->actingAs(User::factory()->create());
|
||||
$page = Livewire::test(ListChannels::class)->assertCanSeeTableRecords([$channel])->assertSee('Letzter Sync: 27.10.2026 11:50')->assertSee('Letzter Abruf: 27.10.2026 12:00')->assertDontSee('Unverified-Client/9')->assertDontSee($channel->export_token);
|
||||
$page->mountAction(TestAction::make('exportRequests')->table($channel))->assertActionMounted(TestAction::make('exportRequests')->table($channel));
|
||||
$schema = $page->instance()->getSchema($page->instance()->getMountedActionSchemaName());
|
||||
$entries = collect($schema->getFlatComponents())->first(fn ($component): bool => $component instanceof RepeatableEntry);
|
||||
$this->assertSame('Unverified-Client/9', $entries->getState()[0]['client']);
|
||||
}
|
||||
|
||||
public function test_request_history_is_not_visible_across_landlords(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$channel = Channel::factory()->for($property)->create();
|
||||
$this->get($channel->exportUrl())->assertOk();
|
||||
$other = Tenant::factory()->create();
|
||||
app(TenantContext::class)->set($other);
|
||||
$this->assertSame(0, ChannelExportRequest::count());
|
||||
$this->assertSame(0, $channel->exportRequests()->count());
|
||||
}
|
||||
|
||||
public function test_client_metadata_is_bounded_and_does_not_keep_reflected_export_tokens(): void
|
||||
{
|
||||
$property = $this->property();
|
||||
$channel = Channel::factory()->for($property)->create();
|
||||
$oldToken = $channel->export_token;
|
||||
$rotated = app(RotateChannelToken::class)->handle($channel);
|
||||
$agent = 'Synthetic '.$oldToken.' '.$rotated->export_token.' '.str_repeat('x', 600);
|
||||
|
||||
$this->withHeader('User-Agent', $agent)->get($rotated->exportUrl())->assertOk();
|
||||
|
||||
$recorded = $channel->exportRequests()->sole()->user_agent;
|
||||
$this->assertSame(512, mb_strlen($recorded));
|
||||
$this->assertStringNotContainsString($oldToken, $recorded);
|
||||
$this->assertStringNotContainsString($rotated->export_token, $recorded);
|
||||
}
|
||||
|
||||
private function property(): Property
|
||||
{
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-27 12:00'));
|
||||
$this->seed(PropertySeeder::class);
|
||||
$property = Property::sole();
|
||||
app(TenantContext::class)->set($property->tenant);
|
||||
|
||||
return $property;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user