2024-01-09 23:26:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\KoelPlus;
|
|
|
|
|
|
|
|
use App\Models\Song;
|
2024-02-24 07:28:49 +00:00
|
|
|
use App\Services\Streamer\Adapters\LocalStreamerAdapter;
|
2024-01-09 23:26:16 +00:00
|
|
|
use App\Services\TokenManager;
|
|
|
|
use App\Values\CompositeToken;
|
2024-01-18 11:13:05 +00:00
|
|
|
use Tests\PlusTestCase;
|
2024-01-09 23:26:16 +00:00
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\create_user;
|
|
|
|
use function Tests\test_path;
|
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
class SongPlayTest extends PlusTestCase
|
2024-01-09 23:26:16 +00:00
|
|
|
{
|
|
|
|
public function testPlayPublicUnownedSong(): void
|
|
|
|
{
|
|
|
|
/** @var CompositeToken $token */
|
2024-01-11 12:41:33 +00:00
|
|
|
$token = app(TokenManager::class)->createCompositeToken(create_user());
|
2024-01-09 23:26:16 +00:00
|
|
|
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->public()->create([
|
|
|
|
'path' => test_path('songs/blank.mp3'),
|
|
|
|
]);
|
|
|
|
|
2024-02-24 07:28:49 +00:00
|
|
|
$this->mock(LocalStreamerAdapter::class)
|
|
|
|
->shouldReceive('stream')
|
|
|
|
->once();
|
2024-01-09 23:26:16 +00:00
|
|
|
|
|
|
|
$this->get("play/$song->id?t=$token->audioToken")
|
|
|
|
->assertOk();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPlayPrivateOwnedSong(): void
|
|
|
|
{
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->private()->create([
|
|
|
|
'path' => test_path('songs/blank.mp3'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
/** @var CompositeToken $token */
|
|
|
|
$token = app(TokenManager::class)->createCompositeToken($song->owner);
|
|
|
|
|
2024-02-24 07:28:49 +00:00
|
|
|
$this->mock(LocalStreamerAdapter::class)
|
|
|
|
->shouldReceive('stream')
|
|
|
|
->once();
|
2024-01-09 23:26:16 +00:00
|
|
|
|
|
|
|
$this->get("play/$song->id?t=$token->audioToken")
|
|
|
|
->assertOk();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCannotPlayPrivateUnownedSong(): void
|
|
|
|
{
|
|
|
|
/** @var Song $song */
|
|
|
|
$song = Song::factory()->private()->create([
|
|
|
|
'path' => test_path('songs/blank.mp3'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
/** @var CompositeToken $token */
|
2024-01-11 12:41:33 +00:00
|
|
|
$token = app(TokenManager::class)->createCompositeToken(create_user());
|
2024-01-09 23:26:16 +00:00
|
|
|
|
|
|
|
$this->get("play/$song->id?t=$token->audioToken")
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
}
|