2024-01-12 14:41:02 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\KoelPlus;
|
|
|
|
|
2024-01-25 16:21:26 +00:00
|
|
|
use App\Http\Resources\PlaylistResource;
|
2024-01-12 14:41:02 +00:00
|
|
|
use App\Models\Playlist;
|
|
|
|
use App\Values\SmartPlaylistRule;
|
2024-01-18 11:13:05 +00:00
|
|
|
use Tests\PlusTestCase;
|
2024-01-12 14:41:02 +00:00
|
|
|
|
|
|
|
use function Tests\create_user;
|
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
class PlaylistTest extends PlusTestCase
|
2024-01-12 14:41:02 +00:00
|
|
|
{
|
|
|
|
public function testCreatingPlaylistWithOwnSongsOnlyOption(): void
|
|
|
|
{
|
|
|
|
$user = create_user();
|
|
|
|
|
|
|
|
$rule = SmartPlaylistRule::make([
|
|
|
|
'model' => 'artist.name',
|
|
|
|
'operator' => SmartPlaylistRule::OPERATOR_IS,
|
|
|
|
'value' => ['Bob Dylan'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->postAs('api/playlists', [
|
|
|
|
'name' => 'Smart Foo Bar',
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'id' => '2a4548cd-c67f-44d4-8fec-34ff75c8a026',
|
|
|
|
'rules' => [$rule->toArray()],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'own_songs_only' => true,
|
2024-01-25 16:21:26 +00:00
|
|
|
], $user)->assertJsonStructure(PlaylistResource::JSON_STRUCTURE);
|
2024-01-12 14:41:02 +00:00
|
|
|
|
|
|
|
/** @var Playlist $playlist */
|
2024-01-18 11:13:05 +00:00
|
|
|
$playlist = Playlist::query()->latest()->first();
|
2024-01-12 14:41:02 +00:00
|
|
|
|
|
|
|
self::assertSame('Smart Foo Bar', $playlist->name);
|
2024-01-18 11:13:05 +00:00
|
|
|
self::assertTrue($playlist->ownedBy($user));
|
2024-01-12 14:41:02 +00:00
|
|
|
self::assertTrue($playlist->is_smart);
|
|
|
|
self::assertCount(1, $playlist->rule_groups);
|
|
|
|
self::assertNull($playlist->folder_id);
|
|
|
|
self::assertTrue($rule->equals($playlist->rule_groups[0]->rules[0]));
|
|
|
|
self::assertTrue($playlist->own_songs_only);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdatePlaylistWithOwnSongsOnlyOption(): void
|
|
|
|
{
|
|
|
|
/** @var Playlist $playlist */
|
|
|
|
$playlist = Playlist::factory()->smart()->create();
|
|
|
|
|
2024-01-18 11:13:05 +00:00
|
|
|
$this->putAs("api/playlists/$playlist->id", [
|
2024-01-12 14:41:02 +00:00
|
|
|
'name' => 'Foo',
|
|
|
|
'own_songs_only' => true,
|
|
|
|
'rules' => $playlist->rules->toArray(),
|
|
|
|
], $playlist->user)
|
2024-01-25 16:21:26 +00:00
|
|
|
->assertJsonStructure(PlaylistResource::JSON_STRUCTURE);
|
2024-01-12 14:41:02 +00:00
|
|
|
|
|
|
|
$playlist->refresh();
|
|
|
|
|
|
|
|
self::assertTrue($playlist->own_songs_only);
|
|
|
|
}
|
|
|
|
}
|