Add superadmin moderation queues
This commit is contained in:
89
tests/Feature/PhotoModerationQueueTest.php
Normal file
89
tests/Feature/PhotoModerationQueueTest.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Filament\Clusters\DailyOps\Resources\Photos\Pages\ListPhotos;
|
||||
use App\Models\Event;
|
||||
use App\Models\Photo;
|
||||
use App\Models\Tenant;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Testing\TestAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PhotoModerationQueueTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_superadmin_can_approve_pending_photo(): void
|
||||
{
|
||||
$user = User::factory()->create(['role' => 'super_admin']);
|
||||
$tenant = Tenant::factory()->create();
|
||||
$event = Event::factory()->create(['tenant_id' => $tenant->id]);
|
||||
$photo = Photo::factory()->for($event)->create([
|
||||
'status' => 'pending',
|
||||
'ingest_source' => Photo::SOURCE_GUEST_PWA,
|
||||
]);
|
||||
|
||||
$this->bootSuperAdminPanel($user);
|
||||
|
||||
Livewire::test(ListPhotos::class)
|
||||
->callAction(TestAction::make('approve')->table($photo), [
|
||||
'moderation_notes' => 'Looks good.',
|
||||
]);
|
||||
|
||||
$photo->refresh();
|
||||
|
||||
$this->assertSame('approved', $photo->status);
|
||||
$this->assertSame('Looks good.', $photo->moderation_notes);
|
||||
$this->assertNotNull($photo->moderated_at);
|
||||
$this->assertSame($user->id, $photo->moderated_by);
|
||||
}
|
||||
|
||||
public function test_superadmin_can_bulk_reject_pending_photos(): void
|
||||
{
|
||||
$user = User::factory()->create(['role' => 'super_admin']);
|
||||
$tenant = Tenant::factory()->create();
|
||||
$event = Event::factory()->create(['tenant_id' => $tenant->id]);
|
||||
$photoA = Photo::factory()->for($event)->create([
|
||||
'status' => 'pending',
|
||||
'ingest_source' => Photo::SOURCE_GUEST_PWA,
|
||||
]);
|
||||
$photoB = Photo::factory()->for($event)->create([
|
||||
'status' => 'pending',
|
||||
'ingest_source' => Photo::SOURCE_GUEST_PWA,
|
||||
]);
|
||||
|
||||
$this->bootSuperAdminPanel($user);
|
||||
|
||||
Livewire::test(ListPhotos::class)
|
||||
->callTableBulkAction('reject', [$photoA, $photoB], [
|
||||
'moderation_notes' => 'Policy violation.',
|
||||
]);
|
||||
|
||||
$photoA->refresh();
|
||||
$photoB->refresh();
|
||||
|
||||
$this->assertSame('rejected', $photoA->status);
|
||||
$this->assertSame('rejected', $photoB->status);
|
||||
$this->assertSame('Policy violation.', $photoA->moderation_notes);
|
||||
$this->assertSame('Policy violation.', $photoB->moderation_notes);
|
||||
$this->assertNotNull($photoA->moderated_at);
|
||||
$this->assertNotNull($photoB->moderated_at);
|
||||
$this->assertSame($user->id, $photoA->moderated_by);
|
||||
$this->assertSame($user->id, $photoB->moderated_by);
|
||||
}
|
||||
|
||||
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