mirror of
https://github.com/koel/koel
synced 2024-12-22 10:33:16 +00:00
55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Playlist;
|
|
use App\Models\Song;
|
|
use App\Models\User;
|
|
|
|
class PlaylistSongTest extends TestCase
|
|
{
|
|
public function testUpdatePlaylistSongs(): void
|
|
{
|
|
$this->doTestUpdatePlaylistSongs();
|
|
}
|
|
|
|
/** @deprecated */
|
|
public function testSyncPlaylist(): void
|
|
{
|
|
$this->doTestUpdatePlaylistSongs(true);
|
|
}
|
|
|
|
private function doTestUpdatePlaylistSongs(bool $useDeprecatedRoute = false): void
|
|
{
|
|
/** @var User $user */
|
|
$user = User::factory()->create();
|
|
|
|
/** @var Playlist $playlist */
|
|
$playlist = Playlist::factory()->for($user)->create();
|
|
|
|
$toRemainSongs = Song::factory(3)->create();
|
|
$toBeRemovedSongs = Song::factory(2)->create();
|
|
$playlist->songs()->attach($toRemainSongs->merge($toBeRemovedSongs));
|
|
|
|
$path = $useDeprecatedRoute ? "api/playlist/$playlist->id/sync" : "api/playlist/$playlist->id/songs";
|
|
|
|
$this->putAs($path, ['songs' => $toRemainSongs->pluck('id')->all()], $user)->assertNoContent();
|
|
|
|
self::assertEqualsCanonicalizing(
|
|
$toRemainSongs->pluck('id')->all(),
|
|
$playlist->refresh()->songs->pluck('id')->all()
|
|
);
|
|
}
|
|
|
|
public function testGetPlaylistSongs(): void
|
|
{
|
|
/** @var Playlist $playlist */
|
|
$playlist = Playlist::factory()->create();
|
|
|
|
$songs = Song::factory(2)->create();
|
|
$playlist->songs()->saveMany($songs);
|
|
|
|
$this->getAs("api/playlist/$playlist->id/songs", $playlist->user)
|
|
->assertJson($songs->pluck('id')->all());
|
|
}
|
|
}
|