mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
feat(api): adding feature flag for playlist management (#544)
This commit is contained in:
@@ -164,6 +164,7 @@ ALLOW_DISCORD_NOTIFICATIONS=false
|
||||
ALLOW_VIEW_RECORDING=false
|
||||
ALLOW_DUMP_DOWNLOADING=false
|
||||
ALLOW_SCRIPT_DOWNLOADING=false
|
||||
ALLOW_PLAYLIST_MANAGEMENT=false
|
||||
|
||||
# fortify
|
||||
FORTIFY_HOME=http://localhost
|
||||
|
||||
@@ -32,4 +32,8 @@ class FlagConstants
|
||||
final public const ALLOW_SCRIPT_DOWNLOADING_FLAG = 'allow_script_downloading';
|
||||
|
||||
final public const ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED = 'flags.allow_script_downloading';
|
||||
|
||||
final public const ALLOW_PLAYLIST_MANAGEMENT = 'allow_playlist_management';
|
||||
|
||||
final public const ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED = 'flags.allow_playlist_management';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Api\Field\Config\Flags;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Http\Api\Field\Field;
|
||||
use App\Http\Api\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Class FlagsAllowPlaylistManagementField.
|
||||
*/
|
||||
class FlagsAllowPlaylistManagementField extends Field
|
||||
{
|
||||
/**
|
||||
* Create a new field instance.
|
||||
*
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function __construct(Schema $schema)
|
||||
{
|
||||
parent::__construct($schema, FlagConstants::ALLOW_PLAYLIST_MANAGEMENT);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace App\Http\Api\Schema\Config;
|
||||
use App\Http\Api\Field\Config\Flags\FlagsAllowAudioStreamsField;
|
||||
use App\Http\Api\Field\Config\Flags\FlagsAllowDiscordNotificationsField;
|
||||
use App\Http\Api\Field\Config\Flags\FlagsAllowDumpDownloadingField;
|
||||
use App\Http\Api\Field\Config\Flags\FlagsAllowPlaylistManagementField;
|
||||
use App\Http\Api\Field\Config\Flags\FlagsAllowScriptDownloadingField;
|
||||
use App\Http\Api\Field\Config\Flags\FlagsAllowVideoStreamsField;
|
||||
use App\Http\Api\Field\Config\Flags\FlagsAllowViewRecordingField;
|
||||
@@ -56,6 +57,7 @@ class FlagsSchema extends Schema
|
||||
new FlagsAllowViewRecordingField($this),
|
||||
new FlagsAllowDumpDownloadingField($this),
|
||||
new FlagsAllowScriptDownloadingField($this),
|
||||
new FlagsAllowPlaylistManagementField($this),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Actions\Http\Api\List\Playlist\Track\RestoreTrackAction;
|
||||
use App\Actions\Http\Api\List\Playlist\Track\StoreTrackAction;
|
||||
use App\Actions\Http\Api\List\Playlist\Track\UpdateTrackAction;
|
||||
use App\Actions\Http\Api\ShowAction;
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Http\Api\Query\Query;
|
||||
use App\Http\Controllers\Api\BaseController;
|
||||
use App\Http\Requests\Api\IndexRequest;
|
||||
@@ -23,6 +24,7 @@ use App\Models\List\Playlist;
|
||||
use App\Models\List\Playlist\PlaylistTrack;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class TrackController.
|
||||
@@ -35,6 +37,13 @@ class TrackController extends BaseController
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(PlaylistTrack::class, 'track,playlist');
|
||||
|
||||
$isPlaylistManagementAllowed = Str::of('is_feature_enabled:')
|
||||
->append(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED)
|
||||
->append(',Playlist Management Disabled')
|
||||
->__toString();
|
||||
|
||||
$this->middleware($isPlaylistManagementAllowed)->except(['index', 'show']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Actions\Http\Api\RestoreAction;
|
||||
use App\Actions\Http\Api\ShowAction;
|
||||
use App\Actions\Http\Api\StoreAction;
|
||||
use App\Actions\Http\Api\UpdateAction;
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Http\Api\Query\Query;
|
||||
use App\Http\Controllers\Api\BaseController;
|
||||
@@ -24,6 +25,7 @@ use App\Models\List\Playlist;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class PlaylistController.
|
||||
@@ -36,6 +38,13 @@ class PlaylistController extends BaseController
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Playlist::class, 'playlist');
|
||||
|
||||
$isPlaylistManagementAllowed = Str::of('is_feature_enabled:')
|
||||
->append(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED)
|
||||
->append(',Playlist Management Disabled')
|
||||
->__toString();
|
||||
|
||||
$this->middleware($isPlaylistManagementAllowed)->except(['index', 'show']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Actions\Http\Api\DestroyAction;
|
||||
use App\Actions\Http\Api\IndexAction;
|
||||
use App\Actions\Http\Api\ShowAction;
|
||||
use App\Actions\Http\Api\StoreAction;
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Http\Api\Query\Query;
|
||||
use App\Http\Controllers\Api\Pivot\PivotController;
|
||||
@@ -21,6 +22,7 @@ use App\Models\Wiki\Image;
|
||||
use App\Pivots\List\PlaylistImage;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class PlaylistImageController.
|
||||
@@ -33,6 +35,13 @@ class PlaylistImageController extends PivotController
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Playlist::class, 'playlist', Image::class, 'image');
|
||||
|
||||
$isPlaylistManagementAllowed = Str::of('is_feature_enabled:')
|
||||
->append(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED)
|
||||
->append(',Playlist Management Disabled')
|
||||
->__toString();
|
||||
|
||||
$this->middleware($isPlaylistManagementAllowed)->except(['index', 'show']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,6 +72,10 @@ class FlagsResource extends JsonResource
|
||||
$result[FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG] = Config::bool(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED);
|
||||
}
|
||||
|
||||
if ($criteria === null || $criteria->isAllowedField(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT)) {
|
||||
$result[FlagConstants::ALLOW_PLAYLIST_MANAGEMENT] = Config::bool(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,10 +64,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
AboutCommand::add('Flags', [
|
||||
'Allow Audio Streams' => fn () => Config::bool(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow Discord Notifications' => fn () => Config::bool(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow Dump Downloading' => fn () => Config::bool(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow Playlist Management' => fn () => Config::bool(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow Script Downloading' => fn () => Config::bool(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow Video Streams' => fn () => Config::bool(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow View Recording' => fn () => Config::bool(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow Dump Downloading' => fn () => Config::bool(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
'Allow Script Downloading' => fn () => Config::bool(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED) ? 'true' : 'false',
|
||||
]);
|
||||
|
||||
AboutCommand::add('Images', [
|
||||
|
||||
@@ -82,4 +82,17 @@ return [
|
||||
*/
|
||||
|
||||
'allow_script_downloading' => (bool) env('ALLOW_SCRIPT_DOWNLOADING', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allow Playlist Management
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When playlist management is allowed, requests to write routes for playlist resources
|
||||
| permit authorized users. If disabled, requests to write routes for playlist resources
|
||||
| will raise a 403 Forbidden response.
|
||||
|
|
||||
*/
|
||||
|
||||
'allow_playlist_management' => (bool) env('ALLOW_PLAYLIST_MANAGEMENT', false),
|
||||
];
|
||||
|
||||
@@ -48,29 +48,10 @@ class UserFactory extends Factory
|
||||
/**
|
||||
* Create and assign permission to user.
|
||||
*
|
||||
* @param string $ability
|
||||
* @param string ...$abilities
|
||||
* @return static
|
||||
*/
|
||||
public function withPermission(string $ability): static
|
||||
{
|
||||
return $this->afterCreating(
|
||||
function (User $user) use ($ability) {
|
||||
$permission = Permission::findOrCreate($ability);
|
||||
|
||||
App::make(PermissionRegistrar::class)->forgetCachedPermissions();
|
||||
|
||||
$user->givePermissionTo($permission);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and assign permission to user.
|
||||
*
|
||||
* @param string[] $abilities
|
||||
* @return static
|
||||
*/
|
||||
public function withPermissions(array $abilities): static
|
||||
public function withPermissions(string ...$abilities): static
|
||||
{
|
||||
return $this->afterCreating(
|
||||
function (User $user) use ($abilities) {
|
||||
|
||||
@@ -79,17 +79,17 @@ class AnimeFactory extends Factory
|
||||
->create();
|
||||
|
||||
Series::factory()
|
||||
->hasAttached($anime, [], 'anime')
|
||||
->hasAttached($anime, [], Series::RELATION_ANIME)
|
||||
->count(fake()->numberBetween(1, 3))
|
||||
->create();
|
||||
|
||||
ExternalResource::factory()
|
||||
->hasAttached($anime, [], 'anime')
|
||||
->hasAttached($anime, [], ExternalResource::RELATION_ANIME)
|
||||
->count(fake()->numberBetween(1, 3))
|
||||
->create();
|
||||
|
||||
Image::factory()
|
||||
->hasAttached($anime, [], 'anime')
|
||||
->hasAttached($anime, [], Image::RELATION_ANIME)
|
||||
->count(fake()->numberBetween(1, 3))
|
||||
->create();
|
||||
}
|
||||
|
||||
@@ -59,12 +59,12 @@ class ArtistFactory extends Factory
|
||||
->create();
|
||||
|
||||
Artist::factory()
|
||||
->hasAttached($artist, [], 'members')
|
||||
->hasAttached($artist, [], Artist::RELATION_MEMBERS)
|
||||
->count(fake()->randomDigitNotNull())
|
||||
->create();
|
||||
|
||||
Artist::factory()
|
||||
->hasAttached($artist, [], 'groups')
|
||||
->hasAttached($artist, [], Artist::RELATION_GROUPS)
|
||||
->count(fake()->randomDigitNotNull())
|
||||
->create();
|
||||
|
||||
|
||||
@@ -112,5 +112,15 @@ class SettingSeeder extends Seeder
|
||||
Setting::ATTRIBUTE_VALUE => Config::get(WikiConstants::FEATURED_VIDEO_SETTING_QUALIFIED, ''),
|
||||
]
|
||||
);
|
||||
|
||||
Setting::query()->firstOrCreate(
|
||||
[
|
||||
Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_PLAYLIST_MANAGEMENT,
|
||||
],
|
||||
[
|
||||
Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_PLAYLIST_MANAGEMENT,
|
||||
Setting::ATTRIBUTE_VALUE => 'false',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class DumpTest extends TestCase
|
||||
Dump::ATTRIBUTE_PATH => $fsFile,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withPermission(SpecialPermission::BYPASS_FEATURE_FLAGS)->createOne();
|
||||
$user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS)->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class LatestDocumentDumpTest extends TestCase
|
||||
Dump::ATTRIBUTE_PATH => $fsFile,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withPermission(SpecialPermission::BYPASS_FEATURE_FLAGS)->createOne();
|
||||
$user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS)->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class LatestWikiDumpTest extends TestCase
|
||||
Dump::ATTRIBUTE_PATH => $fsFile,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withPermission(SpecialPermission::BYPASS_FEATURE_FLAGS)->createOne();
|
||||
$user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS)->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class AnnouncementDestroyTest extends TestCase
|
||||
|
||||
$announcement->delete();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -79,7 +79,7 @@ class AnnouncementDestroyTest extends TestCase
|
||||
{
|
||||
$announcement = Announcement::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class AnnouncementForceDeleteTest extends TestCase
|
||||
{
|
||||
$announcement = Announcement::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class AnnouncementRestoreTest extends TestCase
|
||||
{
|
||||
$announcement = Announcement::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -83,7 +83,7 @@ class AnnouncementRestoreTest extends TestCase
|
||||
|
||||
$announcement->delete();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class AnnouncementStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -77,7 +77,7 @@ class AnnouncementStoreTest extends TestCase
|
||||
{
|
||||
$parameters = Announcement::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class AnnouncementUpdateTest extends TestCase
|
||||
|
||||
$parameters = Announcement::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -87,7 +87,7 @@ class AnnouncementUpdateTest extends TestCase
|
||||
|
||||
$parameters = Announcement::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Announcement::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Announcement::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class DumpDestroyTest extends TestCase
|
||||
|
||||
$dump->delete();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -79,7 +79,7 @@ class DumpDestroyTest extends TestCase
|
||||
{
|
||||
$dump = Dump::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class DumpForceDeleteTest extends TestCase
|
||||
{
|
||||
$dump = Dump::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class DumpRestoreTest extends TestCase
|
||||
{
|
||||
$dump = Dump::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -83,7 +83,7 @@ class DumpRestoreTest extends TestCase
|
||||
|
||||
$dump->delete();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class DumpStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -77,7 +77,7 @@ class DumpStoreTest extends TestCase
|
||||
{
|
||||
$parameters = Dump::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class DumpUpdateTest extends TestCase
|
||||
|
||||
$parameters = Dump::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -87,7 +87,7 @@ class DumpUpdateTest extends TestCase
|
||||
|
||||
$parameters = Dump::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Dump::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Dump::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class MyPlaylistIndexTest extends TestCase
|
||||
->count($this->faker->randomDigitNotNull())
|
||||
->create();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlistCount = $this->faker->randomDigitNotNull();
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class BalanceDestroyTest extends TestCase
|
||||
|
||||
$balance->delete();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -79,7 +79,7 @@ class BalanceDestroyTest extends TestCase
|
||||
{
|
||||
$balance = Balance::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class BalanceForceDeleteTest extends TestCase
|
||||
{
|
||||
$balance = Balance::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class BalanceRestoreTest extends TestCase
|
||||
{
|
||||
$balance = Balance::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -83,7 +83,7 @@ class BalanceRestoreTest extends TestCase
|
||||
|
||||
$balance->delete();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class BalanceStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +89,7 @@ class BalanceStoreTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class BalanceUpdateTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -113,7 +113,7 @@ class BalanceUpdateTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Balance::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Balance::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class TransactionDestroyTest extends TestCase
|
||||
|
||||
$transaction->delete();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -79,7 +79,7 @@ class TransactionDestroyTest extends TestCase
|
||||
{
|
||||
$transaction = Transaction::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class TransactionForceDeleteTest extends TestCase
|
||||
{
|
||||
$transaction = Transaction::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class TransactionRestoreTest extends TestCase
|
||||
{
|
||||
$transaction = Transaction::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -83,7 +83,7 @@ class TransactionRestoreTest extends TestCase
|
||||
|
||||
$transaction->delete();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class TransactionStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -84,7 +84,7 @@ class TransactionStoreTest extends TestCase
|
||||
[Transaction::ATTRIBUTE_SERVICE => Service::getRandomInstance()->description]
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class TransactionUpdateTest extends TestCase
|
||||
[Transaction::ATTRIBUTE_SERVICE => Service::getRandomInstance()->description]
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -100,7 +100,7 @@ class TransactionUpdateTest extends TestCase
|
||||
[Transaction::ATTRIBUTE_SERVICE => Service::getRandomInstance()->description]
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Transaction::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Transaction::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class PageDestroyTest extends TestCase
|
||||
|
||||
$page->delete();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -79,7 +79,7 @@ class PageDestroyTest extends TestCase
|
||||
{
|
||||
$page = Page::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class PageForceDeleteTest extends TestCase
|
||||
{
|
||||
$page = Page::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class PageRestoreTest extends TestCase
|
||||
{
|
||||
$page = Page::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -83,7 +83,7 @@ class PageRestoreTest extends TestCase
|
||||
|
||||
$page->delete();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class PageStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -79,7 +79,7 @@ class PageStoreTest extends TestCase
|
||||
{
|
||||
$parameters = Page::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class PageUpdateTest extends TestCase
|
||||
|
||||
$parameters = Page::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -87,7 +87,7 @@ class PageUpdateTest extends TestCase
|
||||
|
||||
$parameters = Page::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Page::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Page::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class BackwardIndexTest extends TestCase
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::PRIVATE,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -88,7 +88,7 @@ class BackwardIndexTest extends TestCase
|
||||
*/
|
||||
public function testPrivatePlaylistTrackCanBeViewedByOwner(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -72,7 +72,7 @@ class ForwardIndexTest extends TestCase
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::PRIVATE,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -88,7 +88,7 @@ class ForwardIndexTest extends TestCase
|
||||
*/
|
||||
public function testPrivatePlaylistTrackCanBeViewedByOwner(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -4,10 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -16,6 +20,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class PlaylistDestroyTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use WithoutEvents;
|
||||
|
||||
/**
|
||||
@@ -25,6 +30,8 @@ class PlaylistDestroyTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$response = $this->delete(route('api.playlist.destroy', ['playlist' => $playlist]));
|
||||
@@ -39,6 +46,8 @@ class PlaylistDestroyTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$user = User::factory()->createOne();
|
||||
@@ -57,11 +66,36 @@ class PlaylistDestroyTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for(User::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.destroy', ['playlist' => $playlist]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Destroy Endpoint shall forbid users from destroying playlists
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -77,7 +111,9 @@ class PlaylistDestroyTest extends TestCase
|
||||
*/
|
||||
public function testTrashed(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Playlist::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -99,7 +135,9 @@ class PlaylistDestroyTest extends TestCase
|
||||
*/
|
||||
public function testDeleted(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Playlist::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -112,4 +150,32 @@ class PlaylistDestroyTest extends TestCase
|
||||
$response->assertOk();
|
||||
static::assertSoftDeleted($playlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to destroy playlists
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDestroyPermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Playlist::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.destroy', ['playlist' => $playlist]));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\ExtendedCrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -16,6 +20,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class PlaylistForceDeleteTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use WithoutEvents;
|
||||
|
||||
/**
|
||||
@@ -25,6 +30,8 @@ class PlaylistForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testAuthorized(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$response = $this->delete(route('api.playlist.forceDelete', ['playlist' => $playlist]));
|
||||
@@ -37,8 +44,10 @@ class PlaylistForceDeleteTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbidden(): void
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$user = User::factory()->createOne();
|
||||
@@ -50,6 +59,27 @@ class PlaylistForceDeleteTest extends TestCase
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Force Delete Endpoint shall forbid users from force deleting playlists
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.forceDelete', ['playlist' => $playlist]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Force Delete Endpoint shall force delete the playlist.
|
||||
*
|
||||
@@ -57,9 +87,11 @@ class PlaylistForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testDeleted(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -68,4 +100,32 @@ class PlaylistForceDeleteTest extends TestCase
|
||||
$response->assertOk();
|
||||
static::assertModelMissing($playlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to force delete playlists
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeletePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
ExtendedCrudPermission::FORCE_DELETE()->format(Playlist::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.forceDelete', ['playlist' => $playlist]));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\ExtendedCrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -16,6 +20,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class PlaylistRestoreTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use WithoutEvents;
|
||||
|
||||
/**
|
||||
@@ -25,6 +30,8 @@ class PlaylistRestoreTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$response = $this->patch(route('api.playlist.restore', ['playlist' => $playlist]));
|
||||
@@ -39,6 +46,8 @@ class PlaylistRestoreTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$user = User::factory()->createOne();
|
||||
@@ -57,11 +66,38 @@ class PlaylistRestoreTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for(User::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->patch(route('api.playlist.restore', ['playlist' => $playlist]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Restore Endpoint shall forbid users from restoring playlists
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$playlist->delete();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -77,7 +113,9 @@ class PlaylistRestoreTest extends TestCase
|
||||
*/
|
||||
public function testTrashed(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -97,7 +135,40 @@ class PlaylistRestoreTest extends TestCase
|
||||
*/
|
||||
public function testRestored(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$playlist->delete();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->patch(route('api.playlist.restore', ['playlist' => $playlist]));
|
||||
|
||||
$response->assertOk();
|
||||
static::assertNotSoftDeleted($playlist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to restore playlists
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
ExtendedCrudPermission::RESTORE()->format(Playlist::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -64,7 +64,7 @@ class PlaylistShowTest extends TestCase
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::PRIVATE,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -80,7 +80,7 @@ class PlaylistShowTest extends TestCase
|
||||
*/
|
||||
public function testPrivatePlaylistCanBeViewedByOwner(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -4,11 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -17,6 +21,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class PlaylistStoreTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use WithoutEvents;
|
||||
|
||||
/**
|
||||
@@ -26,6 +31,8 @@ class PlaylistStoreTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->makeOne();
|
||||
|
||||
$response = $this->post(route('api.playlist.store', $playlist->toArray()));
|
||||
@@ -38,8 +45,10 @@ class PlaylistStoreTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbidden(): void
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->makeOne();
|
||||
|
||||
$user = User::factory()->createOne();
|
||||
@@ -51,6 +60,30 @@ class PlaylistStoreTest extends TestCase
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Store Endpoint shall forbid users from creating playlists
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$parameters = array_merge(
|
||||
Playlist::factory()->raw(),
|
||||
[Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->post(route('api.playlist.store', $parameters));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Store Endpoint shall require name & visibility fields.
|
||||
*
|
||||
@@ -58,7 +91,9 @@ class PlaylistStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Playlist::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -77,12 +112,14 @@ class PlaylistStoreTest extends TestCase
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$parameters = array_merge(
|
||||
Playlist::factory()->raw(),
|
||||
[Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -92,4 +129,33 @@ class PlaylistStoreTest extends TestCase
|
||||
static::assertDatabaseCount(Playlist::TABLE, 1);
|
||||
static::assertDatabaseHas(Playlist::TABLE, [Playlist::ATTRIBUTE_USER => $user->getKey()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to create playlists
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$parameters = array_merge(
|
||||
Playlist::factory()->raw(),
|
||||
[Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description],
|
||||
);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Playlist::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->post(route('api.playlist.store', $parameters));
|
||||
|
||||
$response->assertCreated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Models\List\Playlist\PlaylistTrack;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -18,6 +21,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class PlaylistUpdateTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use WithoutEvents;
|
||||
|
||||
/**
|
||||
@@ -27,6 +31,8 @@ class PlaylistUpdateTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$parameters = array_merge(
|
||||
@@ -46,6 +52,8 @@ class PlaylistUpdateTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$parameters = array_merge(
|
||||
@@ -69,6 +77,8 @@ class PlaylistUpdateTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for(User::factory())
|
||||
->createOne();
|
||||
@@ -78,7 +88,37 @@ class PlaylistUpdateTest extends TestCase
|
||||
[Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->put(route('api.playlist.update', ['playlist' => $playlist] + $parameters));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Update Endpoint shall forbid users from updating playlists
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$parameters = array_merge(
|
||||
Playlist::factory()->raw(),
|
||||
[
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description,
|
||||
],
|
||||
);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -94,28 +134,20 @@ class PlaylistUpdateTest extends TestCase
|
||||
*/
|
||||
public function testTrashed(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Playlist::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$first = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
$last = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
$playlist->delete();
|
||||
|
||||
$parameters = array_merge(
|
||||
Playlist::factory()->raw(),
|
||||
[
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description,
|
||||
Playlist::ATTRIBUTE_FIRST => $first->getKey(),
|
||||
Playlist::ATTRIBUTE_LAST => $last->getKey(),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -133,26 +165,53 @@ class PlaylistUpdateTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Playlist::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$parameters = array_merge(
|
||||
Playlist::factory()->raw(),
|
||||
[
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description,
|
||||
],
|
||||
);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->put(route('api.playlist.update', ['playlist' => $playlist] + $parameters));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to update playlists
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdatePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::UPDATE()->format(Playlist::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$first = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
$last = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
$parameters = array_merge(
|
||||
Playlist::factory()->raw(),
|
||||
[
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::getRandomInstance()->description,
|
||||
Playlist::ATTRIBUTE_FIRST => $first->getKey(),
|
||||
Playlist::ATTRIBUTE_LAST => $last->getKey(),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -4,13 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist\Track;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Models\List\Playlist\PlaylistTrack;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -29,6 +32,8 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory())
|
||||
->createOne();
|
||||
@@ -45,6 +50,8 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory())
|
||||
->createOne();
|
||||
@@ -65,11 +72,13 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory()->for(User::factory()))
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -78,6 +87,33 @@ class TrackDestroyTest extends TestCase
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Destroy Endpoint shall forbid users from destroying playlists tracks
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.track.destroy', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Destroy Endpoint shall scope bindings.
|
||||
*
|
||||
@@ -85,7 +121,9 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testScoped(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -112,7 +150,9 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testTrashed(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory()->for($user))
|
||||
@@ -134,7 +174,9 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testDeleted(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -162,6 +204,38 @@ class TrackDestroyTest extends TestCase
|
||||
static::assertTrue($track->next()->doesntExist());
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to destroy playlist tracks
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDestroyPermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(PlaylistTrack::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.track.destroy', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Destroy Endpoint shall delete the first track.
|
||||
*
|
||||
@@ -169,7 +243,9 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testDestroyFirst(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -206,7 +282,9 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testDestroyLast(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -243,7 +321,9 @@ class TrackDestroyTest extends TestCase
|
||||
*/
|
||||
public function testDestroySecond(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -4,13 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist\Track;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\ExtendedCrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Models\List\Playlist\PlaylistTrack;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -29,6 +32,8 @@ class TrackForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testAuthorized(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory())
|
||||
->createOne();
|
||||
@@ -43,8 +48,10 @@ class TrackForceDeleteTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbidden(): void
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory())
|
||||
->createOne();
|
||||
@@ -65,7 +72,9 @@ class TrackForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testScoped(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -85,6 +94,33 @@ class TrackForceDeleteTest extends TestCase
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Force Delete Endpoint shall forbid users from force deleting playlist tracks
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.track.forceDelete', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Force Delete Endpoint shall force delete the sole playlist track.
|
||||
*
|
||||
@@ -92,7 +128,9 @@ class TrackForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testDeleted(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -116,6 +154,38 @@ class TrackForceDeleteTest extends TestCase
|
||||
static::assertTrue($playlist->last()->doesntExist());
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to force delete playlist tracks
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeletePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlist.track.forceDelete', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Force Delete Endpoint shall delete the first track.
|
||||
*
|
||||
@@ -123,7 +193,9 @@ class TrackForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testForceDeleteFirst(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -156,7 +228,9 @@ class TrackForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testForceDeleteLast(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -189,7 +263,9 @@ class TrackForceDeleteTest extends TestCase
|
||||
*/
|
||||
public function testForceDeleteSecond(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -78,7 +78,7 @@ class TrackIndexTest extends TestCase
|
||||
Playlist::ATTRIBUTE_VISIBILITY => PlaylistVisibility::PRIVATE,
|
||||
]);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -94,7 +94,7 @@ class TrackIndexTest extends TestCase
|
||||
*/
|
||||
public function testPrivatePlaylistTrackCanBeViewedByOwner(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -4,14 +4,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist\Track;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\ExtendedCrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Models\List\Playlist\PlaylistTrack;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -30,6 +33,8 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory())
|
||||
->createOne();
|
||||
@@ -46,6 +51,8 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory())
|
||||
->createOne();
|
||||
@@ -66,11 +73,13 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory()->for(User::factory()))
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -86,7 +95,9 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testScoped(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -113,7 +124,9 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testTrashed(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for(Playlist::factory()->for($user))
|
||||
@@ -126,6 +139,40 @@ class TrackRestoreTest extends TestCase
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Restore Endpoint shall forbid users from restoring playlists
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(PlaylistTrack::class),
|
||||
ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->delete(route('api.playlist.track.destroy', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response = $this->patch(route('api.playlist.track.restore', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Restore Endpoint shall restore the sole playlist track.
|
||||
*
|
||||
@@ -133,7 +180,13 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testRestored(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(PlaylistTrack::class), ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)])->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(PlaylistTrack::class),
|
||||
ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -170,7 +223,14 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testRestoreFirst(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(PlaylistTrack::class), ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)])->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(PlaylistTrack::class),
|
||||
ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -214,7 +274,14 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testRestoreLast(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(PlaylistTrack::class), ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)])->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(PlaylistTrack::class),
|
||||
ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -253,7 +320,14 @@ class TrackRestoreTest extends TestCase
|
||||
*/
|
||||
public function testRestoreSecond(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(PlaylistTrack::class), ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)])->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(PlaylistTrack::class),
|
||||
ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -291,4 +365,39 @@ class TrackRestoreTest extends TestCase
|
||||
static::assertTrue($third->previous()->is($first));
|
||||
static::assertTrue($third->next()->is($second));
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to force delete playlist tracks
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDeletePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(PlaylistTrack::class),
|
||||
ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->delete(route('api.playlist.track.destroy', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response = $this->patch(route('api.playlist.track.restore', ['playlist' => $playlist, 'track' => $track]));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class TrackShowTest extends TestCase
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -85,7 +85,7 @@ class TrackShowTest extends TestCase
|
||||
*/
|
||||
public function testPrivatePlaylistTrackCanBeViewedByOwner(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -155,7 +155,7 @@ class TrackShowTest extends TestCase
|
||||
*/
|
||||
public function testScoped(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
|
||||
@@ -4,13 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist\Track;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Models\List\Playlist\PlaylistTrack;
|
||||
use App\Models\Wiki\Video;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -29,6 +32,8 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
@@ -47,6 +52,8 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
@@ -69,6 +76,8 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for(User::factory())
|
||||
->createOne();
|
||||
@@ -77,7 +86,35 @@ class TrackStoreTest extends TestCase
|
||||
->for($playlist)
|
||||
->makeOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->post(route('api.playlist.track.store', ['playlist' => $playlist] + $track->toArray()));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Store Endpoint shall forbid users from creating playlist tracks
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->for(Video::factory())
|
||||
->makeOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -93,7 +130,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -115,7 +154,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testProhibitsNextAndPrevious(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -154,7 +195,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testScopeNext(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -187,7 +230,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testScopePrevious(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -220,7 +265,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -253,7 +300,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testCreateAfterLastTrack(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$trackCount = $this->faker->numberBetween(2, 9);
|
||||
|
||||
@@ -299,7 +348,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testCreateAfterFirstTrack(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$trackCount = $this->faker->numberBetween(2, 9);
|
||||
|
||||
@@ -346,7 +397,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testCreateBeforeLastTrack(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$trackCount = $this->faker->numberBetween(2, 9);
|
||||
|
||||
@@ -393,7 +446,9 @@ class TrackStoreTest extends TestCase
|
||||
*/
|
||||
public function testCreateBeforeFirstTrack(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$trackCount = $this->faker->numberBetween(2, 9);
|
||||
|
||||
@@ -429,4 +484,37 @@ class TrackStoreTest extends TestCase
|
||||
static::assertTrue($track->previous()->doesntExist());
|
||||
static::assertTrue($track->next()->is($first));
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to create playlist tracks
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(PlaylistTrack::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->for(Video::factory())
|
||||
->makeOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->post(route('api.playlist.track.store', ['playlist' => $playlist] + $track->toArray()));
|
||||
|
||||
$response->assertCreated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Http\Api\List\Playlist\Track;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Enums\Models\List\PlaylistVisibility;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
@@ -12,6 +14,7 @@ use App\Models\List\Playlist\PlaylistTrack;
|
||||
use App\Models\Wiki\Video;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -30,6 +33,8 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
@@ -53,6 +58,8 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
@@ -80,6 +87,8 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for(User::factory())
|
||||
->createOne();
|
||||
@@ -93,7 +102,7 @@ class TrackUpdateTest extends TestCase
|
||||
[PlaylistTrack::ATTRIBUTE_VIDEO => Video::factory()->createOne()->getKey()],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -109,7 +118,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testScoped(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -141,7 +152,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testScopePrevious(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -179,7 +192,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testPreviousIsNotSelf(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -213,7 +228,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testScopeNext(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -251,7 +268,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testNextIsNotSelf(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -285,7 +304,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testProhibitsNextAndPrevious(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -322,6 +343,40 @@ class TrackUpdateTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Update Endpoint shall forbid users from updating playlists
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
$parameters = array_merge(
|
||||
PlaylistTrack::factory()->raw(),
|
||||
[
|
||||
PlaylistTrack::ATTRIBUTE_VIDEO => Video::factory()->createOne()->getKey(),
|
||||
],
|
||||
);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->put(route('api.playlist.track.update', ['playlist' => $playlist, 'track' => $track] + $parameters));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Track Update Endpoint shall forbid users from updating a track that is trashed.
|
||||
*
|
||||
@@ -329,7 +384,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testTrashed(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -372,7 +429,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -403,7 +462,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertFirstAfterSecond(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -449,7 +510,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertFirstAfterThird(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -495,7 +558,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertFirstBeforeThird(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -541,7 +606,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertSecondAfterThird(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -587,7 +654,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertSecondBeforeFirst(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -633,7 +702,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertThirdAfterFirst(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -679,7 +750,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertThirdBeforeSecond(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -725,7 +798,9 @@ class TrackUpdateTest extends TestCase
|
||||
*/
|
||||
public function testInsertThirdBeforeFirst(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -763,4 +838,43 @@ class TrackUpdateTest extends TestCase
|
||||
static::assertTrue($third->previous()->doesntExist());
|
||||
static::assertTrue($third->next()->is($first));
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to update playlist tracks
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUpdatePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::UPDATE()->format(PlaylistTrack::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
->createOne();
|
||||
|
||||
$track = PlaylistTrack::factory()
|
||||
->for($playlist)
|
||||
->createOne();
|
||||
|
||||
$parameters = array_merge(
|
||||
PlaylistTrack::factory()->raw(),
|
||||
[
|
||||
PlaylistTrack::ATTRIBUTE_VIDEO => Video::factory()->createOne()->getKey(),
|
||||
],
|
||||
);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->put(route('api.playlist.track.update', ['playlist' => $playlist, 'track' => $track] + $parameters));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Http\Api\Pivot\List\PlaylistImage;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Models\Wiki\Image;
|
||||
use App\Pivots\List\PlaylistImage;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -18,6 +22,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class PlaylistImageDestroyTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use WithoutEvents;
|
||||
|
||||
/**
|
||||
@@ -27,6 +32,8 @@ class PlaylistImageDestroyTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory())
|
||||
->for(Image::factory())
|
||||
@@ -44,6 +51,8 @@ class PlaylistImageDestroyTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory())
|
||||
->for(Image::factory())
|
||||
@@ -65,12 +74,46 @@ class PlaylistImageDestroyTest extends TestCase
|
||||
*/
|
||||
public function testForbiddenIfNotOwnPlaylist(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory()->for(User::factory()))
|
||||
->for(Image::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Playlist::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Playlist::class),
|
||||
CrudPermission::DELETE()->format(Image::class))
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlistimage.destroy', ['playlist' => $playlistImage->playlist, 'image' => $playlistImage->image]));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Image Destroy Endpoint shall forbid users from destroying playlist images
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Playlist::class),
|
||||
CrudPermission::DELETE()->format(Image::class))
|
||||
->createOne();
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory()->for($user))
|
||||
->for(Image::factory())
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -86,7 +129,14 @@ class PlaylistImageDestroyTest extends TestCase
|
||||
*/
|
||||
public function testNotFound(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Playlist::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Playlist::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlist = Playlist::factory()
|
||||
->for($user)
|
||||
@@ -107,7 +157,14 @@ class PlaylistImageDestroyTest extends TestCase
|
||||
*/
|
||||
public function testDeleted(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Playlist::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Playlist::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory()->for($user))
|
||||
@@ -121,4 +178,34 @@ class PlaylistImageDestroyTest extends TestCase
|
||||
$response->assertOk();
|
||||
static::assertModelMissing($playlistImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to destroy playlist images
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDestroyPermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Playlist::class),
|
||||
CrudPermission::DELETE()->format(Image::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory()->for($user))
|
||||
->for(Image::factory())
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->delete(route('api.playlistimage.destroy', ['playlist' => $playlistImage->playlist, 'image' => $playlistImage->image]));
|
||||
|
||||
$response->assertOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class PlaylistImageShowTest extends TestCase
|
||||
->for(Image::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -109,7 +109,7 @@ class PlaylistImageShowTest extends TestCase
|
||||
*/
|
||||
public function testPrivatePlaylistImageCanBeViewedByOwner(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(Playlist::class))->createOne();
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(
|
||||
|
||||
@@ -4,12 +4,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace Http\Api\Pivot\List\PlaylistImage;
|
||||
|
||||
use App\Constants\Config\FlagConstants;
|
||||
use App\Enums\Auth\CrudPermission;
|
||||
use App\Enums\Auth\SpecialPermission;
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Models\Wiki\Image;
|
||||
use App\Pivots\List\PlaylistImage;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -18,6 +22,7 @@ use Tests\TestCase;
|
||||
*/
|
||||
class PlaylistImageStoreTest extends TestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use WithoutEvents;
|
||||
|
||||
/**
|
||||
@@ -27,6 +32,8 @@ class PlaylistImageStoreTest extends TestCase
|
||||
*/
|
||||
public function testProtected(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory())
|
||||
->for(Image::factory())
|
||||
@@ -42,8 +49,10 @@ class PlaylistImageStoreTest extends TestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbidden(): void
|
||||
public function testForbiddenIfMissingPermission(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$playlistImage = PlaylistImage::factory()
|
||||
->for(Playlist::factory())
|
||||
->for(Image::factory())
|
||||
@@ -58,6 +67,35 @@ class PlaylistImageStoreTest extends TestCase
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Image Store Endpoint shall forbid users from creating playlist images
|
||||
* if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testForbiddenIfFlagDisabled(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false);
|
||||
|
||||
$parameters = [
|
||||
PlaylistImage::ATTRIBUTE_PLAYLIST => Playlist::factory()->createOne()->getKey(),
|
||||
PlaylistImage::ATTRIBUTE_IMAGE => Image::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Playlist::class),
|
||||
CrudPermission::CREATE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->post(route('api.playlistimage.store', $parameters));
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Playlist Image Store Endpoint shall require playlist and image fields.
|
||||
*
|
||||
@@ -65,7 +103,14 @@ class PlaylistImageStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Playlist::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Playlist::class),
|
||||
CrudPermission::CREATE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -84,12 +129,19 @@ class PlaylistImageStoreTest extends TestCase
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true);
|
||||
|
||||
$parameters = [
|
||||
PlaylistImage::ATTRIBUTE_PLAYLIST => Playlist::factory()->createOne()->getKey(),
|
||||
PlaylistImage::ATTRIBUTE_IMAGE => Image::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Playlist::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Playlist::class),
|
||||
CrudPermission::CREATE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -98,4 +150,34 @@ class PlaylistImageStoreTest extends TestCase
|
||||
$response->assertCreated();
|
||||
static::assertDatabaseCount(PlaylistImage::TABLE, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Users with the bypass feature flag permission shall be permitted to create playlist images
|
||||
* even if the 'flags.allow_playlist_management' property is disabled.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreatePermittedForBypass(): void
|
||||
{
|
||||
Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean());
|
||||
|
||||
$parameters = [
|
||||
PlaylistImage::ATTRIBUTE_PLAYLIST => Playlist::factory()->createOne()->getKey(),
|
||||
PlaylistImage::ATTRIBUTE_IMAGE => Image::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Playlist::class),
|
||||
CrudPermission::CREATE()->format(Image::class),
|
||||
SpecialPermission::BYPASS_FEATURE_FLAGS
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->post(route('api.playlistimage.store', $parameters));
|
||||
|
||||
$response->assertCreated();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,12 @@ class AnimeImageDestroyTest extends TestCase
|
||||
$anime = Anime::factory()->createOne();
|
||||
$image = Image::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class AnimeImageDestroyTest extends TestCase
|
||||
->for(Image::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,11 @@ class AnimeImageStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(Image::class))
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +93,11 @@ class AnimeImageStoreTest extends TestCase
|
||||
AnimeImage::ATTRIBUTE_IMAGE => Image::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(Image::class))
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class AnimeResourceDestroyTest extends TestCase
|
||||
$anime = Anime::factory()->createOne();
|
||||
$resource = ExternalResource::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class AnimeResourceDestroyTest extends TestCase
|
||||
->for(ExternalResource::factory(), AnimeResource::RELATION_RESOURCE)
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class AnimeResourceStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -90,7 +95,12 @@ class AnimeResourceStoreTest extends TestCase
|
||||
[AnimeResource::ATTRIBUTE_RESOURCE => ExternalResource::factory()->createOne()->getKey()],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -76,7 +76,12 @@ class AnimeResourceUpdateTest extends TestCase
|
||||
|
||||
$parameters = AnimeResource::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::UPDATE()->format(Anime::class), CrudPermission::UPDATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::UPDATE()->format(Anime::class),
|
||||
CrudPermission::UPDATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class AnimeSeriesDestroyTest extends TestCase
|
||||
$anime = Anime::factory()->createOne();
|
||||
$series = Series::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(Series::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(Series::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class AnimeSeriesDestroyTest extends TestCase
|
||||
->for(Series::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(Series::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(Series::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class AnimeSeriesStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(Series::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(Series::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class AnimeSeriesStoreTest extends TestCase
|
||||
AnimeSeries::ATTRIBUTE_SERIES => Series::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(Series::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(Series::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class AnimeStudioDestroyTest extends TestCase
|
||||
$anime = Anime::factory()->createOne();
|
||||
$studio = Studio::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(Studio::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(Studio::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class AnimeStudioDestroyTest extends TestCase
|
||||
->for(Studio::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Anime::class), CrudPermission::DELETE()->format(Studio::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Anime::class),
|
||||
CrudPermission::DELETE()->format(Studio::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class AnimeStudioStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(Studio::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(Studio::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class AnimeStudioStoreTest extends TestCase
|
||||
AnimeStudio::ATTRIBUTE_STUDIO => Studio::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Anime::class), CrudPermission::CREATE()->format(Studio::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Anime::class),
|
||||
CrudPermission::CREATE()->format(Studio::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
+12
-2
@@ -73,7 +73,12 @@ class AnimeThemeEntryVideoDestroyTest extends TestCase
|
||||
|
||||
$video = Video::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(AnimeThemeEntry::class), CrudPermission::DELETE()->format(Video::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(AnimeThemeEntry::class),
|
||||
CrudPermission::DELETE()->format(Video::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -94,7 +99,12 @@ class AnimeThemeEntryVideoDestroyTest extends TestCase
|
||||
->for(Video::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(AnimeThemeEntry::class), CrudPermission::DELETE()->format(Video::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(AnimeThemeEntry::class),
|
||||
CrudPermission::DELETE()->format(Video::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
+12
-2
@@ -67,7 +67,12 @@ class AnimeThemeEntryVideoStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(AnimeThemeEntry::class), CrudPermission::CREATE()->format(Video::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(AnimeThemeEntry::class),
|
||||
CrudPermission::CREATE()->format(Video::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -95,7 +100,12 @@ class AnimeThemeEntryVideoStoreTest extends TestCase
|
||||
AnimeThemeEntryVideo::ATTRIBUTE_VIDEO => Video::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(AnimeThemeEntry::class), CrudPermission::CREATE()->format(Video::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(AnimeThemeEntry::class),
|
||||
CrudPermission::CREATE()->format(Video::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class ArtistImageDestroyTest extends TestCase
|
||||
$artist = Artist::factory()->createOne();
|
||||
$image = Image::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Artist::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Artist::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class ArtistImageDestroyTest extends TestCase
|
||||
->for(Image::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Artist::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Artist::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class ArtistImageStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Artist::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Artist::class),
|
||||
CrudPermission::CREATE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class ArtistImageStoreTest extends TestCase
|
||||
ArtistImage::ATTRIBUTE_IMAGE => Image::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Artist::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Artist::class),
|
||||
CrudPermission::CREATE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class ArtistMemberDestroyTest extends TestCase
|
||||
$artist = Artist::factory()->createOne();
|
||||
$member = Artist::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Artist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Artist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -88,7 +88,7 @@ class ArtistMemberDestroyTest extends TestCase
|
||||
->for(Artist::factory(), ArtistMember::RELATION_MEMBER)
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Artist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Artist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ use App\Http\Api\Query\Query;
|
||||
use App\Http\Api\Schema\Pivot\Wiki\ArtistMemberSchema;
|
||||
use App\Http\Resources\Pivot\Wiki\Resource\ArtistMemberResource;
|
||||
use App\Models\Wiki\Artist;
|
||||
use App\Models\Wiki\Member;
|
||||
use App\Pivots\Wiki\ArtistMember;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\WithoutEvents;
|
||||
|
||||
@@ -64,7 +64,7 @@ class ArtistMemberStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Artist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Artist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +89,7 @@ class ArtistMemberStoreTest extends TestCase
|
||||
[ArtistMember::ATTRIBUTE_MEMBER => Artist::factory()->createOne()->getKey()],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Artist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Artist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ class ArtistMemberUpdateTest extends TestCase
|
||||
|
||||
$parameters = ArtistMember::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Artist::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Artist::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class ArtistResourceDestroyTest extends TestCase
|
||||
$artist = Artist::factory()->createOne();
|
||||
$resource = ExternalResource::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Artist::class), CrudPermission::DELETE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Artist::class),
|
||||
CrudPermission::DELETE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class ArtistResourceDestroyTest extends TestCase
|
||||
->for(ExternalResource::factory(), ArtistResource::RELATION_RESOURCE)
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Artist::class), CrudPermission::DELETE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Artist::class),
|
||||
CrudPermission::DELETE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class ArtistResourceStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Artist::class), CrudPermission::CREATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Artist::class),
|
||||
CrudPermission::CREATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -90,7 +95,12 @@ class ArtistResourceStoreTest extends TestCase
|
||||
[ArtistResource::ATTRIBUTE_RESOURCE => ExternalResource::factory()->createOne()->getKey()],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Artist::class), CrudPermission::CREATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Artist::class),
|
||||
CrudPermission::CREATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -76,7 +76,12 @@ class ArtistResourceUpdateTest extends TestCase
|
||||
|
||||
$parameters = ArtistResource::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::UPDATE()->format(Artist::class), CrudPermission::UPDATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::UPDATE()->format(Artist::class),
|
||||
CrudPermission::UPDATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class ArtistSongDestroyTest extends TestCase
|
||||
$artist = Artist::factory()->createOne();
|
||||
$song = Song::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Artist::class), CrudPermission::DELETE()->format(Song::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Artist::class),
|
||||
CrudPermission::DELETE()->format(Song::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class ArtistSongDestroyTest extends TestCase
|
||||
->for(Song::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Artist::class), CrudPermission::DELETE()->format(Song::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Artist::class),
|
||||
CrudPermission::DELETE()->format(Song::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class ArtistSongStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Artist::class), CrudPermission::CREATE()->format(Song::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Artist::class),
|
||||
CrudPermission::CREATE()->format(Song::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -90,7 +95,12 @@ class ArtistSongStoreTest extends TestCase
|
||||
[ArtistSong::ATTRIBUTE_SONG => Song::factory()->createOne()->getKey()],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Artist::class), CrudPermission::CREATE()->format(Song::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Artist::class),
|
||||
CrudPermission::CREATE()->format(Song::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -76,7 +76,12 @@ class ArtistSongUpdateTest extends TestCase
|
||||
|
||||
$parameters = ArtistSong::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::UPDATE()->format(Artist::class), CrudPermission::UPDATE()->format(Song::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::UPDATE()->format(Artist::class),
|
||||
CrudPermission::UPDATE()->format(Song::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class StudioImageDestroyTest extends TestCase
|
||||
$studio = Studio::factory()->createOne();
|
||||
$image = Image::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Studio::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Studio::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class StudioImageDestroyTest extends TestCase
|
||||
->for(Image::factory())
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Studio::class), CrudPermission::DELETE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Studio::class),
|
||||
CrudPermission::DELETE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class StudioImageStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Studio::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Studio::class),
|
||||
CrudPermission::CREATE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class StudioImageStoreTest extends TestCase
|
||||
StudioImage::ATTRIBUTE_IMAGE => Image::factory()->createOne()->getKey(),
|
||||
];
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Studio::class), CrudPermission::CREATE()->format(Image::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Studio::class),
|
||||
CrudPermission::CREATE()->format(Image::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,12 @@ class StudioResourceDestroyTest extends TestCase
|
||||
$studio = Studio::factory()->createOne();
|
||||
$resource = ExternalResource::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Studio::class), CrudPermission::DELETE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Studio::class),
|
||||
CrudPermission::DELETE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -89,7 +94,12 @@ class StudioResourceDestroyTest extends TestCase
|
||||
->for(ExternalResource::factory(), StudioResource::RELATION_RESOURCE)
|
||||
->createOne();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::DELETE()->format(Studio::class), CrudPermission::DELETE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::DELETE()->format(Studio::class),
|
||||
CrudPermission::DELETE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -65,7 +65,12 @@ class StudioResourceStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Studio::class), CrudPermission::CREATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Studio::class),
|
||||
CrudPermission::CREATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -90,7 +95,12 @@ class StudioResourceStoreTest extends TestCase
|
||||
[StudioResource::ATTRIBUTE_RESOURCE => ExternalResource::factory()->createOne()->getKey()],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::CREATE()->format(Studio::class), CrudPermission::CREATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::CREATE()->format(Studio::class),
|
||||
CrudPermission::CREATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -76,7 +76,12 @@ class StudioResourceUpdateTest extends TestCase
|
||||
|
||||
$parameters = StudioResource::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermissions([CrudPermission::UPDATE()->format(Studio::class), CrudPermission::UPDATE()->format(ExternalResource::class)])->createOne();
|
||||
$user = User::factory()
|
||||
->withPermissions(
|
||||
CrudPermission::UPDATE()->format(Studio::class),
|
||||
CrudPermission::UPDATE()->format(ExternalResource::class)
|
||||
)
|
||||
->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class ThrottleTest extends TestCase
|
||||
*/
|
||||
public function testClientNotRateLimited(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(SpecialPermission::BYPASS_API_RATE_LIMITER)->createOne();
|
||||
$user = User::factory()->withPermissions(SpecialPermission::BYPASS_API_RATE_LIMITER)->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class AnimeDestroyTest extends TestCase
|
||||
|
||||
$anime->delete();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -79,7 +79,7 @@ class AnimeDestroyTest extends TestCase
|
||||
{
|
||||
$anime = Anime::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class AnimeForceDeleteTest extends TestCase
|
||||
{
|
||||
$anime = Anime::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class AnimeRestoreTest extends TestCase
|
||||
{
|
||||
$anime = Anime::factory()->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -83,7 +83,7 @@ class AnimeRestoreTest extends TestCase
|
||||
|
||||
$anime->delete();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class AnimeStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -84,7 +84,7 @@ class AnimeStoreTest extends TestCase
|
||||
[Anime::ATTRIBUTE_SEASON => AnimeSeason::getRandomInstance()->description],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class AnimeUpdateTest extends TestCase
|
||||
[Anime::ATTRIBUTE_SEASON => AnimeSeason::getRandomInstance()->description],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -100,7 +100,7 @@ class AnimeUpdateTest extends TestCase
|
||||
[Anime::ATTRIBUTE_SEASON => AnimeSeason::getRandomInstance()->description],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(Anime::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Anime::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class SynonymDestroyTest extends TestCase
|
||||
|
||||
$synonym->delete();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -80,7 +80,7 @@ class SynonymDestroyTest extends TestCase
|
||||
{
|
||||
$synonym = AnimeSynonym::factory()->for(Anime::factory())->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::DELETE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::DELETE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class SynonymForceDeleteTest extends TestCase
|
||||
{
|
||||
$synonym = AnimeSynonym::factory()->for(Anime::factory())->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::FORCE_DELETE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class SynonymRestoreTest extends TestCase
|
||||
{
|
||||
$synonym = AnimeSynonym::factory()->for(Anime::factory())->createOne();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -84,7 +84,7 @@ class SynonymRestoreTest extends TestCase
|
||||
|
||||
$synonym->delete();
|
||||
|
||||
$user = User::factory()->withPermission(ExtendedCrudPermission::RESTORE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class SynonymStoreTest extends TestCase
|
||||
*/
|
||||
public function testRequiredFields(): void
|
||||
{
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -83,7 +83,7 @@ class SynonymStoreTest extends TestCase
|
||||
[AnimeSynonym::ATTRIBUTE_ANIME => $anime->getKey()],
|
||||
);
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::CREATE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::CREATE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class SynonymUpdateTest extends TestCase
|
||||
|
||||
$parameters = AnimeSynonym::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::VIEW()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::VIEW()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
@@ -88,7 +88,7 @@ class SynonymUpdateTest extends TestCase
|
||||
|
||||
$parameters = AnimeSynonym::factory()->raw();
|
||||
|
||||
$user = User::factory()->withPermission(CrudPermission::UPDATE()->format(AnimeSynonym::class))->createOne();
|
||||
$user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(AnimeSynonym::class))->createOne();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user