2024-01-12 14:41:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\KoelPlus\Services;
|
|
|
|
|
2024-01-25 16:21:26 +00:00
|
|
|
use App\Models\Playlist;
|
2024-01-12 14:41:02 +00:00
|
|
|
use App\Models\Song;
|
2024-01-25 16:21:26 +00:00
|
|
|
use App\Services\SmartPlaylistService;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Tests\PlusTestCase;
|
2024-01-12 14:41:02 +00:00
|
|
|
|
|
|
|
use function Tests\create_user;
|
|
|
|
|
2024-01-25 16:21:26 +00:00
|
|
|
class SmartPlaylistServiceTest extends PlusTestCase
|
2024-01-12 14:41:02 +00:00
|
|
|
{
|
2024-01-25 16:21:26 +00:00
|
|
|
private SmartPlaylistService $service;
|
|
|
|
|
2024-01-12 14:41:02 +00:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2024-01-25 16:21:26 +00:00
|
|
|
$this->service = app(SmartPlaylistService::class);
|
2024-01-12 14:41:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnSongsOnlyOption(): void
|
|
|
|
{
|
|
|
|
$owner = create_user();
|
|
|
|
$matches = Song::factory()->count(3)->for($owner, 'owner')->create(['title' => 'Foo Something']);
|
2024-01-25 16:21:26 +00:00
|
|
|
|
2024-01-12 14:41:02 +00:00
|
|
|
Song::factory()->count(2)->create(['title' => 'Foo Something']);
|
|
|
|
Song::factory()->count(3)->create(['title' => 'Bar Something']);
|
|
|
|
|
2024-01-25 16:21:26 +00:00
|
|
|
/** @var Playlist $playlist */
|
|
|
|
$playlist = Playlist::factory()
|
|
|
|
->for($owner)
|
|
|
|
->create([
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'id' => Str::uuid()->toString(),
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'id' => Str::uuid()->toString(),
|
|
|
|
'model' => 'title',
|
|
|
|
'operator' => 'is',
|
|
|
|
'value' => ['Foo Something'],
|
|
|
|
],
|
2024-01-12 14:41:02 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2024-01-25 16:21:26 +00:00
|
|
|
'own_songs_only' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
self::assertEqualsCanonicalizing(
|
|
|
|
$matches->pluck('id')->all(),
|
|
|
|
$this->service->getSongs($playlist, $owner)->pluck('id')->all()
|
2024-01-12 14:41:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|