Admin can now control channel creation from the admin dashboard
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Channel;
|
||||
use App\Models\PlatformSetting;
|
||||
use App\Models\StreamKey;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -13,9 +14,9 @@ class CreatorChannelTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_user_can_create_one_channel_and_receives_one_time_stream_key(): void
|
||||
public function test_user_with_creator_access_can_create_one_channel_and_receives_one_time_stream_key(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$user = User::factory()->create(['can_create_channel' => true]);
|
||||
$category = Category::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('creator.channel.store'), [
|
||||
@@ -39,9 +40,48 @@ class CreatorChannelTest extends TestCase
|
||||
$this->assertDatabaseCount(StreamKey::class, 1);
|
||||
}
|
||||
|
||||
public function test_user_cannot_create_more_than_one_channel(): void
|
||||
public function test_user_without_creator_access_cannot_create_channel(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('creator.channel.store'), [
|
||||
'display_name' => 'Nyone Live',
|
||||
'slug' => 'nyone-live',
|
||||
]);
|
||||
|
||||
$response->assertForbidden();
|
||||
|
||||
$this->assertDatabaseMissing(Channel::class, [
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_channel_creation_can_be_opened_by_default(): void
|
||||
{
|
||||
PlatformSetting::current()->forceFill([
|
||||
'channel_creation_open' => true,
|
||||
])->save();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('creator.channel.store'), [
|
||||
'display_name' => 'Nyone Live',
|
||||
'slug' => 'nyone-live',
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertRedirect(route('dashboard', absolute: false))
|
||||
->assertSessionHas('plain_stream_key');
|
||||
|
||||
$this->assertDatabaseHas(Channel::class, [
|
||||
'user_id' => $user->id,
|
||||
'slug' => 'nyone-live',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_user_cannot_create_more_than_one_channel(): void
|
||||
{
|
||||
$user = User::factory()->create(['can_create_channel' => true]);
|
||||
Channel::factory()->for($user)->create();
|
||||
|
||||
$response = $this->actingAs($user)->post(route('creator.channel.store'), [
|
||||
|
||||
@@ -30,6 +30,19 @@ class DashboardTest extends TestCase
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
public function test_creator_dashboard_exposes_channel_creation_access(): void
|
||||
{
|
||||
$user = User::factory()->create(['can_create_channel' => true]);
|
||||
|
||||
$this->actingAs($user)
|
||||
->get(route('dashboard'))
|
||||
->assertOk()
|
||||
->assertInertia(fn (Assert $page) => $page
|
||||
->component('dashboard')
|
||||
->where('canCreateChannel', true),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_home_page_exposes_channel_display_media_props(): void
|
||||
{
|
||||
$channel = Channel::factory()->create([
|
||||
|
||||
Reference in New Issue
Block a user