65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Filament\Resources\EventResource\Pages\ListEvents;
|
|
use App\Models\Event;
|
|
use App\Models\User;
|
|
use App\Services\EventJoinTokenService;
|
|
use Filament\Actions\Testing\TestAction;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class EventJoinTokenExpiryActionTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_superadmin_can_extend_join_token_expiry(): void
|
|
{
|
|
$user = User::factory()->create(['role' => 'super_admin']);
|
|
$event = Event::factory()->create([
|
|
'date' => now()->addDays(10),
|
|
]);
|
|
|
|
$token = $event->joinTokens()->latest('id')->first();
|
|
|
|
$minimumExpiry = app(EventJoinTokenService::class)->minimumExpiryForEvent($event);
|
|
$newExpiry = ($minimumExpiry ?? now()->addDay())->copy()->addDays(2)->seconds(0);
|
|
|
|
$this->bootSuperAdminPanel($user);
|
|
|
|
Livewire::test(ListEvents::class)
|
|
->callAction(
|
|
[
|
|
TestAction::make('join_tokens')->table($event),
|
|
TestAction::make('extend_join_token_expiry')
|
|
->arguments(['token_id' => $token->id]),
|
|
],
|
|
[
|
|
'expires_at' => $newExpiry->toDateTimeString(),
|
|
]
|
|
)
|
|
->assertHasNoErrors();
|
|
|
|
$token->refresh();
|
|
|
|
$this->assertSame(
|
|
$newExpiry->toDateTimeString(),
|
|
$token->expires_at?->toDateTimeString()
|
|
);
|
|
}
|
|
|
|
private function bootSuperAdminPanel(User $user): void
|
|
{
|
|
$panel = Filament::getPanel('superadmin');
|
|
|
|
$this->assertNotNull($panel);
|
|
|
|
Filament::setCurrentPanel($panel);
|
|
Filament::bootCurrentPanel();
|
|
Filament::auth()->login($user);
|
|
}
|
|
}
|