koel/tests/Feature/KoelPlus/SongVisibilityTest.php

55 lines
1.8 KiB
PHP
Raw Normal View History

2024-01-09 18:34:40 +00:00
<?php
namespace Tests\Feature\KoelPlus;
use App\Models\Song;
use Illuminate\Support\Collection;
2024-01-18 11:13:05 +00:00
use Tests\PlusTestCase;
2024-01-09 18:34:40 +00:00
2024-01-11 12:41:33 +00:00
use function Tests\create_user;
2024-01-18 11:13:05 +00:00
class SongVisibilityTest extends PlusTestCase
2024-01-09 18:34:40 +00:00
{
public function testMakingSongPublic(): void
{
2024-01-11 12:41:33 +00:00
$currentUser = create_user();
$anotherUser = create_user();
2024-01-09 18:34:40 +00:00
/** @var Collection<Song> $externalSongs */
$externalSongs = Song::factory(3)->for($anotherUser, 'owner')->private()->create();
// We can't make public songs that are not ours.
2024-01-16 21:14:14 +00:00
$this->putAs('api/songs/publicize', ['songs' => $externalSongs->pluck('id')->toArray()], $currentUser)
2024-01-09 18:34:40 +00:00
->assertForbidden();
// But we can our own songs.
$ownSongs = Song::factory(3)->for($currentUser, 'owner')->create();
2024-01-16 21:14:14 +00:00
$this->putAs('api/songs/publicize', ['songs' => $ownSongs->pluck('id')->toArray()], $currentUser)
2024-01-09 18:34:40 +00:00
->assertSuccessful();
$ownSongs->each(static fn (Song $song) => self::assertTrue($song->refresh()->is_public));
}
public function testMakingSongPrivate(): void
{
2024-01-11 12:41:33 +00:00
$currentUser = create_user();
$anotherUser = create_user();
2024-01-09 18:34:40 +00:00
/** @var Collection<Song> $externalSongs */
$externalSongs = Song::factory(3)->for($anotherUser, 'owner')->public()->create();
// We can't Mark as Private songs that are not ours.
2024-01-16 21:14:14 +00:00
$this->putAs('api/songs/privatize', ['songs' => $externalSongs->pluck('id')->toArray()], $currentUser)
2024-01-09 18:34:40 +00:00
->assertForbidden();
// But we can our own songs.
$ownSongs = Song::factory(3)->for($currentUser, 'owner')->create();
2024-01-16 21:14:14 +00:00
$this->putAs('api/songs/privatize', ['songs' => $ownSongs->pluck('id')->toArray()], $currentUser)
2024-01-09 18:34:40 +00:00
->assertSuccessful();
$ownSongs->each(static fn (Song $song) => self::assertFalse($song->refresh()->is_public));
}
}