mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
fix(test): broken tests
This commit is contained in:
parent
6e2f3764cc
commit
e4ca67bc69
4 changed files with 18 additions and 39 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace App\Values;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
final class AlbumInformation implements Arrayable
|
||||
{
|
||||
|
@ -25,7 +26,7 @@ final class AlbumInformation implements Arrayable
|
|||
{
|
||||
return self::make(
|
||||
url: $data->url,
|
||||
cover: $data->cover,
|
||||
cover: Arr::get($data->image, '0.#text'),
|
||||
wiki: [
|
||||
'summary' => isset($data->wiki) ? self::formatLastFmText($data->wiki->summary) : '',
|
||||
'full' => isset($data->wiki) ? self::formatLastFmText($data->wiki->content) : '',
|
||||
|
|
|
@ -5,7 +5,6 @@ namespace Tests\Feature;
|
|||
use App\Models\Playlist;
|
||||
use App\Models\Song;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PlaylistSongTest extends TestCase
|
||||
{
|
||||
|
@ -33,49 +32,31 @@ class PlaylistSongTest extends TestCase
|
|||
$user = User::factory()->create();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = Playlist::factory()->create([], $user);
|
||||
$playlist = Playlist::factory()->for($user)->create();
|
||||
|
||||
/** @var array<Song>|Collection $songs */
|
||||
$songs = Song::orderBy('id')->take(4)->get();
|
||||
$playlist->songs()->attach($songs->pluck('id')->all());
|
||||
|
||||
/** @var Song $removedSong */
|
||||
$removedSong = $songs->pop();
|
||||
$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' => $songs->pluck('id')->all(),
|
||||
], $user)->assertOk();
|
||||
$this->putAs($path, ['songs' => $toRemainSongs->pluck('id')->all()], $user)->assertOk();
|
||||
|
||||
// We should still see the first 3 songs, but not the removed one
|
||||
foreach ($songs as $song) {
|
||||
self::assertDatabaseHas('playlist_song', [
|
||||
'playlist_id' => $playlist->id,
|
||||
'song_id' => $song->id,
|
||||
]);
|
||||
}
|
||||
|
||||
self::assertDatabaseMissing('playlist_song', [
|
||||
'playlist_id' => $playlist->id,
|
||||
'song_id' => $removedSong->id,
|
||||
]);
|
||||
self::assertEqualsCanonicalizing(
|
||||
$toRemainSongs->pluck('id')->all(),
|
||||
$playlist->refresh()->songs->pluck('id')->all()
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetPlaylistSongs(): void
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = User::factory()->create();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = Playlist::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
$playlist = Playlist::factory()->create();
|
||||
|
||||
$songs = Song::factory(2)->create();
|
||||
$playlist->songs()->saveMany($songs);
|
||||
|
||||
$this->getAs("api/playlist/$playlist->id/songs", $user)
|
||||
$this->getAs("api/playlist/$playlist->id/songs", $playlist->user)
|
||||
->assertJson($songs->pluck('id')->all());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,10 +60,7 @@ class LastfmServiceTest extends TestCase
|
|||
$artist = Artist::factory()->create(['name' => 'bar']);
|
||||
|
||||
/** @var Album $album */
|
||||
$album = Album::factory()->create([
|
||||
'artist_id' => $artist->id,
|
||||
'name' => 'foo',
|
||||
]);
|
||||
$album = Album::factory()->for($artist)->create(['name' => 'foo']);
|
||||
|
||||
/** @var Client $client */
|
||||
$client = Mockery::mock(Client::class, [
|
||||
|
@ -79,12 +76,12 @@ class LastfmServiceTest extends TestCase
|
|||
'tracks' => [
|
||||
[
|
||||
'title' => 'Track 1',
|
||||
'url' => 'http://foo/track1',
|
||||
'url' => 'https://foo/track1',
|
||||
'length' => 100,
|
||||
],
|
||||
[
|
||||
'title' => 'Track 2',
|
||||
'url' => 'http://foo/track2',
|
||||
'url' => 'https://foo/track2',
|
||||
'length' => 150,
|
||||
],
|
||||
],
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
"track": [
|
||||
{
|
||||
"name": "Track 1",
|
||||
"url": "http://foo/track1",
|
||||
"url": "https://foo/track1",
|
||||
"duration": "100",
|
||||
"@attr": {
|
||||
"rank": "1"
|
||||
|
@ -53,7 +53,7 @@
|
|||
},
|
||||
{
|
||||
"name": "Track 2",
|
||||
"url": "http://foo/track2",
|
||||
"url": "https://foo/track2",
|
||||
"duration": "150",
|
||||
"@attr": {
|
||||
"rank": "2"
|
||||
|
|
Loading…
Reference in a new issue