Admin can now control channel creation from the admin dashboard

This commit is contained in:
2026-05-16 03:43:25 +03:30
parent 34445f3032
commit f46f32aa4c
14 changed files with 639 additions and 95 deletions

View File

@@ -4,6 +4,7 @@ namespace Tests\Feature;
use App\Models\Broadcast;
use App\Models\Channel;
use App\Models\PlatformSetting;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
@@ -34,4 +35,65 @@ class AdminDashboardTest extends TestCase
->where('channels.0.thumbnail_url', '/storage/channels/demo/thumb.jpg'),
);
}
public function test_admin_dashboard_exposes_channel_creation_controls(): void
{
$admin = User::factory()->create(['is_admin' => true]);
$creator = User::factory()->create(['can_create_channel' => true]);
Channel::factory()->for($creator)->create(['display_name' => 'Creator One']);
$this->actingAs($admin)
->get(route('admin.dashboard'))
->assertOk()
->assertInertia(fn (Assert $page) => $page
->component('admin/dashboard')
->where('channelCreationPolicy.channel_creation_open', false)
->where('users.0.id', $creator->id)
->where('users.0.can_create_channel', true)
->where('users.0.channel.display_name', 'Creator One'),
);
}
public function test_admin_can_update_channel_creation_default(): void
{
$admin = User::factory()->create(['is_admin' => true]);
$this->actingAs($admin)
->patch(route('admin.channel-creation.update'), [
'channel_creation_open' => true,
])
->assertRedirect()
->assertSessionHasNoErrors();
$this->assertTrue(PlatformSetting::current()->channel_creation_open);
}
public function test_admin_can_grant_user_channel_creation_access(): void
{
$admin = User::factory()->create(['is_admin' => true]);
$user = User::factory()->create(['can_create_channel' => false]);
$this->actingAs($admin)
->patch(route('admin.users.creator-access.update', $user), [
'can_create_channel' => true,
])
->assertRedirect()
->assertSessionHasNoErrors();
$this->assertTrue($user->refresh()->can_create_channel);
}
public function test_non_admin_cannot_update_user_channel_creation_access(): void
{
$user = User::factory()->create();
$target = User::factory()->create();
$this->actingAs($user)
->patch(route('admin.users.creator-access.update', $target), [
'can_create_channel' => true,
])
->assertForbidden();
$this->assertFalse($target->refresh()->can_create_channel);
}
}