Add join token expiry action in event modal
This commit is contained in:
64
tests/Feature/EventJoinTokenExpiryActionTest.php
Normal file
64
tests/Feature/EventJoinTokenExpiryActionTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user