koel/tests/Feature/KoelPlus/PlaylistTest.php

64 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\KoelPlus;
use App\Http\Resources\PlaylistResource;
use App\Models\Playlist;
use App\Values\SmartPlaylistRule;
2024-01-18 11:13:05 +00:00
use Tests\PlusTestCase;
use function Tests\create_user;
2024-01-18 11:13:05 +00:00
class PlaylistTest extends PlusTestCase
{
public function testCreatingPlaylistWithOwnSongsOnlyOption(): void
{
$user = create_user();
$rule = SmartPlaylistRule::make([
'model' => 'artist.name',
'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,
], $user)->assertJsonStructure(PlaylistResource::JSON_STRUCTURE);
/** @var Playlist $playlist */
2024-01-18 11:13:05 +00:00
$playlist = Playlist::query()->latest()->first();
self::assertSame('Smart Foo Bar', $playlist->name);
2024-01-18 11:13:05 +00:00
self::assertTrue($playlist->ownedBy($user));
self::assertTrue($playlist->is_smart);
self::assertCount(1, $playlist->rule_groups);
self::assertNull($playlist->getFolderId());
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", [
'name' => 'Foo',
'own_songs_only' => true,
'rules' => $playlist->rules->toArray(),
], $playlist->user)
->assertJsonStructure(PlaylistResource::JSON_STRUCTURE);
$playlist->refresh();
self::assertTrue($playlist->own_songs_only);
}
}