diff --git a/cypress/integration/song-editing.spec.ts b/cypress/integration/song-editing.spec.ts index 68f0b481..e68fb282 100644 --- a/cypress/integration/song-editing.spec.ts +++ b/cypress/integration/song-editing.spec.ts @@ -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() }) diff --git a/app/Services/License/FakePlusLicenseService.php b/tests/Fakes/FakePlusLicenseService.php similarity index 90% rename from app/Services/License/FakePlusLicenseService.php rename to tests/Fakes/FakePlusLicenseService.php index fd8ad8b0..6f2fcb59 100644 --- a/app/Services/License/FakePlusLicenseService.php +++ b/tests/Fakes/FakePlusLicenseService.php @@ -1,9 +1,10 @@ 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)); + } } diff --git a/tests/PlusTestCase.php b/tests/PlusTestCase.php index a2d2e668..ac7f1a35 100644 --- a/tests/PlusTestCase.php +++ b/tests/PlusTestCase.php @@ -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(); } }