mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
feat(test): add missing tests for Playlist services
This commit is contained in:
parent
35df3a6826
commit
259e96bdd3
4 changed files with 56 additions and 4 deletions
|
@ -24,7 +24,7 @@ context('Song Editing', { scrollBehavior: false }, () => {
|
|||
cy.get('[name=title]').clear().type('New Title')
|
||||
cy.findByTestId('edit-song-lyrics-tab').click()
|
||||
cy.get('textarea[name=lyrics]').should('be.visible').and('contain.value', 'Sample song lyrics')
|
||||
.clear().type('New lyrics{enter}Supports multiline.')
|
||||
.clear().type('New lyrics{enter}Fake multiline.')
|
||||
|
||||
cy.get('button[type=submit]').click()
|
||||
})
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\License;
|
||||
namespace Tests\Fakes;
|
||||
|
||||
use App\Exceptions\MethodNotImplementedException;
|
||||
use App\Models\License;
|
||||
use App\Services\License\LicenseServiceInterface;
|
||||
use App\Values\LicenseStatus;
|
||||
|
||||
class FakePlusLicenseService implements LicenseServiceInterface
|
|
@ -9,6 +9,7 @@ use App\Services\PlaylistService;
|
|||
use App\Values\SmartPlaylistRuleGroupCollection;
|
||||
use Illuminate\Support\Collection;
|
||||
use InvalidArgumentException as BaseInvalidArgumentException;
|
||||
use Tests\PlusTestCase;
|
||||
use Tests\TestCase;
|
||||
use Webmozart\Assert\InvalidArgumentException;
|
||||
|
||||
|
@ -187,4 +188,49 @@ class PlaylistServiceTest extends TestCase
|
|||
ownSongsOnly: true
|
||||
);
|
||||
}
|
||||
|
||||
public function testAddSongsToPlaylist(): void
|
||||
{
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = Playlist::factory()->create();
|
||||
$playlist->addSongs(Song::factory(3)->create());
|
||||
$songs = Song::factory(2)->create();
|
||||
|
||||
$addedSongs = $this->service->addSongsToPlaylist($playlist, $songs, $playlist->user);
|
||||
$playlist->refresh();
|
||||
|
||||
self::assertCount(2, $addedSongs);
|
||||
self::assertCount(5, $playlist->songs);
|
||||
self::assertEqualsCanonicalizing($addedSongs->pluck('id')->all(), $songs->pluck('id')->all());
|
||||
$songs->each(static fn (Song $song) => self::assertTrue($playlist->songs->contains($song)));
|
||||
}
|
||||
|
||||
public function testPrivateSongsAreMadePublicWhenAddedToCollaborativePlaylist(): void
|
||||
{
|
||||
PlusTestCase::enablePlusLicense();
|
||||
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = Playlist::factory()->create();
|
||||
$user = create_user();
|
||||
$playlist->collaborators()->attach($user);
|
||||
$playlist->refresh();
|
||||
self::assertTrue($playlist->is_collaborative);
|
||||
|
||||
$songs = Song::factory(2)->create(['is_public' => false]);
|
||||
|
||||
$this->service->addSongsToPlaylist($playlist, $songs, $user);
|
||||
|
||||
$songs->each(static fn (Song $song) => self::assertTrue($song->refresh()->is_public));
|
||||
}
|
||||
|
||||
public function testMakePlaylistSongsPublic(): void
|
||||
{
|
||||
/** @var Playlist $playlist */
|
||||
$playlist = Playlist::factory()->create();
|
||||
$playlist->addSongs(Song::factory(2)->create(['is_public' => false]));
|
||||
|
||||
$this->service->makePlaylistSongsPublic($playlist);
|
||||
|
||||
$playlist->songs->each(static fn (Song $song) => self::assertTrue($song->is_public));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,20 @@
|
|||
namespace Tests;
|
||||
|
||||
use App\Facades\License;
|
||||
use App\Services\License\FakePlusLicenseService;
|
||||
use Tests\Fakes\FakePlusLicenseService;
|
||||
use Tests\TestCase as BaseTestCase;
|
||||
|
||||
class PlusTestCase extends BaseTestCase
|
||||
{
|
||||
public static function enablePlusLicense(): void
|
||||
{
|
||||
License::swap(app(FakePlusLicenseService::class));
|
||||
}
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
License::swap(app()->make(FakePlusLicenseService::class));
|
||||
self::enablePlusLicense();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue