From 088ea287c5efc695747d4e2357b11269100199f8 Mon Sep 17 00:00:00 2001 From: paranarimasu <33796518+paranarimasu@users.noreply.github.com> Date: Sun, 23 Apr 2023 18:54:34 -0500 Subject: [PATCH] feat: initial migration to pennant features for feature flags and global site config [incremental] (#573) * feat: initial commit for feature management * style: fix StyleCI findings * fix(api): prohibit features of nonnull scope from API & fix(admin): wrong translate key * style: fix Static Analysis error --- .env.example | 13 +- app/Console/Kernel.php | 3 +- app/Constants/Config/FlagConstants.php | 39 --- app/Constants/Config/VideoConstants.php | 4 - app/Constants/FeatureConstants.php | 19 ++ app/Contracts/Events/DiscordMessageEvent.php | 7 + .../Events/NovaNotificationEvent.php | 6 +- app/Events/Admin/Feature/FeatureCreated.php | 34 +++ app/Events/Admin/Feature/FeatureDeleted.php | 32 +++ app/Events/Admin/Feature/FeatureEvent.php | 56 ++++ app/Events/Admin/Feature/FeatureUpdated.php | 48 ++++ app/Events/Admin/Setting/SettingCreated.php | 15 +- app/Events/Admin/Setting/SettingDeleted.php | 15 +- app/Events/Admin/Setting/SettingEvent.php | 25 +- app/Events/Admin/Setting/SettingUpdated.php | 15 +- app/Events/Auth/User/UserCreated.php | 15 +- app/Events/Auth/User/UserDeleted.php | 15 +- app/Events/Auth/User/UserEvent.php | 25 +- app/Events/Auth/User/UserRestored.php | 15 +- app/Events/Auth/User/UserUpdated.php | 15 +- app/Events/Base/Admin/AdminCreatedEvent.php | 10 + app/Events/Base/Admin/AdminDeletedEvent.php | 10 + app/Events/Base/Admin/AdminRestoredEvent.php | 10 + app/Events/Base/Admin/AdminUpdatedEvent.php | 10 + app/Events/Base/BaseCreatedEvent.php | 10 + app/Events/Base/BaseDeletedEvent.php | 10 + app/Events/Base/BaseRestoredEvent.php | 10 + app/Events/Base/BaseUpdatedEvent.php | 10 + app/Events/Base/Wiki/WikiDeletedEvent.php | 10 +- app/Events/BasePivotEvent.php | 10 + app/Events/Document/Page/PageDeleted.php | 2 +- app/Events/Wiki/Anime/AnimeDeleted.php | 2 +- .../Wiki/Anime/Synonym/SynonymDeleted.php | 2 +- .../Wiki/Anime/Theme/Entry/EntryDeleted.php | 2 +- app/Events/Wiki/Anime/Theme/ThemeDeleted.php | 2 +- app/Events/Wiki/Artist/ArtistDeleted.php | 2 +- app/Events/Wiki/Audio/AudioDeleted.php | 2 +- .../ExternalResourceDeleted.php | 2 +- app/Events/Wiki/Image/ImageDeleted.php | 2 +- app/Events/Wiki/Series/SeriesDeleted.php | 2 +- app/Events/Wiki/Song/SongDeleted.php | 2 +- app/Events/Wiki/Studio/StudioDeleted.php | 2 +- .../Wiki/Video/Script/VideoScriptDeleted.php | 2 +- app/Events/Wiki/Video/VideoDeleted.php | 2 +- app/Features/AllowAudioStreams.php | 19 ++ app/Features/AllowDumpDownloading.php | 19 ++ app/Features/AllowPlaylistManagement.php | 19 ++ app/Features/AllowScriptDownloading.php | 19 ++ app/Features/AllowVideoStreams.php | 19 ++ .../Field/Admin/Feature/FeatureNameField.php | 25 ++ .../Field/Admin/Feature/FeatureValueField.php | 43 +++ .../Flags/FlagsAllowAudioStreamsField.php | 25 -- .../FlagsAllowDiscordNotificationsField.php | 25 -- .../Flags/FlagsAllowDumpDownloadingField.php | 25 -- .../FlagsAllowPlaylistManagementField.php | 25 -- .../FlagsAllowScriptDownloadingField.php | 25 -- .../Flags/FlagsAllowVideoStreamsField.php | 25 -- .../Flags/FlagsAllowViewRecordingField.php | 25 -- app/Http/Api/Schema/Admin/FeatureSchema.php | 58 ++++ app/Http/Api/Schema/Config/FlagsSchema.php | 63 ---- .../Api/Admin/FeatureController.php | 82 ++++++ .../Api/Config/FlagsController.php | 42 --- .../Api/List/Playlist/TrackController.php | 9 +- .../Api/List/PlaylistController.php | 9 +- .../Pivot/List/PlaylistImageController.php | 9 +- app/Http/Kernel.php | 2 - app/Http/Middleware/IsFeatureEnabled.php | 43 --- app/Http/Middleware/Models/RecordView.php | 6 +- .../Admin/Collection/FeatureCollection.php | 38 +++ .../Admin/Resource/FeatureResource.php | 32 +++ .../Config/Resource/FlagsResource.php | 81 ------ app/Jobs/SendDiscordNotificationJob.php | 6 +- app/Listeners/NotifiesNovaUsers.php | 6 +- app/Listeners/SendDiscordNotification.php | 17 +- app/Models/Admin/Feature.php | 96 +++++++ app/Notifications/DiscordNotification.php | 6 +- app/Nova/Resources/Admin/Feature.php | 140 +++++++++ app/Policies/Admin/FeaturePolicy.php | 81 ++++++ app/Providers/AppServiceProvider.php | 70 +---- .../Format/EncoderVersionFormatRule.php | 6 +- composer.json | 1 + composer.lock | 78 ++++- config/flags.php | 98 ------- config/pennant.php | 44 +++ config/setting.php | 9 - config/video.php | 13 - database/factories/Admin/FeatureFactory.php | 41 +++ ...022_11_01_000001_create_features_table.php | 39 +++ .../seeders/Admin/Feature/FeatureSeeder.php | 38 +++ .../seeders/Admin/Setting/SettingSeeder.php | 82 ------ .../Auth/Permission/PermissionSeeder.php | 2 + database/seeders/Auth/Role/AdminSeeder.php | 2 + database/seeders/DatabaseSeeder.php | 2 + lang/en/nova.php | 12 + routes/api.php | 5 +- routes/audio.php | 9 +- routes/dump.php | 9 +- routes/script.php | 9 +- routes/video.php | 9 +- tests/Feature/Events/Admin/FeatureTest.php | 81 ++++++ tests/Feature/Http/Admin/DumpTest.php | 15 +- .../Http/Admin/LatestDocumentDumpTest.php | 17 +- .../Feature/Http/Admin/LatestWikiDumpTest.php | 17 +- .../Api/Admin/Feature/FeatureIndexTest.php | 272 ++++++++++++++++++ .../Api/Admin/Feature/FeatureShowTest.php | 96 +++++++ .../Api/Admin/Feature/FeatureUpdateTest.php | 79 +++++ .../Feature/Http/Api/Config/FlagsShowTest.php | 85 ------ .../Feature/Http/Api/Config/WikiShowTest.php | 2 +- .../Api/List/Playlist/PlaylistDestroyTest.php | 22 +- .../List/Playlist/PlaylistForceDeleteTest.php | 18 +- .../Api/List/Playlist/PlaylistRestoreTest.php | 25 +- .../Api/List/Playlist/PlaylistStoreTest.php | 29 +- .../Api/List/Playlist/PlaylistUpdateTest.php | 27 +- .../List/Playlist/Track/TrackDestroyTest.php | 30 +- .../Playlist/Track/TrackForceDeleteTest.php | 26 +- .../List/Playlist/Track/TrackRestoreTest.php | 33 +-- .../List/Playlist/Track/TrackStoreTest.php | 39 +-- .../List/Playlist/Track/TrackUpdateTest.php | 50 ++-- .../PlaylistImageDestroyTest.php | 22 +- .../PlaylistImage/PlaylistImageStoreTest.php | 18 +- tests/Feature/Http/Wiki/Audio/AudioTest.php | 32 ++- .../Http/Wiki/Video/Script/ScriptTest.php | 15 +- tests/Feature/Http/Wiki/Video/VideoTest.php | 32 ++- tests/Feature/Jobs/Admin/AnnouncementTest.php | 12 +- tests/Feature/Jobs/Admin/DumpTest.php | 12 +- tests/Feature/Jobs/Admin/FeatureTest.php | 76 +++++ tests/Feature/Jobs/Admin/SettingTest.php | 10 +- tests/Feature/Jobs/Auth/UserTest.php | 12 +- tests/Feature/Jobs/Billing/BalanceTest.php | 12 +- .../Feature/Jobs/Billing/TransactionTest.php | 12 +- tests/Feature/Jobs/Document/PageTest.php | 12 +- .../Feature/Jobs/List/Playlist/TrackTest.php | 12 +- tests/Feature/Jobs/List/PlaylistTest.php | 12 +- .../Jobs/Pivot/List/PlaylistImageTest.php | 8 +- .../Jobs/Pivot/Wiki/AnimeImageTest.php | 8 +- .../Jobs/Pivot/Wiki/AnimeResourceTest.php | 10 +- .../Jobs/Pivot/Wiki/AnimeSeriesTest.php | 8 +- .../Jobs/Pivot/Wiki/AnimeStudioTest.php | 8 +- .../Pivot/Wiki/AnimeThemeEntryVideoTest.php | 8 +- .../Jobs/Pivot/Wiki/ArtistImageTest.php | 8 +- .../Jobs/Pivot/Wiki/ArtistMemberTest.php | 10 +- .../Jobs/Pivot/Wiki/ArtistResourceTest.php | 10 +- .../Jobs/Pivot/Wiki/ArtistSongTest.php | 10 +- .../Jobs/Pivot/Wiki/StudioImageTest.php | 8 +- .../Jobs/Pivot/Wiki/StudioResourceTest.php | 10 +- .../Jobs/SendDiscordNotificationTest.php | 26 +- tests/Feature/Jobs/Wiki/Anime/SynonymTest.php | 12 +- .../Jobs/Wiki/Anime/Theme/EntryTest.php | 12 +- tests/Feature/Jobs/Wiki/Anime/ThemeTest.php | 12 +- tests/Feature/Jobs/Wiki/AnimeTest.php | 12 +- tests/Feature/Jobs/Wiki/ArtistTest.php | 12 +- tests/Feature/Jobs/Wiki/AudioTest.php | 12 +- .../Jobs/Wiki/ExternalResourceTest.php | 12 +- tests/Feature/Jobs/Wiki/ImageTest.php | 12 +- tests/Feature/Jobs/Wiki/SeriesTest.php | 12 +- tests/Feature/Jobs/Wiki/SongTest.php | 12 +- tests/Feature/Jobs/Wiki/StudioTest.php | 12 +- tests/Feature/Jobs/Wiki/Video/ScriptTest.php | 12 +- tests/Feature/Jobs/Wiki/VideoTest.php | 12 +- .../Listeners/SendDiscordNotificationTest.php | 32 ++- tests/Unit/Models/Admin/FeatureTest.php | 55 ++++ 161 files changed, 2521 insertions(+), 1404 deletions(-) delete mode 100644 app/Constants/Config/FlagConstants.php create mode 100644 app/Constants/FeatureConstants.php create mode 100644 app/Events/Admin/Feature/FeatureCreated.php create mode 100644 app/Events/Admin/Feature/FeatureDeleted.php create mode 100644 app/Events/Admin/Feature/FeatureEvent.php create mode 100644 app/Events/Admin/Feature/FeatureUpdated.php create mode 100644 app/Features/AllowAudioStreams.php create mode 100644 app/Features/AllowDumpDownloading.php create mode 100644 app/Features/AllowPlaylistManagement.php create mode 100644 app/Features/AllowScriptDownloading.php create mode 100644 app/Features/AllowVideoStreams.php create mode 100644 app/Http/Api/Field/Admin/Feature/FeatureNameField.php create mode 100644 app/Http/Api/Field/Admin/Feature/FeatureValueField.php delete mode 100644 app/Http/Api/Field/Config/Flags/FlagsAllowAudioStreamsField.php delete mode 100644 app/Http/Api/Field/Config/Flags/FlagsAllowDiscordNotificationsField.php delete mode 100644 app/Http/Api/Field/Config/Flags/FlagsAllowDumpDownloadingField.php delete mode 100644 app/Http/Api/Field/Config/Flags/FlagsAllowPlaylistManagementField.php delete mode 100644 app/Http/Api/Field/Config/Flags/FlagsAllowScriptDownloadingField.php delete mode 100644 app/Http/Api/Field/Config/Flags/FlagsAllowVideoStreamsField.php delete mode 100644 app/Http/Api/Field/Config/Flags/FlagsAllowViewRecordingField.php create mode 100644 app/Http/Api/Schema/Admin/FeatureSchema.php delete mode 100644 app/Http/Api/Schema/Config/FlagsSchema.php create mode 100644 app/Http/Controllers/Api/Admin/FeatureController.php delete mode 100644 app/Http/Controllers/Api/Config/FlagsController.php delete mode 100644 app/Http/Middleware/IsFeatureEnabled.php create mode 100644 app/Http/Resources/Admin/Collection/FeatureCollection.php create mode 100644 app/Http/Resources/Admin/Resource/FeatureResource.php delete mode 100644 app/Http/Resources/Config/Resource/FlagsResource.php create mode 100644 app/Models/Admin/Feature.php create mode 100644 app/Nova/Resources/Admin/Feature.php create mode 100644 app/Policies/Admin/FeaturePolicy.php delete mode 100644 config/flags.php create mode 100644 config/pennant.php create mode 100644 database/factories/Admin/FeatureFactory.php create mode 100644 database/migrations/2022_11_01_000001_create_features_table.php create mode 100644 database/seeders/Admin/Feature/FeatureSeeder.php create mode 100644 tests/Feature/Events/Admin/FeatureTest.php create mode 100644 tests/Feature/Http/Api/Admin/Feature/FeatureIndexTest.php create mode 100644 tests/Feature/Http/Api/Admin/Feature/FeatureShowTest.php create mode 100644 tests/Feature/Http/Api/Admin/Feature/FeatureUpdateTest.php delete mode 100644 tests/Feature/Http/Api/Config/FlagsShowTest.php create mode 100644 tests/Feature/Jobs/Admin/FeatureTest.php create mode 100644 tests/Unit/Models/Admin/FeatureTest.php diff --git a/.env.example b/.env.example index 8ef7af993..842658a9c 100644 --- a/.env.example +++ b/.env.example @@ -157,15 +157,6 @@ SCRIPT_STREAM_READS= SCRIPT_DISABLE_ASSERTS= SCRIPT_VISIBILITY= -# flags -ALLOW_VIDEO_STREAMS=false -ALLOW_AUDIO_STREAMS=false -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 FORTIFY_PATH= @@ -214,6 +205,9 @@ NOVA_LICENSE_KEY= NOVA_PASSWORDS=null NOVA_PATH=/admin +# pennant +PENNANT_STORE=database + # playlist PLAYLIST_MAX_TRACKS=1000 USER_MAX_PLAYLISTS=1000 @@ -278,7 +272,6 @@ VIDEO_PATH=/video VIDEO_URL= VIDEO_STREAMING_METHOD=response VIDEO_NGINX_REDIRECT= -VIDEO_ENCODER_VERSION= SCRIPT_DISK=scripts_local SCRIPT_DISK_ROOT= diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 312039b68..b96df1d30 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -18,7 +18,6 @@ use Illuminate\Database\Console\PruneCommand as PruneModelsCommand; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Queue\Console\MonitorCommand as MonitorQueueCommand; use Illuminate\Queue\Console\PruneFailedJobsCommand; -use Illuminate\Support\Facades\Config; use Laravel\Horizon\Console\SnapshotCommand; use Laravel\Sanctum\Console\Commands\PruneExpired; use Laravel\Telescope\Console\PruneCommand as PruneTelescopeEntriesCommand; @@ -99,7 +98,7 @@ class Kernel extends ConsoleKernel ->storeOutput() ->hourly(); - if (Config::bool('telescope.enabled')) { + if (config('telescope.enabled') === true) { $schedule->command(PruneTelescopeEntriesCommand::class) ->withoutOverlapping() ->runInBackground() diff --git a/app/Constants/Config/FlagConstants.php b/app/Constants/Config/FlagConstants.php deleted file mode 100644 index ef8504f4b..000000000 --- a/app/Constants/Config/FlagConstants.php +++ /dev/null @@ -1,39 +0,0 @@ -getFeature(); + + return DiscordMessage::create('', [ + 'description' => "Feature '**{$feature->getName()}**' has been created.", + 'color' => EmbedColor::GREEN, + ]); + } +} diff --git a/app/Events/Admin/Feature/FeatureDeleted.php b/app/Events/Admin/Feature/FeatureDeleted.php new file mode 100644 index 000000000..b412ccc6f --- /dev/null +++ b/app/Events/Admin/Feature/FeatureDeleted.php @@ -0,0 +1,32 @@ +getFeature(); + + return DiscordMessage::create('', [ + 'description' => "Feature '**{$feature->getName()}**' has been deleted.", + 'color' => EmbedColor::RED, + ]); + } +} diff --git a/app/Events/Admin/Feature/FeatureEvent.php b/app/Events/Admin/Feature/FeatureEvent.php new file mode 100644 index 000000000..5fd1b679b --- /dev/null +++ b/app/Events/Admin/Feature/FeatureEvent.php @@ -0,0 +1,56 @@ +feature; + } + + /** + * Get Discord channel the message will be sent to. + * + * @return string + */ + public function getDiscordChannel(): string + { + return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); + } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return $this->feature->isNullScope(); + } +} diff --git a/app/Events/Admin/Feature/FeatureUpdated.php b/app/Events/Admin/Feature/FeatureUpdated.php new file mode 100644 index 000000000..1ca8a1373 --- /dev/null +++ b/app/Events/Admin/Feature/FeatureUpdated.php @@ -0,0 +1,48 @@ +initializeEmbedFields($feature); + } + + /** + * Get Discord message payload. + * + * @return DiscordMessage + */ + public function getDiscordMessage(): DiscordMessage + { + $feature = $this->getFeature(); + + return DiscordMessage::create('', [ + 'description' => "Feature '**{$feature->getName()}**' has been updated.", + 'fields' => $this->getEmbedFields(), + 'color' => EmbedColor::YELLOW, + ]); + } +} diff --git a/app/Events/Admin/Setting/SettingCreated.php b/app/Events/Admin/Setting/SettingCreated.php index a856db576..afe2543cf 100644 --- a/app/Events/Admin/Setting/SettingCreated.php +++ b/app/Events/Admin/Setting/SettingCreated.php @@ -4,18 +4,15 @@ declare(strict_types=1); namespace App\Events\Admin\Setting; -use App\Constants\Config\ServiceConstants; -use App\Contracts\Events\DiscordMessageEvent; use App\Enums\Discord\EmbedColor; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Config; use NotificationChannels\Discord\DiscordMessage; /** * Class SettingCreated. */ -class SettingCreated extends SettingEvent implements DiscordMessageEvent +class SettingCreated extends SettingEvent { use Dispatchable; use SerializesModels; @@ -34,14 +31,4 @@ class SettingCreated extends SettingEvent implements DiscordMessageEvent 'color' => EmbedColor::GREEN, ]); } - - /** - * Get Discord channel the message will be sent to. - * - * @return string - */ - public function getDiscordChannel(): string - { - return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); - } } diff --git a/app/Events/Admin/Setting/SettingDeleted.php b/app/Events/Admin/Setting/SettingDeleted.php index 5807800db..caf2c11ce 100644 --- a/app/Events/Admin/Setting/SettingDeleted.php +++ b/app/Events/Admin/Setting/SettingDeleted.php @@ -4,17 +4,14 @@ declare(strict_types=1); namespace App\Events\Admin\Setting; -use App\Constants\Config\ServiceConstants; -use App\Contracts\Events\DiscordMessageEvent; use App\Enums\Discord\EmbedColor; use Illuminate\Foundation\Events\Dispatchable; -use Illuminate\Support\Facades\Config; use NotificationChannels\Discord\DiscordMessage; /** * Class SettingDeleted. */ -class SettingDeleted extends SettingEvent implements DiscordMessageEvent +class SettingDeleted extends SettingEvent { use Dispatchable; @@ -32,14 +29,4 @@ class SettingDeleted extends SettingEvent implements DiscordMessageEvent 'color' => EmbedColor::RED, ]); } - - /** - * Get Discord channel the message will be sent to. - * - * @return string - */ - public function getDiscordChannel(): string - { - return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); - } } diff --git a/app/Events/Admin/Setting/SettingEvent.php b/app/Events/Admin/Setting/SettingEvent.php index 9a28d62ba..1520f2d22 100644 --- a/app/Events/Admin/Setting/SettingEvent.php +++ b/app/Events/Admin/Setting/SettingEvent.php @@ -4,12 +4,15 @@ declare(strict_types=1); namespace App\Events\Admin\Setting; +use App\Constants\Config\ServiceConstants; +use App\Contracts\Events\DiscordMessageEvent; use App\Models\Admin\Setting; +use Illuminate\Support\Facades\Config; /** * Class SettingEvent. */ -abstract class SettingEvent +abstract class SettingEvent implements DiscordMessageEvent { /** * Create a new event instance. @@ -30,4 +33,24 @@ abstract class SettingEvent { return $this->setting; } + + /** + * Get Discord channel the message will be sent to. + * + * @return string + */ + public function getDiscordChannel(): string + { + return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); + } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } } diff --git a/app/Events/Admin/Setting/SettingUpdated.php b/app/Events/Admin/Setting/SettingUpdated.php index f606e3dba..9b4e0f866 100644 --- a/app/Events/Admin/Setting/SettingUpdated.php +++ b/app/Events/Admin/Setting/SettingUpdated.php @@ -5,18 +5,15 @@ declare(strict_types=1); namespace App\Events\Admin\Setting; use App\Concerns\Discord\HasAttributeUpdateEmbedFields; -use App\Constants\Config\ServiceConstants; -use App\Contracts\Events\DiscordMessageEvent; use App\Enums\Discord\EmbedColor; use App\Models\Admin\Setting; use Illuminate\Foundation\Events\Dispatchable; -use Illuminate\Support\Facades\Config; use NotificationChannels\Discord\DiscordMessage; /** * Class SettingUpdated. */ -class SettingUpdated extends SettingEvent implements DiscordMessageEvent +class SettingUpdated extends SettingEvent { use Dispatchable; use HasAttributeUpdateEmbedFields; @@ -48,14 +45,4 @@ class SettingUpdated extends SettingEvent implements DiscordMessageEvent 'color' => EmbedColor::YELLOW, ]); } - - /** - * Get Discord channel the message will be sent to. - * - * @return string - */ - public function getDiscordChannel(): string - { - return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); - } } diff --git a/app/Events/Auth/User/UserCreated.php b/app/Events/Auth/User/UserCreated.php index cfee8ad1c..e9bd8b751 100644 --- a/app/Events/Auth/User/UserCreated.php +++ b/app/Events/Auth/User/UserCreated.php @@ -4,18 +4,15 @@ declare(strict_types=1); namespace App\Events\Auth\User; -use App\Constants\Config\ServiceConstants; -use App\Contracts\Events\DiscordMessageEvent; use App\Enums\Discord\EmbedColor; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Config; use NotificationChannels\Discord\DiscordMessage; /** * Class UserCreated. */ -class UserCreated extends UserEvent implements DiscordMessageEvent +class UserCreated extends UserEvent { use Dispatchable; use SerializesModels; @@ -34,14 +31,4 @@ class UserCreated extends UserEvent implements DiscordMessageEvent 'color' => EmbedColor::GREEN, ]); } - - /** - * Get Discord channel the message will be sent to. - * - * @return string - */ - public function getDiscordChannel(): string - { - return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); - } } diff --git a/app/Events/Auth/User/UserDeleted.php b/app/Events/Auth/User/UserDeleted.php index b8a2795be..a178a6368 100644 --- a/app/Events/Auth/User/UserDeleted.php +++ b/app/Events/Auth/User/UserDeleted.php @@ -4,17 +4,14 @@ declare(strict_types=1); namespace App\Events\Auth\User; -use App\Constants\Config\ServiceConstants; -use App\Contracts\Events\DiscordMessageEvent; use App\Enums\Discord\EmbedColor; use Illuminate\Foundation\Events\Dispatchable; -use Illuminate\Support\Facades\Config; use NotificationChannels\Discord\DiscordMessage; /** * Class UserDeleted. */ -class UserDeleted extends UserEvent implements DiscordMessageEvent +class UserDeleted extends UserEvent { use Dispatchable; @@ -32,14 +29,4 @@ class UserDeleted extends UserEvent implements DiscordMessageEvent 'color' => EmbedColor::RED, ]); } - - /** - * Get Discord channel the message will be sent to. - * - * @return string - */ - public function getDiscordChannel(): string - { - return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); - } } diff --git a/app/Events/Auth/User/UserEvent.php b/app/Events/Auth/User/UserEvent.php index b9d90665a..0a19e03ee 100644 --- a/app/Events/Auth/User/UserEvent.php +++ b/app/Events/Auth/User/UserEvent.php @@ -4,12 +4,15 @@ declare(strict_types=1); namespace App\Events\Auth\User; +use App\Constants\Config\ServiceConstants; +use App\Contracts\Events\DiscordMessageEvent; use App\Models\Auth\User; +use Illuminate\Support\Facades\Config; /** * Class UserEvent. */ -abstract class UserEvent +abstract class UserEvent implements DiscordMessageEvent { /** * Create a new event instance. @@ -30,4 +33,24 @@ abstract class UserEvent { return $this->user; } + + /** + * Get Discord channel the message will be sent to. + * + * @return string + */ + public function getDiscordChannel(): string + { + return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); + } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } } diff --git a/app/Events/Auth/User/UserRestored.php b/app/Events/Auth/User/UserRestored.php index 53452516e..ff77dd9d4 100644 --- a/app/Events/Auth/User/UserRestored.php +++ b/app/Events/Auth/User/UserRestored.php @@ -4,18 +4,15 @@ declare(strict_types=1); namespace App\Events\Auth\User; -use App\Constants\Config\ServiceConstants; -use App\Contracts\Events\DiscordMessageEvent; use App\Enums\Discord\EmbedColor; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Config; use NotificationChannels\Discord\DiscordMessage; /** * Class UserRestored. */ -class UserRestored extends UserEvent implements DiscordMessageEvent +class UserRestored extends UserEvent { use Dispatchable; use SerializesModels; @@ -34,14 +31,4 @@ class UserRestored extends UserEvent implements DiscordMessageEvent 'color' => EmbedColor::GREEN, ]); } - - /** - * Get Discord channel the message will be sent to. - * - * @return string - */ - public function getDiscordChannel(): string - { - return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); - } } diff --git a/app/Events/Auth/User/UserUpdated.php b/app/Events/Auth/User/UserUpdated.php index 7f1866f0e..c0d521c6a 100644 --- a/app/Events/Auth/User/UserUpdated.php +++ b/app/Events/Auth/User/UserUpdated.php @@ -5,18 +5,15 @@ declare(strict_types=1); namespace App\Events\Auth\User; use App\Concerns\Discord\HasAttributeUpdateEmbedFields; -use App\Constants\Config\ServiceConstants; -use App\Contracts\Events\DiscordMessageEvent; use App\Enums\Discord\EmbedColor; use App\Models\Auth\User; use Illuminate\Foundation\Events\Dispatchable; -use Illuminate\Support\Facades\Config; use NotificationChannels\Discord\DiscordMessage; /** * Class UserUpdated. */ -class UserUpdated extends UserEvent implements DiscordMessageEvent +class UserUpdated extends UserEvent { use Dispatchable; use HasAttributeUpdateEmbedFields; @@ -48,14 +45,4 @@ class UserUpdated extends UserEvent implements DiscordMessageEvent 'color' => EmbedColor::YELLOW, ]); } - - /** - * Get Discord channel the message will be sent to. - * - * @return string - */ - public function getDiscordChannel(): string - { - return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); - } } diff --git a/app/Events/Base/Admin/AdminCreatedEvent.php b/app/Events/Base/Admin/AdminCreatedEvent.php index f661200dc..dce79ed20 100644 --- a/app/Events/Base/Admin/AdminCreatedEvent.php +++ b/app/Events/Base/Admin/AdminCreatedEvent.php @@ -26,4 +26,14 @@ abstract class AdminCreatedEvent extends BaseCreatedEvent { return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } } diff --git a/app/Events/Base/Admin/AdminDeletedEvent.php b/app/Events/Base/Admin/AdminDeletedEvent.php index 803f03a4a..f5d723a21 100644 --- a/app/Events/Base/Admin/AdminDeletedEvent.php +++ b/app/Events/Base/Admin/AdminDeletedEvent.php @@ -26,4 +26,14 @@ abstract class AdminDeletedEvent extends BaseDeletedEvent { return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } } diff --git a/app/Events/Base/Admin/AdminRestoredEvent.php b/app/Events/Base/Admin/AdminRestoredEvent.php index 036526b69..6b5d76862 100644 --- a/app/Events/Base/Admin/AdminRestoredEvent.php +++ b/app/Events/Base/Admin/AdminRestoredEvent.php @@ -26,4 +26,14 @@ abstract class AdminRestoredEvent extends BaseRestoredEvent { return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } } diff --git a/app/Events/Base/Admin/AdminUpdatedEvent.php b/app/Events/Base/Admin/AdminUpdatedEvent.php index 972eaee98..286093e2b 100644 --- a/app/Events/Base/Admin/AdminUpdatedEvent.php +++ b/app/Events/Base/Admin/AdminUpdatedEvent.php @@ -26,4 +26,14 @@ abstract class AdminUpdatedEvent extends BaseUpdatedEvent { return Config::get(ServiceConstants::ADMIN_DISCORD_CHANNEL_QUALIFIED); } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } } diff --git a/app/Events/Base/BaseCreatedEvent.php b/app/Events/Base/BaseCreatedEvent.php index edf5ac1d8..fe8f9b4a7 100644 --- a/app/Events/Base/BaseCreatedEvent.php +++ b/app/Events/Base/BaseCreatedEvent.php @@ -36,6 +36,16 @@ abstract class BaseCreatedEvent extends BaseEvent implements DiscordMessageEvent ]); } + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } + /** * Get the description for the Discord message payload. * diff --git a/app/Events/Base/BaseDeletedEvent.php b/app/Events/Base/BaseDeletedEvent.php index 7bd696fd5..cd03dab34 100644 --- a/app/Events/Base/BaseDeletedEvent.php +++ b/app/Events/Base/BaseDeletedEvent.php @@ -34,6 +34,16 @@ abstract class BaseDeletedEvent extends BaseEvent implements DiscordMessageEvent ]); } + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } + /** * Get the description for the Discord message payload. * diff --git a/app/Events/Base/BaseRestoredEvent.php b/app/Events/Base/BaseRestoredEvent.php index 9bc17c158..037fb0c59 100644 --- a/app/Events/Base/BaseRestoredEvent.php +++ b/app/Events/Base/BaseRestoredEvent.php @@ -36,6 +36,16 @@ abstract class BaseRestoredEvent extends BaseEvent implements DiscordMessageEven ]); } + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } + /** * Get the description for the Discord message payload. * diff --git a/app/Events/Base/BaseUpdatedEvent.php b/app/Events/Base/BaseUpdatedEvent.php index 9a0f0b13d..0d1905d96 100644 --- a/app/Events/Base/BaseUpdatedEvent.php +++ b/app/Events/Base/BaseUpdatedEvent.php @@ -37,6 +37,16 @@ abstract class BaseUpdatedEvent extends BaseEvent implements DiscordMessageEvent ]); } + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } + /** * Get the description for the Discord message payload. * diff --git a/app/Events/Base/Wiki/WikiDeletedEvent.php b/app/Events/Base/Wiki/WikiDeletedEvent.php index e49e386b8..7ab21be83 100644 --- a/app/Events/Base/Wiki/WikiDeletedEvent.php +++ b/app/Events/Base/Wiki/WikiDeletedEvent.php @@ -37,7 +37,7 @@ abstract class WikiDeletedEvent extends BaseDeletedEvent implements NovaNotifica * * @return bool */ - public function shouldSend(): bool + public function shouldSendNovaNotification(): bool { $model = $this->getModel(); @@ -49,13 +49,13 @@ abstract class WikiDeletedEvent extends BaseDeletedEvent implements NovaNotifica * * @return NovaNotification */ - public function getNotification(): NovaNotification + public function getNovaNotification(): NovaNotification { return NovaNotification::make() ->icon('flag') ->message($this->getNotificationMessage()) ->type(NovaNotification::INFO_TYPE) - ->url($this->getNotificationUrl()); + ->url($this->getNovaNotificationUrl()); } /** @@ -63,7 +63,7 @@ abstract class WikiDeletedEvent extends BaseDeletedEvent implements NovaNotifica * * @return Collection */ - public function getUsers(): Collection + public function getNovaNotificationRecipients(): Collection { return User::query() ->whereRelation(User::RELATION_ROLES, Role::ATTRIBUTE_NAME, 'Admin') @@ -82,5 +82,5 @@ abstract class WikiDeletedEvent extends BaseDeletedEvent implements NovaNotifica * * @return string */ - abstract protected function getNotificationUrl(): string; + abstract protected function getNovaNotificationUrl(): string; } diff --git a/app/Events/BasePivotEvent.php b/app/Events/BasePivotEvent.php index 3e9644563..d9e93c40c 100644 --- a/app/Events/BasePivotEvent.php +++ b/app/Events/BasePivotEvent.php @@ -57,6 +57,16 @@ abstract class BasePivotEvent implements DiscordMessageEvent return Config::get(ServiceConstants::DB_UPDATES_DISCORD_CHANNEL_QUALIFIED); } + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } + /** * Get the description for the Discord message payload. * diff --git a/app/Events/Document/Page/PageDeleted.php b/app/Events/Document/Page/PageDeleted.php index 8edc36a16..c4273fae5 100644 --- a/app/Events/Document/Page/PageDeleted.php +++ b/app/Events/Document/Page/PageDeleted.php @@ -60,7 +60,7 @@ class PageDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = PageResource::uriKey(); diff --git a/app/Events/Wiki/Anime/AnimeDeleted.php b/app/Events/Wiki/Anime/AnimeDeleted.php index 62b4f30b3..b1fb4b532 100644 --- a/app/Events/Wiki/Anime/AnimeDeleted.php +++ b/app/Events/Wiki/Anime/AnimeDeleted.php @@ -60,7 +60,7 @@ class AnimeDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = AnimeResource::uriKey(); diff --git a/app/Events/Wiki/Anime/Synonym/SynonymDeleted.php b/app/Events/Wiki/Anime/Synonym/SynonymDeleted.php index 7c3b598a9..d12a8d390 100644 --- a/app/Events/Wiki/Anime/Synonym/SynonymDeleted.php +++ b/app/Events/Wiki/Anime/Synonym/SynonymDeleted.php @@ -73,7 +73,7 @@ class SynonymDeleted extends WikiDeletedEvent implements UpdateRelatedIndicesEve * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = SynonymResource::uriKey(); diff --git a/app/Events/Wiki/Anime/Theme/Entry/EntryDeleted.php b/app/Events/Wiki/Anime/Theme/Entry/EntryDeleted.php index 04ab9193b..4b3e581e8 100644 --- a/app/Events/Wiki/Anime/Theme/Entry/EntryDeleted.php +++ b/app/Events/Wiki/Anime/Theme/Entry/EntryDeleted.php @@ -62,7 +62,7 @@ class EntryDeleted extends WikiDeletedEvent implements UpdateRelatedIndicesEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = EntryResource::uriKey(); diff --git a/app/Events/Wiki/Anime/Theme/ThemeDeleted.php b/app/Events/Wiki/Anime/Theme/ThemeDeleted.php index 4eeb413f5..8c79fc1c4 100644 --- a/app/Events/Wiki/Anime/Theme/ThemeDeleted.php +++ b/app/Events/Wiki/Anime/Theme/ThemeDeleted.php @@ -69,7 +69,7 @@ class ThemeDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = ThemeResource::uriKey(); diff --git a/app/Events/Wiki/Artist/ArtistDeleted.php b/app/Events/Wiki/Artist/ArtistDeleted.php index f099a1c62..9c76b7da2 100644 --- a/app/Events/Wiki/Artist/ArtistDeleted.php +++ b/app/Events/Wiki/Artist/ArtistDeleted.php @@ -60,7 +60,7 @@ class ArtistDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = ArtistResource::uriKey(); diff --git a/app/Events/Wiki/Audio/AudioDeleted.php b/app/Events/Wiki/Audio/AudioDeleted.php index c084f0a81..15888fdd9 100644 --- a/app/Events/Wiki/Audio/AudioDeleted.php +++ b/app/Events/Wiki/Audio/AudioDeleted.php @@ -60,7 +60,7 @@ class AudioDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = AudioResource::uriKey(); diff --git a/app/Events/Wiki/ExternalResource/ExternalResourceDeleted.php b/app/Events/Wiki/ExternalResource/ExternalResourceDeleted.php index 7b584dfa1..4d6f11aa2 100644 --- a/app/Events/Wiki/ExternalResource/ExternalResourceDeleted.php +++ b/app/Events/Wiki/ExternalResource/ExternalResourceDeleted.php @@ -60,7 +60,7 @@ class ExternalResourceDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = ExternalResourceResource::uriKey(); diff --git a/app/Events/Wiki/Image/ImageDeleted.php b/app/Events/Wiki/Image/ImageDeleted.php index bb4e5db54..5a943af0c 100644 --- a/app/Events/Wiki/Image/ImageDeleted.php +++ b/app/Events/Wiki/Image/ImageDeleted.php @@ -60,7 +60,7 @@ class ImageDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = ImageResource::uriKey(); diff --git a/app/Events/Wiki/Series/SeriesDeleted.php b/app/Events/Wiki/Series/SeriesDeleted.php index a5c4c7200..6080759ac 100644 --- a/app/Events/Wiki/Series/SeriesDeleted.php +++ b/app/Events/Wiki/Series/SeriesDeleted.php @@ -60,7 +60,7 @@ class SeriesDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = SeriesResource::uriKey(); diff --git a/app/Events/Wiki/Song/SongDeleted.php b/app/Events/Wiki/Song/SongDeleted.php index a204f9e98..f1e2888e9 100644 --- a/app/Events/Wiki/Song/SongDeleted.php +++ b/app/Events/Wiki/Song/SongDeleted.php @@ -65,7 +65,7 @@ class SongDeleted extends WikiDeletedEvent implements UpdateRelatedIndicesEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = SongResource::uriKey(); diff --git a/app/Events/Wiki/Studio/StudioDeleted.php b/app/Events/Wiki/Studio/StudioDeleted.php index 684d71a70..332017618 100644 --- a/app/Events/Wiki/Studio/StudioDeleted.php +++ b/app/Events/Wiki/Studio/StudioDeleted.php @@ -60,7 +60,7 @@ class StudioDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = StudioResource::uriKey(); diff --git a/app/Events/Wiki/Video/Script/VideoScriptDeleted.php b/app/Events/Wiki/Video/Script/VideoScriptDeleted.php index 717ffde59..169f55065 100644 --- a/app/Events/Wiki/Video/Script/VideoScriptDeleted.php +++ b/app/Events/Wiki/Video/Script/VideoScriptDeleted.php @@ -60,7 +60,7 @@ class VideoScriptDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = Script::uriKey(); diff --git a/app/Events/Wiki/Video/VideoDeleted.php b/app/Events/Wiki/Video/VideoDeleted.php index e61c13b15..b5ed8c3a4 100644 --- a/app/Events/Wiki/Video/VideoDeleted.php +++ b/app/Events/Wiki/Video/VideoDeleted.php @@ -60,7 +60,7 @@ class VideoDeleted extends WikiDeletedEvent * * @return string */ - protected function getNotificationUrl(): string + protected function getNovaNotificationUrl(): string { $uriKey = VideoResource::uriKey(); diff --git a/app/Features/AllowAudioStreams.php b/app/Features/AllowAudioStreams.php new file mode 100644 index 000000000..2bc7fbc66 --- /dev/null +++ b/app/Features/AllowAudioStreams.php @@ -0,0 +1,19 @@ +can(SpecialPermission::BYPASS_FEATURE_FLAGS))) { + return true; + } + + return Feature::for(null)->value(static::class); + } +} diff --git a/app/Features/AllowDumpDownloading.php b/app/Features/AllowDumpDownloading.php new file mode 100644 index 000000000..d904fd2eb --- /dev/null +++ b/app/Features/AllowDumpDownloading.php @@ -0,0 +1,19 @@ +can(SpecialPermission::BYPASS_FEATURE_FLAGS))) { + return true; + } + + return Feature::for(null)->value(static::class); + } +} diff --git a/app/Features/AllowPlaylistManagement.php b/app/Features/AllowPlaylistManagement.php new file mode 100644 index 000000000..09b7b21c8 --- /dev/null +++ b/app/Features/AllowPlaylistManagement.php @@ -0,0 +1,19 @@ +can(SpecialPermission::BYPASS_FEATURE_FLAGS))) { + return true; + } + + return Feature::for(null)->value(static::class); + } +} diff --git a/app/Features/AllowScriptDownloading.php b/app/Features/AllowScriptDownloading.php new file mode 100644 index 000000000..c552bed55 --- /dev/null +++ b/app/Features/AllowScriptDownloading.php @@ -0,0 +1,19 @@ +can(SpecialPermission::BYPASS_FEATURE_FLAGS))) { + return true; + } + + return Feature::for(null)->value(static::class); + } +} diff --git a/app/Features/AllowVideoStreams.php b/app/Features/AllowVideoStreams.php new file mode 100644 index 000000000..1c87bdbfc --- /dev/null +++ b/app/Features/AllowVideoStreams.php @@ -0,0 +1,19 @@ +can(SpecialPermission::BYPASS_FEATURE_FLAGS))) { + return true; + } + + return Feature::for(null)->value(static::class); + } +} diff --git a/app/Http/Api/Field/Admin/Feature/FeatureNameField.php b/app/Http/Api/Field/Admin/Feature/FeatureNameField.php new file mode 100644 index 000000000..20fa39b1f --- /dev/null +++ b/app/Http/Api/Field/Admin/Feature/FeatureNameField.php @@ -0,0 +1,25 @@ +validated()); + + $builder = Feature::query()->where(Feature::ATTRIBUTE_SCOPE, FeatureConstants::NULL_SCOPE); + + $features = $action->index($builder, $query, $request->schema()); + + return new FeatureCollection($features, $query); + } + + /** + * Display the specified resource. + * + * @param ShowRequest $request + * @param Feature $feature + * @param ShowAction $action + * @return FeatureResource + */ + public function show(ShowRequest $request, Feature $feature, ShowAction $action): FeatureResource + { + $query = new Query($request->validated()); + + $show = $action->show($feature, $query, $request->schema()); + + return new FeatureResource($show, $query); + } + + /** + * Update the specified resource. + * + * @param UpdateRequest $request + * @param Feature $feature + * @param UpdateAction $action + * @return FeatureResource + */ + public function update(UpdateRequest $request, Feature $feature, UpdateAction $action): FeatureResource + { + $updated = $action->update($feature, $request->validated()); + + return new FeatureResource($updated, new Query()); + } +} diff --git a/app/Http/Controllers/Api/Config/FlagsController.php b/app/Http/Controllers/Api/Config/FlagsController.php deleted file mode 100644 index 6c3f874e7..000000000 --- a/app/Http/Controllers/Api/Config/FlagsController.php +++ /dev/null @@ -1,42 +0,0 @@ -validated()); - - return new FlagsResource($query); - } - - /** - * Get the underlying schema. - * - * @return Schema - */ - public function schema(): Schema - { - return new FlagsSchema(); - } -} diff --git a/app/Http/Controllers/Api/List/Playlist/TrackController.php b/app/Http/Controllers/Api/List/Playlist/TrackController.php index d3cfb1e64..583658f1a 100644 --- a/app/Http/Controllers/Api/List/Playlist/TrackController.php +++ b/app/Http/Controllers/Api/List/Playlist/TrackController.php @@ -11,7 +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\Features\AllowPlaylistManagement; use App\Http\Api\Query\Query; use App\Http\Controllers\Api\BaseController; use App\Http\Middleware\Models\List\PlaylistExceedsTrackLimit; @@ -26,6 +26,7 @@ use App\Models\List\Playlist\PlaylistTrack; use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Support\Str; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; /** * Class TrackController. @@ -39,9 +40,9 @@ class TrackController extends BaseController { parent::__construct(PlaylistTrack::class, 'track,playlist'); - $isPlaylistManagementAllowed = Str::of('is_feature_enabled:') - ->append(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED) - ->append(',Playlist Management Disabled') + $isPlaylistManagementAllowed = Str::of(EnsureFeaturesAreActive::class) + ->append(':') + ->append(AllowPlaylistManagement::class) ->__toString(); $this->middleware($isPlaylistManagementAllowed)->except(['index', 'show']); diff --git a/app/Http/Controllers/Api/List/PlaylistController.php b/app/Http/Controllers/Api/List/PlaylistController.php index fca4ea9ce..492912ea6 100644 --- a/app/Http/Controllers/Api/List/PlaylistController.php +++ b/app/Http/Controllers/Api/List/PlaylistController.php @@ -11,8 +11,8 @@ 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\Features\AllowPlaylistManagement; use App\Http\Api\Query\Query; use App\Http\Controllers\Api\BaseController; use App\Http\Middleware\Models\List\UserExceedsPlaylistLimit; @@ -26,6 +26,7 @@ use App\Models\List\Playlist; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Str; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; /** * Class PlaylistController. @@ -39,9 +40,9 @@ class PlaylistController extends BaseController { parent::__construct(Playlist::class, 'playlist'); - $isPlaylistManagementAllowed = Str::of('is_feature_enabled:') - ->append(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED) - ->append(',Playlist Management Disabled') + $isPlaylistManagementAllowed = Str::of(EnsureFeaturesAreActive::class) + ->append(':') + ->append(AllowPlaylistManagement::class) ->__toString(); $this->middleware($isPlaylistManagementAllowed)->except(['index', 'show']); diff --git a/app/Http/Controllers/Api/Pivot/List/PlaylistImageController.php b/app/Http/Controllers/Api/Pivot/List/PlaylistImageController.php index 813316ece..fc8322044 100644 --- a/app/Http/Controllers/Api/Pivot/List/PlaylistImageController.php +++ b/app/Http/Controllers/Api/Pivot/List/PlaylistImageController.php @@ -8,8 +8,8 @@ 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\Features\AllowPlaylistManagement; use App\Http\Api\Query\Query; use App\Http\Controllers\Api\Pivot\PivotController; use App\Http\Requests\Api\IndexRequest; @@ -23,6 +23,7 @@ use App\Pivots\List\PlaylistImage; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\JsonResponse; use Illuminate\Support\Str; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; /** * Class PlaylistImageController. @@ -36,9 +37,9 @@ class PlaylistImageController extends PivotController { parent::__construct(Playlist::class, 'playlist', Image::class, 'image'); - $isPlaylistManagementAllowed = Str::of('is_feature_enabled:') - ->append(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED) - ->append(',Playlist Management Disabled') + $isPlaylistManagementAllowed = Str::of(EnsureFeaturesAreActive::class) + ->append(':') + ->append(AllowPlaylistManagement::class) ->__toString(); $this->middleware($isPlaylistManagementAllowed)->except(['index', 'show']); diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 555d220d7..2cd3cd2d3 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -7,7 +7,6 @@ namespace App\Http; use App\Http\Middleware\Api\SetAcceptJsonHeader; use App\Http\Middleware\Auth\Authenticate; use App\Http\Middleware\Auth\RedirectIfAuthenticated; -use App\Http\Middleware\IsFeatureEnabled; use App\Http\Middleware\LogRequest; use App\Http\Middleware\Models\RecordView; use App\Http\Middleware\ThrottleRequestsWithService; @@ -97,7 +96,6 @@ class Kernel extends HttpKernel 'cache.headers' => SetCacheHeaders::class, 'can' => Authorize::class, 'guest' => RedirectIfAuthenticated::class, - 'is_feature_enabled' => IsFeatureEnabled::class, 'password.confirm' => RequirePassword::class, 'record_view' => RecordView::class, 'signed' => ValidateSignature::class, diff --git a/app/Http/Middleware/IsFeatureEnabled.php b/app/Http/Middleware/IsFeatureEnabled.php deleted file mode 100644 index eb3f49f97..000000000 --- a/app/Http/Middleware/IsFeatureEnabled.php +++ /dev/null @@ -1,43 +0,0 @@ -user('sanctum'); - - if (! Config::bool($flag) && empty($user?->can(SpecialPermission::BYPASS_FEATURE_FLAGS))) { - abort(403, $message); - } - - return $next($request); - } -} diff --git a/app/Http/Middleware/Models/RecordView.php b/app/Http/Middleware/Models/RecordView.php index 7f5cbb316..847b4dbd2 100644 --- a/app/Http/Middleware/Models/RecordView.php +++ b/app/Http/Middleware/Models/RecordView.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace App\Http\Middleware\Models; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use Closure; use CyrildeWit\EloquentViewable\Contracts\Viewable; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Config; +use Laravel\Pennant\Feature; use RuntimeException; /** @@ -32,7 +32,7 @@ class RecordView throw new RuntimeException('record_view should only be configured for viewable models'); } - if (Config::bool(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED)) { + if (Feature::active(FeatureConstants::ALLOW_VIEW_RECORDING)) { views($model)->cooldown(now()->addMinutes(5))->record(); } diff --git a/app/Http/Resources/Admin/Collection/FeatureCollection.php b/app/Http/Resources/Admin/Collection/FeatureCollection.php new file mode 100644 index 000000000..2e1d240e9 --- /dev/null +++ b/app/Http/Resources/Admin/Collection/FeatureCollection.php @@ -0,0 +1,38 @@ +collection->map( + fn (Feature $feature) => new FeatureResource($feature, $this->query) + )->all(); + } +} diff --git a/app/Http/Resources/Admin/Resource/FeatureResource.php b/app/Http/Resources/Admin/Resource/FeatureResource.php new file mode 100644 index 000000000..1c8579a17 --- /dev/null +++ b/app/Http/Resources/Admin/Resource/FeatureResource.php @@ -0,0 +1,32 @@ +query->getFieldCriteria(static::$wrap); - - if ($criteria === null || $criteria->isAllowedField(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG)) { - $result[FlagConstants::ALLOW_VIDEO_STREAMS_FLAG] = Config::bool(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED); - } - - if ($criteria === null || $criteria->isAllowedField(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG)) { - $result[FlagConstants::ALLOW_AUDIO_STREAMS_FLAG] = Config::bool(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED); - } - - if ($criteria === null || $criteria->isAllowedField(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG)) { - $result[FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG] = Config::bool(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED); - } - - if ($criteria === null || $criteria->isAllowedField(FlagConstants::ALLOW_VIEW_RECORDING_FLAG)) { - $result[FlagConstants::ALLOW_VIEW_RECORDING_FLAG] = Config::bool(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED); - } - - if ($criteria === null || $criteria->isAllowedField(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG)) { - $result[FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG] = Config::bool(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED); - } - - if ($criteria === null || $criteria->isAllowedField(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG)) { - $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; - } -} diff --git a/app/Jobs/SendDiscordNotificationJob.php b/app/Jobs/SendDiscordNotificationJob.php index ae90fabdb..e733fdbed 100644 --- a/app/Jobs/SendDiscordNotificationJob.php +++ b/app/Jobs/SendDiscordNotificationJob.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace App\Jobs; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Contracts\Events\DiscordMessageEvent; use App\Jobs\Middleware\RateLimited; use App\Notifications\DiscordNotification; @@ -14,8 +14,8 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Notification; +use Laravel\Pennant\Feature; /** * Class SendDiscordNotification. @@ -44,7 +44,7 @@ class SendDiscordNotificationJob implements ShouldQueue */ public function handle(): void { - if (Config::bool(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED)) { + if (Feature::active(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS)) { Notification::route('discord', $this->event->getDiscordChannel()) ->notify(new DiscordNotification($this->event->getDiscordMessage())); } diff --git a/app/Listeners/NotifiesNovaUsers.php b/app/Listeners/NotifiesNovaUsers.php index e4dbbcd14..b0dbad941 100644 --- a/app/Listeners/NotifiesNovaUsers.php +++ b/app/Listeners/NotifiesNovaUsers.php @@ -23,9 +23,9 @@ class NotifiesNovaUsers implements ShouldQueue */ public function handle(NovaNotificationEvent $event): void { - if ($event->shouldSend()) { - $notification = $event->getNotification(); - foreach ($event->getUsers() as $user) { + if ($event->shouldSendNovaNotification()) { + $notification = $event->getNovaNotification(); + foreach ($event->getNovaNotificationRecipients() as $user) { $user->notify($notification); } } diff --git a/app/Listeners/SendDiscordNotification.php b/app/Listeners/SendDiscordNotification.php index 558545e00..0bca88935 100644 --- a/app/Listeners/SendDiscordNotification.php +++ b/app/Listeners/SendDiscordNotification.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace App\Listeners; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Contracts\Events\DiscordMessageEvent; use App\Jobs\SendDiscordNotificationJob; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Support\Facades\Config; +use Laravel\Pennant\Feature; /** * Class SendDiscordNotification. @@ -26,8 +26,19 @@ class SendDiscordNotification implements ShouldQueue */ public function handle(DiscordMessageEvent $event): void { - if (Config::bool(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED)) { + if (Feature::active(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS)) { SendDiscordNotificationJob::dispatch($event); } } + + /** + * Determine whether the listener should be queued. + * + * @param DiscordMessageEvent $event + * @return bool + */ + public function shouldQueue(DiscordMessageEvent $event): bool + { + return $event->shouldSendDiscordMessage(); + } } diff --git a/app/Models/Admin/Feature.php b/app/Models/Admin/Feature.php new file mode 100644 index 000000000..eb72fa322 --- /dev/null +++ b/app/Models/Admin/Feature.php @@ -0,0 +1,96 @@ + FeatureCreated::class, + 'deleted' => FeatureDeleted::class, + 'updated' => FeatureUpdated::class, + ]; + + /** + * The table associated with the model. + * + * @var string + */ + protected $table = Feature::TABLE; + + /** + * The primary key associated with the table. + * + * @var string + */ + protected $primaryKey = Feature::ATTRIBUTE_ID; + + /** + * Get name. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Determine if the feature scope is global. + * + * @return bool + */ + public function isNullScope(): bool + { + return $this->scope === FeatureConstants::NULL_SCOPE; + } +} diff --git a/app/Notifications/DiscordNotification.php b/app/Notifications/DiscordNotification.php index 959ee8d6d..e250f2291 100644 --- a/app/Notifications/DiscordNotification.php +++ b/app/Notifications/DiscordNotification.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace App\Notifications; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; -use Illuminate\Support\Facades\Config; +use Laravel\Pennant\Feature; use NotificationChannels\Discord\DiscordChannel; use NotificationChannels\Discord\DiscordMessage; @@ -66,6 +66,6 @@ class DiscordNotification extends Notification implements ShouldQueue */ public function shouldSend(mixed $notifiable, string $channel): bool { - return Config::bool(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED); + return Feature::active(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); } } diff --git a/app/Nova/Resources/Admin/Feature.php b/app/Nova/Resources/Admin/Feature.php new file mode 100644 index 000000000..97fa1625f --- /dev/null +++ b/app/Nova/Resources/Admin/Feature.php @@ -0,0 +1,140 @@ +sortable() + ->showOnPreview() + ->showWhenPeeking(), + + Text::make(__('nova.fields.feature.key.name'), FeatureModel::ATTRIBUTE_NAME) + ->sortable() + ->copyable() + ->readonly() + ->help(__('nova.fields.feature.key.help')) + ->showOnPreview() + ->filterable() + ->showWhenPeeking(), + + Text::make(__('nova.fields.feature.value.name'), FeatureModel::ATTRIBUTE_VALUE) + ->sortable() + ->copyable() + ->rules(['required', 'max:192']) + ->help(__('nova.fields.feature.value.help')) + ->showOnPreview() + ->filterable() + ->maxlength(192) + ->enforceMaxlength() + ->showWhenPeeking(), + ]; + } +} diff --git a/app/Policies/Admin/FeaturePolicy.php b/app/Policies/Admin/FeaturePolicy.php new file mode 100644 index 000000000..484f1bbd4 --- /dev/null +++ b/app/Policies/Admin/FeaturePolicy.php @@ -0,0 +1,81 @@ + $user !== null && $user->can(CrudPermission::VIEW()->format(Feature::class)), + fn (): bool => true + ); + } + + /** + * Determine whether the user can view the model. + * + * @param User|null $user + * @param Feature $feature + * @return bool + */ + public function view(?User $user, Feature $feature): bool + { + return Nova::whenServing( + fn (): bool => $user !== null && $user->can(CrudPermission::VIEW()->format(Feature::class)), + fn (): bool => $feature->isNullScope() + ); + } + + /** + * Determine whether the user can create models. + * + * @param User $user + * @return bool + */ + public function create(User $user): bool + { + return $user->can(CrudPermission::CREATE()->format(Feature::class)); + } + + /** + * Determine whether the user can update the model. + * + * @param User $user + * @return bool + */ + public function update(User $user): bool + { + return $user->can(CrudPermission::UPDATE()->format(Feature::class)); + } + + /** + * Determine whether the user can delete the model. + * + * @param User $user + * @return bool + */ + public function delete(User $user): bool + { + return $user->can(CrudPermission::DELETE()->format(Feature::class)); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ffd27e86f..9abfdf304 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,18 +4,12 @@ declare(strict_types=1); namespace App\Providers; -use App\Constants\Config\AudioConstants; -use App\Constants\Config\DumpConstants; -use App\Constants\Config\FlagConstants; -use App\Constants\Config\VideoConstants; -use App\Models\Wiki\Anime\Theme\AnimeThemeEntry; -use App\Models\Wiki\Video; -use Illuminate\Config\Repository; use Illuminate\Database\Eloquent\Model; -use Illuminate\Foundation\Console\AboutCommand; -use Illuminate\Support\Facades\Config; +use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; /** * Class AppServiceProvider. @@ -29,17 +23,12 @@ class AppServiceProvider extends ServiceProvider */ public function boot(): void { - Repository::macro('bool', function (string $key, bool $default = false): bool { - /** @var Repository $this */ - return filter_var($this->get($key, $default), FILTER_VALIDATE_BOOLEAN); - }); - Model::preventLazyLoading(); Model::handleLazyLoadingViolationUsing(function (Model $model, string $relation) { $class = get_class($model); - Log::error("Attempted to lazy load [$relation] on model [$class]"); + Log::error("Attempted to lazy load '$relation' on model '$class'"); }); Model::preventsAccessingMissingAttributes(); @@ -47,56 +36,9 @@ class AppServiceProvider extends ServiceProvider Model::handleMissingAttributeViolationUsing(function (Model $model, string $key) { $class = get_class($model); - Log::error("Attribute $key does not exist or was not retrieved for model [$class]"); + Log::error("Attribute '$key' does not exist or was not retrieved for model '$class'"); }); - AboutCommand::add('Audios', [ - 'Default Disk' => fn () => Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED), - 'Disks' => fn () => implode(',', Config::get(AudioConstants::DISKS_QUALIFIED)), - 'Nginx Redirect' => fn () => Config::get(AudioConstants::NGINX_REDIRECT_QUALIFIED), - 'Streaming Method' => fn () => Config::get(AudioConstants::STREAMING_METHOD_QUALIFIED), - ]); - - AboutCommand::add('Dumps', [ - 'Disk' => fn () => Config::get(DumpConstants::DISK_QUALIFIED), - ]); - - 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', - ]); - - AboutCommand::add('Images', [ - 'Disk' => fn () => Config::get('image.disk'), - ]); - - AboutCommand::add('Videos', [ - 'Default Disk' => fn () => Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED), - 'Disks' => fn () => implode(',', Config::get(VideoConstants::DISKS_QUALIFIED)), - 'Encoder Version' => fn () => Config::get(VideoConstants::ENCODER_VERSION_QUALIFIED), - 'Nginx Redirect' => fn () => Config::get(VideoConstants::NGINX_REDIRECT_QUALIFIED), - 'Script Disk' => fn () => Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED), - 'Streaming Method' => fn () => Config::get(VideoConstants::STREAMING_METHOD_QUALIFIED), - ]); - - AboutCommand::add('Wiki', [ - 'Featured Entry' => function () { - /** @var AnimeThemeEntry|null $entry */ - $entry = AnimeThemeEntry::query()->find(Config::get('wiki.featured_entry')); - - return $entry?->getName(); - }, - 'Featured Video' => function () { - /** @var Video|null $video */ - $video = Video::query()->find(Config::get('wiki.featured_video')); - - return $video?->getName(); - }, - ]); + EnsureFeaturesAreActive::whenInactive(fn (Request $request, array $features) => new Response(status: 403)); } } diff --git a/app/Rules/Wiki/Submission/Format/EncoderVersionFormatRule.php b/app/Rules/Wiki/Submission/Format/EncoderVersionFormatRule.php index 16ab91e29..7b955c4e9 100644 --- a/app/Rules/Wiki/Submission/Format/EncoderVersionFormatRule.php +++ b/app/Rules/Wiki/Submission/Format/EncoderVersionFormatRule.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace App\Rules\Wiki\Submission\Format; -use App\Constants\Config\VideoConstants; +use App\Constants\FeatureConstants; use App\Rules\Wiki\Submission\SubmissionRule; use Illuminate\Http\UploadedFile; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Config; +use Laravel\Pennant\Feature; /** * Class EncoderVersionFormatRule. @@ -28,7 +28,7 @@ class EncoderVersionFormatRule extends SubmissionRule $encoder = Arr::get($tags, 'encoder'); - return version_compare($encoder, Config::get(VideoConstants::ENCODER_VERSION_QUALIFIED), '>='); + return version_compare($encoder, Feature::value(FeatureConstants::REQUIRED_ENCODER_VERSION), '>='); } /** diff --git a/composer.json b/composer.json index 924245bb0..44fa9d16e 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,7 @@ "laravel/framework": "^10.7", "laravel/horizon": "^5.12", "laravel/nova": "^4.22.2", + "laravel/pennant": "^1.2", "laravel/sanctum": "^3.2", "laravel/scout": "^10.0", "laravel/telescope": "^4.12", diff --git a/composer.lock b/composer.lock index 9466c4958..e2cd31dbe 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ab2b43c9ac80ff850075f012223346d9", + "content-hash": "9c9bd83c569aefbc7ee1cbfe7186a0d1", "packages": [ { "name": "akaunting/laravel-setting", @@ -3502,6 +3502,82 @@ }, "time": "2023-04-07T18:14:13+00:00" }, + { + "name": "laravel/pennant", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/pennant.git", + "reference": "783ea43eaa51867247192b30505af0ef5f19ccf1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/pennant/zipball/783ea43eaa51867247192b30505af0ef5f19ccf1", + "reference": "783ea43eaa51867247192b30505af0ef5f19ccf1", + "shasum": "" + }, + "require": { + "illuminate/console": "^10.0", + "illuminate/container": "^10.0", + "illuminate/contracts": "^10.0", + "illuminate/database": "^10.0", + "illuminate/queue": "^10.0", + "illuminate/support": "^10.0", + "php": "^8.1", + "symfony/finder": "^6.0" + }, + "require-dev": { + "laravel/octane": "^1.4", + "orchestra/testbench": "^8.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Pennant\\PennantServiceProvider" + ], + "aliases": { + "Feature": "Laravel\\Pennant\\Feature" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Laravel\\Pennant\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "A simple, lightweight library for managing feature flags.", + "homepage": "https://github.com/laravel/pennant", + "keywords": [ + "feature", + "flags", + "laravel", + "pennant" + ], + "support": { + "issues": "https://github.com/laravel/pennant/issues", + "source": "https://github.com/laravel/pennant" + }, + "time": "2023-03-17T18:08:19+00:00" + }, { "name": "laravel/sanctum", "version": "v3.2.1", diff --git a/config/flags.php b/config/flags.php deleted file mode 100644 index 3430f32fc..000000000 --- a/config/flags.php +++ /dev/null @@ -1,98 +0,0 @@ - (bool) env('ALLOW_VIDEO_STREAMS', false), - - /* - |-------------------------------------------------------------------------- - | Allow Audio Streams - |-------------------------------------------------------------------------- - | - | When audio streams are allowed, requests to the audio.show route will - | stream audio. If disabled, requests to the audio.show route will - | raise a 403 Forbidden response. - | - */ - - 'allow_audio_streams' => (bool) env('ALLOW_AUDIO_STREAMS', false), - - /* - |-------------------------------------------------------------------------- - | Allow Discord Notifications - |-------------------------------------------------------------------------- - | - | When discord notifications are allowed, event listeners shall send discord - | notifications to the configured discord channel through the configured bot. - | If discord notifications are not allowed, event listeners shall not send - | discord notifications. - | - */ - - 'allow_discord_notifications' => (bool) env('ALLOW_DISCORD_NOTIFICATIONS', false), - - /* - |-------------------------------------------------------------------------- - | Allow View Recording - |-------------------------------------------------------------------------- - | - | When set to true, a view will be created for the viewable model in the show - | action of the resource controller. When set to false, a view will not be - | recorded. - | - */ - - 'allow_view_recording' => (bool) env('ALLOW_VIEW_RECORDING', false), - - /* - |-------------------------------------------------------------------------- - | Allow Dump Downloading - |-------------------------------------------------------------------------- - | - | When dump downloads are allowed, requests to the dump.show route will - | download dumps. If disabled, requests to the dump.show route will - | raise a 403 Forbidden response. - | - */ - - 'allow_dump_downloading' => (bool) env('ALLOW_DUMP_DOWNLOADING', false), - - /* - |-------------------------------------------------------------------------- - | Allow Script Downloading - |-------------------------------------------------------------------------- - | - | When script downloads are allowed, requests to the videoscript.show route will - | download scripts. If disabled, requests to the videoscript.show route will - | raise a 403 Forbidden response. - | - */ - - '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), -]; diff --git a/config/pennant.php b/config/pennant.php new file mode 100644 index 000000000..d03ebfb33 --- /dev/null +++ b/config/pennant.php @@ -0,0 +1,44 @@ + env('PENNANT_STORE', 'database'), + + /* + |-------------------------------------------------------------------------- + | Pennant Stores + |-------------------------------------------------------------------------- + | + | Here you may configure each of the stores that should be available to + | Pennant. These stores shall be used to store resolved feature flag + | values - you may configure as many as your application requires. + | + */ + + 'stores' => [ + + 'array' => [ + 'driver' => 'array', + ], + + 'database' => [ + 'driver' => 'database', + 'connection' => null, + 'table' => 'features', + ], + + ], +]; diff --git a/config/setting.php b/config/setting.php index 5094d57d6..4b46db164 100644 --- a/config/setting.php +++ b/config/setting.php @@ -2,8 +2,6 @@ declare(strict_types=1); -use App\Constants\Config\FlagConstants; -use App\Constants\Config\VideoConstants; use App\Constants\Config\WikiConstants; use App\Models\Admin\Setting; @@ -87,13 +85,6 @@ return [ | */ 'override' => [ - FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED => FlagConstants::ALLOW_AUDIO_STREAMS_FLAG, - FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED => FlagConstants::ALLOW_VIDEO_STREAMS_FLAG, - FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED => FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG, - FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED => FlagConstants::ALLOW_VIEW_RECORDING_FLAG, - FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED => FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG, - FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED => FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG, - VideoConstants::ENCODER_VERSION_QUALIFIED => VideoConstants::ENCODER_VERSION, WikiConstants::FEATURED_ENTRY_SETTING_QUALIFIED => WikiConstants::FEATURED_ENTRY_SETTING, WikiConstants::FEATURED_VIDEO_SETTING_QUALIFIED => WikiConstants::FEATURED_VIDEO_SETTING, ], diff --git a/config/video.php b/config/video.php index 175101228..659d973c8 100644 --- a/config/video.php +++ b/config/video.php @@ -54,19 +54,6 @@ return [ 'nginx_redirect' => env('VIDEO_NGINX_REDIRECT', '/video_redirect/'), - /* - |-------------------------------------------------------------------------- - | Video Uploading - |-------------------------------------------------------------------------- - | - | These values facilitate the validation and uploading of video in-system to object storage. - | For validation, we want to enforce that the latest FFmpeg version is used. - | We will use the libavformat version of the form "Lavf{major}.{minor}.{patch]". - | - */ - - 'encoder_version' => env('VIDEO_ENCODER_VERSION'), - /* |-------------------------------------------------------------------------- | Video Scripts diff --git a/database/factories/Admin/FeatureFactory.php b/database/factories/Admin/FeatureFactory.php new file mode 100644 index 000000000..6880bb4a1 --- /dev/null +++ b/database/factories/Admin/FeatureFactory.php @@ -0,0 +1,41 @@ + + */ +class FeatureFactory extends Factory +{ + /** + * The name of the factory's corresponding model. + * + * @var class-string + */ + protected $model = Feature::class; + + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + Feature::ATTRIBUTE_NAME => fake()->unique()->word(), + Feature::ATTRIBUTE_SCOPE => FeatureConstants::NULL_SCOPE, + Feature::ATTRIBUTE_VALUE => fake()->boolean(), + ]; + } +} diff --git a/database/migrations/2022_11_01_000001_create_features_table.php b/database/migrations/2022_11_01_000001_create_features_table.php new file mode 100644 index 000000000..58281cb57 --- /dev/null +++ b/database/migrations/2022_11_01_000001_create_features_table.php @@ -0,0 +1,39 @@ +id(Feature::ATTRIBUTE_ID); + $table->string(Feature::ATTRIBUTE_NAME); + $table->string(Feature::ATTRIBUTE_SCOPE); + $table->text(Feature::ATTRIBUTE_VALUE); + $table->timestamps(6); + + $table->unique([Feature::ATTRIBUTE_NAME, Feature::ATTRIBUTE_SCOPE]); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists(Feature::TABLE); + } +}; diff --git a/database/seeders/Admin/Feature/FeatureSeeder.php b/database/seeders/Admin/Feature/FeatureSeeder.php new file mode 100644 index 000000000..5a4d94da1 --- /dev/null +++ b/database/seeders/Admin/Feature/FeatureSeeder.php @@ -0,0 +1,38 @@ +firstOrCreate( - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_AUDIO_STREAMS_FLAG, - ], - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_AUDIO_STREAMS_FLAG, - Setting::ATTRIBUTE_VALUE => 'false', - ] - ); - - Setting::query()->firstOrCreate( - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_VIDEO_STREAMS_FLAG, - ], - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_VIDEO_STREAMS_FLAG, - Setting::ATTRIBUTE_VALUE => 'false', - ] - ); - - Setting::query()->firstOrCreate( - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG, - ], - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG, - Setting::ATTRIBUTE_VALUE => 'false', - ] - ); - - Setting::query()->firstOrCreate( - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_VIEW_RECORDING_FLAG, - ], - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_VIEW_RECORDING_FLAG, - Setting::ATTRIBUTE_VALUE => 'false', - ] - ); - - Setting::query()->firstOrCreate( - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG, - ], - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG, - Setting::ATTRIBUTE_VALUE => 'false', - ] - ); - - Setting::query()->firstOrCreate( - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG, - ], - [ - Setting::ATTRIBUTE_KEY => FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG, - Setting::ATTRIBUTE_VALUE => 'false', - ] - ); - - Setting::query()->firstOrCreate( - [ - Setting::ATTRIBUTE_KEY => VideoConstants::ENCODER_VERSION, - ], - [ - Setting::ATTRIBUTE_KEY => VideoConstants::ENCODER_VERSION, - Setting::ATTRIBUTE_VALUE => Config::get(VideoConstants::ENCODER_VERSION_QUALIFIED, ''), - ] - ); - Setting::query()->firstOrCreate( [ Setting::ATTRIBUTE_KEY => WikiConstants::FEATURED_ENTRY_SETTING, @@ -112,15 +40,5 @@ 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', - ] - ); } } diff --git a/database/seeders/Auth/Permission/PermissionSeeder.php b/database/seeders/Auth/Permission/PermissionSeeder.php index 19dec4525..e29faa324 100644 --- a/database/seeders/Auth/Permission/PermissionSeeder.php +++ b/database/seeders/Auth/Permission/PermissionSeeder.php @@ -9,6 +9,7 @@ use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\SpecialPermission; use App\Models\Admin\Announcement; use App\Models\Admin\Dump; +use App\Models\Admin\Feature; use App\Models\Admin\Setting; use App\Models\Auth\Permission; use App\Models\Auth\Role; @@ -49,6 +50,7 @@ class PermissionSeeder extends Seeder $this->registerResource(Announcement::class, ExtendedCrudPermission::getInstances()); $this->registerResource(Dump::class, ExtendedCrudPermission::getInstances()); $this->registerResource(Setting::class, CrudPermission::getInstances()); + $this->registerResource(Feature::class, CrudPermission::getInstances()); // Auth Resources $this->registerResource(Permission::class, [CrudPermission::VIEW()]); diff --git a/database/seeders/Auth/Role/AdminSeeder.php b/database/seeders/Auth/Role/AdminSeeder.php index 24468b28a..92ad3f149 100644 --- a/database/seeders/Auth/Role/AdminSeeder.php +++ b/database/seeders/Auth/Role/AdminSeeder.php @@ -9,6 +9,7 @@ use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\SpecialPermission; use App\Models\Admin\Announcement; use App\Models\Admin\Dump; +use App\Models\Admin\Feature; use App\Models\Admin\Setting; use App\Models\Auth\Permission; use App\Models\Auth\Role; @@ -50,6 +51,7 @@ class AdminSeeder extends RoleSeeder // Admin Resources $this->configureResource($role, Announcement::class, ExtendedCrudPermission::getInstances()); $this->configureResource($role, Dump::class, ExtendedCrudPermission::getInstances()); + $this->configureResource($role, Feature::class, [CrudPermission::VIEW(), CrudPermission::UPDATE()]); $this->configureResource($role, Setting::class, CrudPermission::getInstances()); // Auth Resources diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 57b6a88ae..95457b19a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Database\Seeders; +use Database\Seeders\Admin\Feature\FeatureSeeder; use Database\Seeders\Auth\Permission\PermissionSeeder; use Database\Seeders\Auth\Role\RoleSeeder; use Database\Seeders\Billing\Transaction\DigitalOceanTransactionSeeder; @@ -29,5 +30,6 @@ class DatabaseSeeder extends Seeder $this->call(VideoSeeder::class); $this->call(AudioSeeder::class); $this->call(HashidsSeeder::class); + $this->call(FeatureSeeder::class); } } diff --git a/lang/en/nova.php b/lang/en/nova.php index 5020bdbf2..c53479e0b 100644 --- a/lang/en/nova.php +++ b/lang/en/nova.php @@ -492,6 +492,16 @@ return [ 'name' => 'Site', ], ], + 'feature' => [ + 'key' => [ + 'help' => 'The name of the feature. Class strings label features that require business logic to resolve. Otherwise, this is global value.', + 'name' => 'Key', + ], + 'value' => [ + 'help' => 'Binary state features should be true or false. Rich Feature values can be any string.', + 'name' => 'Value', + ], + ], 'image' => [ 'facet' => [ 'help' => 'The page component that the image is intended for. Example: Is this a small cover image or a large cover image?', @@ -801,6 +811,7 @@ return [ 'balances' => 'Balances', 'dumps' => 'Dumps', 'external_resources' => 'External Resources', + 'features' => 'Features', 'groups' => 'Groups', 'images' => 'Images', 'members' => 'Members', @@ -829,6 +840,7 @@ return [ 'balance' => 'Balance', 'dump' => 'Dump', 'external_resource' => 'External Resource', + 'feature' => 'Feature', 'image' => 'Image', 'page' => 'Page', 'permission' => 'Permission', diff --git a/routes/api.php b/routes/api.php index 939ef5305..15cf71589 100644 --- a/routes/api.php +++ b/routes/api.php @@ -4,12 +4,12 @@ declare(strict_types=1); use App\Http\Controllers\Api\Admin\AnnouncementController; use App\Http\Controllers\Api\Admin\DumpController; +use App\Http\Controllers\Api\Admin\FeatureController; use App\Http\Controllers\Api\Auth\User\Me\List\MyPlaylistController; use App\Http\Controllers\Api\Auth\User\Me\MyController; use App\Http\Controllers\Api\Billing\BalanceController; use App\Http\Controllers\Api\Billing\TransactionController; use App\Http\Controllers\Api\Billing\TransparencyController; -use App\Http\Controllers\Api\Config\FlagsController; use App\Http\Controllers\Api\Config\WikiController; use App\Http\Controllers\Api\Document\PageController; use App\Http\Controllers\Api\List\Playlist\TrackBackwardController; @@ -222,6 +222,8 @@ if (! function_exists('apiPivotResourceUri')) { // Admin Routes apiResource('announcement', AnnouncementController::class); apiResource('dump', DumpController::class); +Route::apiResource('feature', FeatureController::class) + ->only(['index', 'show', 'update']); // Auth Routes Route::get('/me', [MyController::class, 'show'])->name('me.show'); @@ -233,7 +235,6 @@ apiResource('transaction', TransactionController::class); Route::get('transparency', [TransparencyController::class, 'show'])->name('transparency.show'); // Config Routes -Route::get('config/flags', [FlagsController::class, 'show'])->name('config.flags.show'); Route::get('config/wiki', [WikiController::class, 'show'])->name('config.wiki.show'); // Document Routes diff --git a/routes/audio.php b/routes/audio.php index fa83f7b72..581524566 100644 --- a/routes/audio.php +++ b/routes/audio.php @@ -2,14 +2,15 @@ declare(strict_types=1); -use App\Constants\Config\FlagConstants; +use App\Features\AllowAudioStreams; use App\Http\Controllers\Wiki\Audio\AudioController; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; -$isAudioStreamingAllowed = Str::of('is_feature_enabled:') - ->append(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED) - ->append(',Audio Streaming Disabled') +$isAudioStreamingAllowed = Str::of(EnsureFeaturesAreActive::class) + ->append(':') + ->append(AllowAudioStreams::class) ->__toString(); Route::get('/{audio}', [AudioController::class, 'show']) diff --git a/routes/dump.php b/routes/dump.php index 707aba867..a550467e5 100644 --- a/routes/dump.php +++ b/routes/dump.php @@ -2,16 +2,17 @@ declare(strict_types=1); -use App\Constants\Config\FlagConstants; +use App\Features\AllowDumpDownloading; use App\Http\Controllers\Admin\DumpController; use App\Http\Controllers\Admin\LatestDocumentDumpController; use App\Http\Controllers\Admin\LatestWikiDumpController; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; -$isDumpDownloadingAllowed = Str::of('is_feature_enabled:') - ->append(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED) - ->append(',Dump Downloading Disabled') +$isDumpDownloadingAllowed = Str::of(EnsureFeaturesAreActive::class) + ->append(':') + ->append(AllowDumpDownloading::class) ->__toString(); Route::get('/latest/document', [LatestDocumentDumpController::class, 'show']) diff --git a/routes/script.php b/routes/script.php index ef98acd73..fded078d9 100644 --- a/routes/script.php +++ b/routes/script.php @@ -2,14 +2,15 @@ declare(strict_types=1); -use App\Constants\Config\FlagConstants; +use App\Features\AllowScriptDownloading; use App\Http\Controllers\Wiki\Video\Script\ScriptController; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; -$isScriptDownloadingAllowed = Str::of('is_feature_enabled:') - ->append(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED) - ->append(',Script Downloading Disabled') +$isScriptDownloadingAllowed = Str::of(EnsureFeaturesAreActive::class) + ->append(':') + ->append(AllowScriptDownloading::class) ->__toString(); Route::get('/{videoscript}', [ScriptController::class, 'show']) diff --git a/routes/video.php b/routes/video.php index 12d3e2659..ef5cdd3e8 100644 --- a/routes/video.php +++ b/routes/video.php @@ -2,14 +2,15 @@ declare(strict_types=1); -use App\Constants\Config\FlagConstants; +use App\Features\AllowVideoStreams; use App\Http\Controllers\Wiki\Video\VideoController; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; +use Laravel\Pennant\Middleware\EnsureFeaturesAreActive; -$isVideoStreamingAllowed = Str::of('is_feature_enabled:') - ->append(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED) - ->append(',Video Streaming Disabled') +$isVideoStreamingAllowed = Str::of(EnsureFeaturesAreActive::class) + ->append(':') + ->append(AllowVideoStreams::class) ->__toString(); Route::get('/{video}', [VideoController::class, 'show']) diff --git a/tests/Feature/Events/Admin/FeatureTest.php b/tests/Feature/Events/Admin/FeatureTest.php new file mode 100644 index 000000000..0d89fcbc9 --- /dev/null +++ b/tests/Feature/Events/Admin/FeatureTest.php @@ -0,0 +1,81 @@ +create(); + + Event::assertDispatched(FeatureCreated::class); + } + + /** + * When a Feature is deleted, a FeatureDeleted event shall be dispatched. + * + * @return void + */ + public function testFeatureDeletedEventDispatched(): void + { + $feature = Feature::factory()->create(); + + $feature->delete(); + + Event::assertDispatched(FeatureDeleted::class); + } + + /** + * When a Feature is updated, a FeatureUpdated event shall be dispatched. + * + * @return void + */ + public function testFeatureUpdatedEventDispatched(): void + { + $feature = Feature::factory()->createOne(); + + $feature->update([ + Feature::ATTRIBUTE_VALUE => ! $feature->value, + ]); + + Event::assertDispatched(FeatureUpdated::class); + } + + /** + * The FeatureUpdated event shall contain embed fields. + * + * @return void + */ + public function testFeatureUpdatedEventEmbedFields(): void + { + $feature = Feature::factory()->createOne(); + + $feature->update([ + Feature::ATTRIBUTE_VALUE => ! $feature->value, + ]); + + Event::assertDispatched(FeatureUpdated::class, function (FeatureUpdated $event) { + $message = $event->getDiscordMessage(); + + return ! empty(Arr::get($message->embed, 'fields')); + }); + } +} diff --git a/tests/Feature/Http/Admin/DumpTest.php b/tests/Feature/Http/Admin/DumpTest.php index 3edc2b688..2737b9169 100644 --- a/tests/Feature/Http/Admin/DumpTest.php +++ b/tests/Feature/Http/Admin/DumpTest.php @@ -5,14 +5,15 @@ declare(strict_types=1); namespace Tests\Feature\Http\Admin; use App\Constants\Config\DumpConstants; -use App\Constants\Config\FlagConstants; use App\Enums\Auth\SpecialPermission; +use App\Features\AllowDumpDownloading; use App\Models\Admin\Dump; use App\Models\Auth\User; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\Testing\File; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -24,14 +25,14 @@ class DumpTest extends TestCase use WithFaker; /** - * If dump downloading is disabled through the 'flags.allow_dump_downloading' property, + * If dump downloading is disabled through the Allow Dump Downloading feature, * the user shall receive a forbidden exception. * * @return void */ public function testDumpDownloadingNotAllowedForbidden(): void { - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, false); + Feature::deactivate(AllowDumpDownloading::class); $dump = Dump::factory()->createOne(); @@ -42,13 +43,13 @@ class DumpTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to download dumps - * even if the 'flags.allow_dump_downloading' property is disabled. + * even if the Allow Dump Downloading feature is disabled. * * @return void */ public function testVideoStreamingPermittedForBypass(): void { - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowDumpDownloading::class, $this->faker->boolean()); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.sql'); @@ -74,7 +75,7 @@ class DumpTest extends TestCase */ public function testCannotDownloadSoftDeletedDump(): void { - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); $dump = Dump::factory()->createOne(); @@ -92,7 +93,7 @@ class DumpTest extends TestCase */ public function testDownloadedThroughResponse(): void { - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.sql'); diff --git a/tests/Feature/Http/Admin/LatestDocumentDumpTest.php b/tests/Feature/Http/Admin/LatestDocumentDumpTest.php index f97e0d449..f92901cd8 100644 --- a/tests/Feature/Http/Admin/LatestDocumentDumpTest.php +++ b/tests/Feature/Http/Admin/LatestDocumentDumpTest.php @@ -7,8 +7,8 @@ namespace Tests\Feature\Http\Admin; use App\Actions\Storage\Admin\Dump\DumpDocumentAction; use App\Actions\Storage\Admin\Dump\DumpWikiAction; use App\Constants\Config\DumpConstants; -use App\Constants\Config\FlagConstants; use App\Enums\Auth\SpecialPermission; +use App\Features\AllowDumpDownloading; use App\Models\Admin\Dump; use App\Models\Auth\User; use Exception; @@ -18,6 +18,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -29,7 +30,7 @@ class LatestDocumentDumpTest extends TestCase use WithFaker; /** - * If dump downloading is disabled through the 'flags.allow_dump_downloading' property, + * If dump downloading is disabled through the Allow Dump Downloading feature, * the user shall receive a forbidden exception. * * @return void @@ -41,7 +42,7 @@ class LatestDocumentDumpTest extends TestCase Storage::fake('local'); Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, false); + Feature::deactivate(AllowDumpDownloading::class); $action = new DumpWikiAction(); @@ -54,7 +55,7 @@ class LatestDocumentDumpTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to download the latest document dump - * even if the 'flags.allow_dump_downloading' property is disabled. + * even if the Allow Dump Downloading feature is disabled. * * @return void */ @@ -63,7 +64,7 @@ class LatestDocumentDumpTest extends TestCase Storage::fake('local'); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowDumpDownloading::class, $this->faker->boolean()); Collection::times($this->faker->randomDigitNotNull(), function () { $action = new DumpWikiAction(); @@ -108,7 +109,7 @@ class LatestDocumentDumpTest extends TestCase Storage::fake('local'); Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); $response = $this->get(route('dump.latest.document.show')); @@ -125,7 +126,7 @@ class LatestDocumentDumpTest extends TestCase Storage::fake('local'); Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); Collection::times($this->faker->randomDigitNotNull(), function () { $action = new DumpWikiAction(); @@ -148,7 +149,7 @@ class LatestDocumentDumpTest extends TestCase Storage::fake('local'); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); Collection::times($this->faker->randomDigitNotNull(), function () { $action = new DumpWikiAction(); diff --git a/tests/Feature/Http/Admin/LatestWikiDumpTest.php b/tests/Feature/Http/Admin/LatestWikiDumpTest.php index 720ea3aaa..665b974b4 100644 --- a/tests/Feature/Http/Admin/LatestWikiDumpTest.php +++ b/tests/Feature/Http/Admin/LatestWikiDumpTest.php @@ -7,8 +7,8 @@ namespace Tests\Feature\Http\Admin; use App\Actions\Storage\Admin\Dump\DumpDocumentAction; use App\Actions\Storage\Admin\Dump\DumpWikiAction; use App\Constants\Config\DumpConstants; -use App\Constants\Config\FlagConstants; use App\Enums\Auth\SpecialPermission; +use App\Features\AllowDumpDownloading; use App\Models\Admin\Dump; use App\Models\Auth\User; use Exception; @@ -18,6 +18,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -29,7 +30,7 @@ class LatestWikiDumpTest extends TestCase use WithFaker; /** - * If dump downloading is disabled through the 'flags.allow_dump_downloading' property, + * If dump downloading is disabled through the Allow Dump Downloading feature, * the user shall receive a forbidden exception. * * @return void @@ -41,7 +42,7 @@ class LatestWikiDumpTest extends TestCase Storage::fake('local'); Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, false); + Feature::deactivate(AllowDumpDownloading::class); $action = new DumpWikiAction(); @@ -54,7 +55,7 @@ class LatestWikiDumpTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to download the latest wiki dump - * even if the 'flags.allow_dump_downloading' property is disabled. + * even if the Allow Dump Downloading feature is disabled. * * @return void */ @@ -63,7 +64,7 @@ class LatestWikiDumpTest extends TestCase Storage::fake('local'); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowDumpDownloading::class, $this->faker->boolean()); Collection::times($this->faker->randomDigitNotNull(), function () { $action = new DumpDocumentAction(); @@ -108,7 +109,7 @@ class LatestWikiDumpTest extends TestCase Storage::fake('local'); Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); $response = $this->get(route('dump.latest.wiki.show')); @@ -125,7 +126,7 @@ class LatestWikiDumpTest extends TestCase Storage::fake('local'); Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); Collection::times($this->faker->randomDigitNotNull(), function () { $action = new DumpDocumentAction(); @@ -148,7 +149,7 @@ class LatestWikiDumpTest extends TestCase Storage::fake('local'); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowDumpDownloading::class); Collection::times($this->faker->randomDigitNotNull(), function () { $action = new DumpDocumentAction(); diff --git a/tests/Feature/Http/Api/Admin/Feature/FeatureIndexTest.php b/tests/Feature/Http/Api/Admin/Feature/FeatureIndexTest.php new file mode 100644 index 000000000..a323947eb --- /dev/null +++ b/tests/Feature/Http/Api/Admin/Feature/FeatureIndexTest.php @@ -0,0 +1,272 @@ +count($this->faker->randomDigitNotNull())->create(); + + $response = $this->get(route('api.feature.index')); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureCollection($features, new Query())) + ->response() + ->getData() + ), + true + ) + ); + } + + /** + * The Feature Show Endpoint shall list features of nonnull scope. + * + * @return void + */ + public function testNonNullForbidden(): void + { + $nullScopeCount = $this->faker->randomDigitNotNull(); + + $features = Feature::factory() + ->count($nullScopeCount) + ->create(); + + Collection::times($this->faker->randomDigitNotNull(), function () { + Feature::factory()->create([ + Feature::ATTRIBUTE_SCOPE => $this->faker->word(), + ]); + }); + + $response = $this->get(route('api.feature.index')); + + $response->assertJsonCount($nullScopeCount, FeatureCollection::$wrap); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureCollection($features, new Query())) + ->response() + ->getData() + ), + true + ) + ); + } + + /** + * The Feature Index Endpoint shall be paginated. + * + * @return void + */ + public function testPaginated(): void + { + Feature::factory()->count($this->faker->randomDigitNotNull())->create(); + + $response = $this->get(route('api.feature.index')); + + $response->assertJsonStructure([ + FeatureCollection::$wrap, + 'links', + 'meta', + ]); + } + + /** + * The Feature Index Endpoint shall implement sparse fieldsets. + * + * @return void + */ + public function testSparseFieldsets(): void + { + $schema = new FeatureSchema(); + + $fields = collect($schema->fields()); + + $includedFields = $fields->random($this->faker->numberBetween(1, $fields->count())); + + $parameters = [ + FieldParser::param() => [ + FeatureResource::$wrap => $includedFields->map(fn (Field $field) => $field->getKey())->join(','), + ], + ]; + + $features = Feature::factory()->count($this->faker->randomDigitNotNull())->create(); + + $response = $this->get(route('api.feature.index', $parameters)); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureCollection($features, new Query($parameters))) + ->response() + ->getData() + ), + true + ) + ); + } + + /** + * The Feature Index Endpoint shall support sorting resources. + * + * @return void + */ + public function testSorts(): void + { + $schema = new FeatureSchema(); + + /** @var Sort $sort */ + $sort = collect($schema->fields()) + ->filter(fn (Field $field) => $field instanceof SortableField) + ->map(fn (SortableField $field) => $field->getSort()) + ->random(); + + $parameters = [ + SortParser::param() => $sort->format(Direction::getRandomInstance()), + ]; + + $query = new Query($parameters); + + Feature::factory()->count($this->faker->randomDigitNotNull())->create(); + + $response = $this->get(route('api.feature.index', $parameters)); + + $features = $this->sort(Feature::query(), $query, $schema)->get(); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureCollection($features, $query)) + ->response() + ->getData() + ), + true + ) + ); + } + + /** + * The Feature Index Endpoint shall support filtering by created_at. + * + * @return void + */ + public function testCreatedAtFilter(): void + { + $createdFilter = $this->faker->date(); + $excludedDate = $this->faker->date(); + + $parameters = [ + FilterParser::param() => [ + BaseModel::ATTRIBUTE_CREATED_AT => $createdFilter, + ], + PagingParser::param() => [ + OffsetCriteria::SIZE_PARAM => Criteria::MAX_RESULTS, + ], + ]; + + Carbon::withTestNow($createdFilter, function () { + Feature::factory()->count($this->faker->randomDigitNotNull())->create(); + }); + + Carbon::withTestNow($excludedDate, function () { + Feature::factory()->count($this->faker->randomDigitNotNull())->create(); + }); + + $feature = Feature::query()->where(BaseModel::ATTRIBUTE_CREATED_AT, $createdFilter)->get(); + + $response = $this->get(route('api.feature.index', $parameters)); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureCollection($feature, new Query($parameters))) + ->response() + ->getData() + ), + true + ) + ); + } + + /** + * The Feature Index Endpoint shall support filtering by updated_at. + * + * @return void + */ + public function testUpdatedAtFilter(): void + { + $updatedFilter = $this->faker->date(); + $excludedDate = $this->faker->date(); + + $parameters = [ + FilterParser::param() => [ + BaseModel::ATTRIBUTE_UPDATED_AT => $updatedFilter, + ], + PagingParser::param() => [ + OffsetCriteria::SIZE_PARAM => Criteria::MAX_RESULTS, + ], + ]; + + Carbon::withTestNow($updatedFilter, function () { + Feature::factory()->count($this->faker->randomDigitNotNull())->create(); + }); + + Carbon::withTestNow($excludedDate, function () { + Feature::factory()->count($this->faker->randomDigitNotNull())->create(); + }); + + $feature = Feature::query()->where(BaseModel::ATTRIBUTE_UPDATED_AT, $updatedFilter)->get(); + + $response = $this->get(route('api.feature.index', $parameters)); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureCollection($feature, new Query($parameters))) + ->response() + ->getData() + ), + true + ) + ); + } +} diff --git a/tests/Feature/Http/Api/Admin/Feature/FeatureShowTest.php b/tests/Feature/Http/Api/Admin/Feature/FeatureShowTest.php new file mode 100644 index 000000000..d42f50bdf --- /dev/null +++ b/tests/Feature/Http/Api/Admin/Feature/FeatureShowTest.php @@ -0,0 +1,96 @@ +create(); + + $response = $this->get(route('api.feature.show', ['feature' => $feature])); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureResource($feature, new Query())) + ->response() + ->getData() + ), + true + ) + ); + } + + /** + * The Feature Show Endpoint shall forbid showing features of nonnull scope. + * + * @return void + */ + public function testNonNullForbidden(): void + { + $feature = Feature::factory()->create([ + Feature::ATTRIBUTE_SCOPE => $this->faker->word(), + ]); + + $response = $this->get(route('api.feature.show', ['feature' => $feature])); + + $response->assertForbidden(); + } + + /** + * The Feature Show Endpoint shall implement sparse fieldsets. + * + * @return void + */ + public function testSparseFieldsets(): void + { + $schema = new FeatureSchema(); + + $fields = collect($schema->fields()); + + $includedFields = $fields->random($this->faker->numberBetween(1, $fields->count())); + + $parameters = [ + FieldParser::param() => [ + FeatureResource::$wrap => $includedFields->map(fn (Field $field) => $field->getKey())->join(','), + ], + ]; + + $feature = Feature::factory()->create(); + + $response = $this->get(route('api.feature.show', ['feature' => $feature] + $parameters)); + + $response->assertJson( + json_decode( + json_encode( + (new FeatureResource($feature, new Query($parameters))) + ->response() + ->getData() + ), + true + ) + ); + } +} diff --git a/tests/Feature/Http/Api/Admin/Feature/FeatureUpdateTest.php b/tests/Feature/Http/Api/Admin/Feature/FeatureUpdateTest.php new file mode 100644 index 000000000..0a5642fe2 --- /dev/null +++ b/tests/Feature/Http/Api/Admin/Feature/FeatureUpdateTest.php @@ -0,0 +1,79 @@ +createOne(); + + $parameters = [ + Feature::ATTRIBUTE_VALUE => ! $feature->value, + ]; + + $response = $this->put(route('api.feature.update', ['feature' => $feature] + $parameters)); + + $response->assertUnauthorized(); + } + + /** + * The Feature Update Endpoint shall forbid users without the update feature permission. + * + * @return void + */ + public function testForbidden(): void + { + $feature = Feature::factory()->createOne(); + + $parameters = [ + Feature::ATTRIBUTE_VALUE => ! $feature->value, + ]; + + $user = User::factory()->createOne(); + + Sanctum::actingAs($user); + + $response = $this->put(route('api.feature.update', ['feature' => $feature] + $parameters)); + + $response->assertForbidden(); + } + + /** + * The Feature Update Endpoint shall update a feature. + * + * @return void + */ + public function testUpdate(): void + { + $feature = Feature::factory()->createOne(); + + $parameters = [ + Feature::ATTRIBUTE_VALUE => ! $feature->value, + ]; + + $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Feature::class))->createOne(); + + Sanctum::actingAs($user); + + $response = $this->put(route('api.feature.update', ['feature' => $feature] + $parameters)); + + $response->assertOk(); + } +} diff --git a/tests/Feature/Http/Api/Config/FlagsShowTest.php b/tests/Feature/Http/Api/Config/FlagsShowTest.php deleted file mode 100644 index aa5a5535f..000000000 --- a/tests/Feature/Http/Api/Config/FlagsShowTest.php +++ /dev/null @@ -1,85 +0,0 @@ -faker->boolean()); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, $this->faker->boolean()); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, $this->faker->boolean()); - - $response = $this->get(route('api.config.flags.show')); - - $response->assertJson( - json_decode( - json_encode( - (new FlagsResource(new Query())) - ->response() - ->getData() - ), - true - ) - ); - } - - /** - * The Flags Show Endpoint shall implement sparse fieldsets. - * - * @return void - */ - public function testSparseFieldsets(): void - { - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, $this->faker->boolean()); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, $this->faker->boolean()); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, $this->faker->boolean()); - - $schema = new FlagsSchema(); - - $fields = collect($schema->fields()); - - $includedFields = $fields->random($this->faker->numberBetween(1, $fields->count())); - - $parameters = [ - FieldParser::param() => [ - FlagsResource::$wrap => $includedFields->map(fn (Field $field) => $field->getKey())->join(','), - ], - ]; - - $response = $this->get(route('api.config.flags.show', $parameters)); - - $response->assertJson( - json_decode( - json_encode( - (new FlagsResource(new Query($parameters))) - ->response() - ->getData() - ), - true - ) - ); - } -} diff --git a/tests/Feature/Http/Api/Config/WikiShowTest.php b/tests/Feature/Http/Api/Config/WikiShowTest.php index 157086d9d..8fbe95614 100644 --- a/tests/Feature/Http/Api/Config/WikiShowTest.php +++ b/tests/Feature/Http/Api/Config/WikiShowTest.php @@ -27,7 +27,7 @@ class WikiShowTest extends TestCase use WithFaker; /** - * By default, the Wiki Show Endpoint shall return a Flags Resource. + * By default, the Wiki Show Endpoint shall return a Wiki Resource. * * @return void */ diff --git a/tests/Feature/Http/Api/List/Playlist/PlaylistDestroyTest.php b/tests/Feature/Http/Api/List/Playlist/PlaylistDestroyTest.php index 8fabffa0d..adc428a74 100644 --- a/tests/Feature/Http/Api/List/Playlist/PlaylistDestroyTest.php +++ b/tests/Feature/Http/Api/List/Playlist/PlaylistDestroyTest.php @@ -4,15 +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\Events\List\Playlist\PlaylistCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -32,7 +32,7 @@ class PlaylistDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -50,7 +50,7 @@ class PlaylistDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -72,7 +72,7 @@ class PlaylistDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory() ->for(User::factory()) @@ -89,7 +89,7 @@ class PlaylistDestroyTest extends TestCase /** * The Playlist Destroy Endpoint shall forbid users from destroying playlists - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -97,7 +97,7 @@ class PlaylistDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Playlist::class))->createOne(); @@ -121,7 +121,7 @@ class PlaylistDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Playlist::class))->createOne(); @@ -147,7 +147,7 @@ class PlaylistDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(Playlist::class))->createOne(); @@ -165,7 +165,7 @@ class PlaylistDestroyTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to destroy playlists - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -173,7 +173,7 @@ class PlaylistDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( diff --git a/tests/Feature/Http/Api/List/Playlist/PlaylistForceDeleteTest.php b/tests/Feature/Http/Api/List/Playlist/PlaylistForceDeleteTest.php index c1a153e4d..003f60e38 100644 --- a/tests/Feature/Http/Api/List/Playlist/PlaylistForceDeleteTest.php +++ b/tests/Feature/Http/Api/List/Playlist/PlaylistForceDeleteTest.php @@ -4,15 +4,15 @@ 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\Events\List\Playlist\PlaylistCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -32,7 +32,7 @@ class PlaylistForceDeleteTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -50,7 +50,7 @@ class PlaylistForceDeleteTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -65,7 +65,7 @@ class PlaylistForceDeleteTest extends TestCase /** * The Playlist Force Delete Endpoint shall forbid users from force deleting playlists - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -73,7 +73,7 @@ class PlaylistForceDeleteTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -95,7 +95,7 @@ class PlaylistForceDeleteTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -111,7 +111,7 @@ class PlaylistForceDeleteTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to force delete playlists - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -119,7 +119,7 @@ class PlaylistForceDeleteTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( diff --git a/tests/Feature/Http/Api/List/Playlist/PlaylistRestoreTest.php b/tests/Feature/Http/Api/List/Playlist/PlaylistRestoreTest.php index 2f0d5cfa6..f12bf7a78 100644 --- a/tests/Feature/Http/Api/List/Playlist/PlaylistRestoreTest.php +++ b/tests/Feature/Http/Api/List/Playlist/PlaylistRestoreTest.php @@ -4,16 +4,17 @@ declare(strict_types=1); namespace Tests\Feature\Http\Api\List\Playlist; -use App\Constants\Config\FlagConstants; use App\Constants\Config\PlaylistConstants; use App\Enums\Auth\ExtendedCrudPermission; use App\Enums\Auth\SpecialPermission; use App\Events\List\Playlist\PlaylistCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -33,7 +34,7 @@ class PlaylistRestoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -51,7 +52,7 @@ class PlaylistRestoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -73,7 +74,7 @@ class PlaylistRestoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory() ->for(User::factory()) @@ -90,7 +91,7 @@ class PlaylistRestoreTest extends TestCase /** * The Playlist Restore Endpoint shall forbid users from restoring playlists - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -98,7 +99,7 @@ class PlaylistRestoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne(); @@ -124,7 +125,7 @@ class PlaylistRestoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne(); @@ -148,7 +149,7 @@ class PlaylistRestoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(Playlist::class))->createOne(); @@ -168,7 +169,7 @@ class PlaylistRestoreTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to restore playlists - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -176,7 +177,7 @@ class PlaylistRestoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( @@ -211,7 +212,7 @@ class PlaylistRestoreTest extends TestCase $playlistLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_PLAYLISTS_QUALIFIED, $playlistLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->has(Playlist::factory()->count($playlistLimit)) @@ -244,7 +245,7 @@ class PlaylistRestoreTest extends TestCase $playlistLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_PLAYLISTS_QUALIFIED, $playlistLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->has(Playlist::factory()->count($playlistLimit)) diff --git a/tests/Feature/Http/Api/List/Playlist/PlaylistStoreTest.php b/tests/Feature/Http/Api/List/Playlist/PlaylistStoreTest.php index 0a1ad718e..b62ef0654 100644 --- a/tests/Feature/Http/Api/List/Playlist/PlaylistStoreTest.php +++ b/tests/Feature/Http/Api/List/Playlist/PlaylistStoreTest.php @@ -4,18 +4,19 @@ declare(strict_types=1); namespace Tests\Feature\Http\Api\List\Playlist; -use App\Constants\Config\FlagConstants; use App\Constants\Config\PlaylistConstants; use App\Constants\Config\ValidationConstants; use App\Enums\Auth\CrudPermission; use App\Enums\Auth\SpecialPermission; use App\Enums\Models\List\PlaylistVisibility; use App\Enums\Rules\ModerationService; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Http; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -33,7 +34,7 @@ class PlaylistStoreTest extends TestCase */ public function testProtected(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->makeOne(); @@ -49,7 +50,7 @@ class PlaylistStoreTest extends TestCase */ public function testForbiddenIfMissingPermission(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->makeOne(); @@ -64,13 +65,13 @@ class PlaylistStoreTest extends TestCase /** * The Playlist Store Endpoint shall forbid users from creating playlists - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ public function testForbiddenIfFlagDisabled(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $parameters = array_merge( Playlist::factory()->raw(), @@ -93,7 +94,7 @@ class PlaylistStoreTest extends TestCase */ public function testRequiredFields(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(Playlist::class))->createOne(); @@ -114,7 +115,7 @@ class PlaylistStoreTest extends TestCase */ public function testCreate(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $parameters = array_merge( Playlist::factory()->raw(), @@ -134,13 +135,13 @@ class PlaylistStoreTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to create playlists - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ public function testCreatePermittedForBypass(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $parameters = array_merge( Playlist::factory()->raw(), @@ -171,7 +172,7 @@ class PlaylistStoreTest extends TestCase $playlistLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_PLAYLISTS_QUALIFIED, $playlistLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $parameters = array_merge( Playlist::factory()->raw(), @@ -201,7 +202,7 @@ class PlaylistStoreTest extends TestCase $playlistLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_PLAYLISTS_QUALIFIED, $playlistLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $parameters = array_merge( Playlist::factory()->raw(), @@ -230,7 +231,7 @@ class PlaylistStoreTest extends TestCase */ public function testCreatedIfNotFlaggedByOpenAI(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); Config::set(ValidationConstants::MODERATION_SERVICE_QUALIFIED, ModerationService::OPENAI); Http::fake([ @@ -264,7 +265,7 @@ class PlaylistStoreTest extends TestCase */ public function testCreatedIfOpenAIFails(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); Config::set(ValidationConstants::MODERATION_SERVICE_QUALIFIED, ModerationService::OPENAI); Http::fake([ @@ -292,7 +293,7 @@ class PlaylistStoreTest extends TestCase */ public function testValidationErrorWhenFlaggedByOpenAI(): void { - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); Config::set(ValidationConstants::MODERATION_SERVICE_QUALIFIED, ModerationService::OPENAI); Http::fake([ diff --git a/tests/Feature/Http/Api/List/Playlist/PlaylistUpdateTest.php b/tests/Feature/Http/Api/List/Playlist/PlaylistUpdateTest.php index 4743ae96b..121a5e7ff 100644 --- a/tests/Feature/Http/Api/List/Playlist/PlaylistUpdateTest.php +++ b/tests/Feature/Http/Api/List/Playlist/PlaylistUpdateTest.php @@ -4,19 +4,20 @@ declare(strict_types=1); namespace Tests\Feature\Http\Api\List\Playlist; -use App\Constants\Config\FlagConstants; use App\Constants\Config\ValidationConstants; use App\Enums\Auth\CrudPermission; use App\Enums\Auth\SpecialPermission; use App\Enums\Models\List\PlaylistVisibility; use App\Enums\Rules\ModerationService; use App\Events\List\Playlist\PlaylistCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Http; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -36,7 +37,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -59,7 +60,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -86,7 +87,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory() ->for(User::factory()) @@ -108,7 +109,7 @@ class PlaylistUpdateTest extends TestCase /** * The Playlist Update Endpoint shall forbid users from updating playlists - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -116,7 +117,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Playlist::class))->createOne(); @@ -147,7 +148,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Playlist::class))->createOne(); @@ -180,7 +181,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(Playlist::class))->createOne(); @@ -204,7 +205,7 @@ class PlaylistUpdateTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to update playlists - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -212,7 +213,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( @@ -248,7 +249,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); Config::set(ValidationConstants::MODERATION_SERVICE_QUALIFIED, ModerationService::OPENAI); Http::fake([ @@ -290,7 +291,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); Config::set(ValidationConstants::MODERATION_SERVICE_QUALIFIED, ModerationService::OPENAI); Http::fake([ @@ -326,7 +327,7 @@ class PlaylistUpdateTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); Config::set(ValidationConstants::MODERATION_SERVICE_QUALIFIED, ModerationService::OPENAI); Http::fake([ diff --git a/tests/Feature/Http/Api/List/Playlist/Track/TrackDestroyTest.php b/tests/Feature/Http/Api/List/Playlist/Track/TrackDestroyTest.php index da92dbf2c..c00d2364a 100644 --- a/tests/Feature/Http/Api/List/Playlist/Track/TrackDestroyTest.php +++ b/tests/Feature/Http/Api/List/Playlist/Track/TrackDestroyTest.php @@ -4,18 +4,18 @@ 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\Events\List\Playlist\PlaylistCreated; use App\Events\List\Playlist\Track\TrackCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use App\Models\List\Playlist\PlaylistTrack; use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -35,7 +35,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()) @@ -55,7 +55,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()) @@ -79,7 +79,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()->for(User::factory())) @@ -96,7 +96,7 @@ class TrackDestroyTest extends TestCase /** * The Track Destroy Endpoint shall forbid users from destroying playlists tracks - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -104,7 +104,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne(); @@ -132,7 +132,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne(); @@ -163,7 +163,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne(); @@ -189,7 +189,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne(); @@ -221,7 +221,7 @@ class TrackDestroyTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to destroy playlist tracks - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -229,7 +229,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( @@ -262,7 +262,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne(); @@ -303,7 +303,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne(); @@ -344,7 +344,7 @@ class TrackDestroyTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::DELETE()->format(PlaylistTrack::class))->createOne(); diff --git a/tests/Feature/Http/Api/List/Playlist/Track/TrackForceDeleteTest.php b/tests/Feature/Http/Api/List/Playlist/Track/TrackForceDeleteTest.php index 3f9e3d8b6..25dffe674 100644 --- a/tests/Feature/Http/Api/List/Playlist/Track/TrackForceDeleteTest.php +++ b/tests/Feature/Http/Api/List/Playlist/Track/TrackForceDeleteTest.php @@ -4,18 +4,18 @@ 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\Events\List\Playlist\PlaylistCreated; use App\Events\List\Playlist\Track\TrackCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use App\Models\List\Playlist\PlaylistTrack; use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -35,7 +35,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()) @@ -55,7 +55,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()) @@ -79,7 +79,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne(); @@ -103,7 +103,7 @@ class TrackForceDeleteTest extends TestCase /** * The Track Force Delete Endpoint shall forbid users from force deleting playlist tracks - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -111,7 +111,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne(); @@ -139,7 +139,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne(); @@ -167,7 +167,7 @@ class TrackForceDeleteTest extends TestCase /** * 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. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -175,7 +175,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( @@ -208,7 +208,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne(); @@ -245,7 +245,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne(); @@ -282,7 +282,7 @@ class TrackForceDeleteTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::FORCE_DELETE()->format(PlaylistTrack::class))->createOne(); diff --git a/tests/Feature/Http/Api/List/Playlist/Track/TrackRestoreTest.php b/tests/Feature/Http/Api/List/Playlist/Track/TrackRestoreTest.php index ebdd27c7d..ada4002d7 100644 --- a/tests/Feature/Http/Api/List/Playlist/Track/TrackRestoreTest.php +++ b/tests/Feature/Http/Api/List/Playlist/Track/TrackRestoreTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Tests\Feature\Http\Api\List\Playlist\Track; -use App\Constants\Config\FlagConstants; use App\Constants\Config\PlaylistConstants; use App\Enums\Auth\CrudPermission; use App\Enums\Auth\ExtendedCrudPermission; @@ -12,12 +11,14 @@ use App\Enums\Auth\SpecialPermission; use App\Enums\Models\List\PlaylistVisibility; use App\Events\List\Playlist\PlaylistCreated; use App\Events\List\Playlist\Track\TrackCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use App\Models\List\Playlist\PlaylistTrack; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -37,7 +38,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()) @@ -57,7 +58,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()) @@ -81,7 +82,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $track = PlaylistTrack::factory() ->for(Playlist::factory()->for(User::factory())) @@ -105,7 +106,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne(); @@ -136,7 +137,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(ExtendedCrudPermission::RESTORE()->format(PlaylistTrack::class))->createOne(); @@ -153,7 +154,7 @@ class TrackRestoreTest extends TestCase /** * The Playlist Restore Endpoint shall forbid users from restoring playlists - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -161,7 +162,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -196,7 +197,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -241,7 +242,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -294,7 +295,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -342,7 +343,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -390,7 +391,7 @@ class TrackRestoreTest extends TestCase /** * 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. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -398,7 +399,7 @@ class TrackRestoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( @@ -437,7 +438,7 @@ class TrackRestoreTest extends TestCase $trackLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_TRACKS_QUALIFIED, $trackLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -477,7 +478,7 @@ class TrackRestoreTest extends TestCase $trackLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_TRACKS_QUALIFIED, $trackLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( diff --git a/tests/Feature/Http/Api/List/Playlist/Track/TrackStoreTest.php b/tests/Feature/Http/Api/List/Playlist/Track/TrackStoreTest.php index f03c9d1de..cbe5c77f2 100644 --- a/tests/Feature/Http/Api/List/Playlist/Track/TrackStoreTest.php +++ b/tests/Feature/Http/Api/List/Playlist/Track/TrackStoreTest.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace Tests\Feature\Http\Api\List\Playlist\Track; -use App\Constants\Config\FlagConstants; use App\Constants\Config\PlaylistConstants; use App\Enums\Auth\CrudPermission; use App\Enums\Auth\SpecialPermission; use App\Events\List\Playlist\PlaylistCreated; use App\Events\List\Playlist\Track\TrackCreated; +use App\Features\AllowPlaylistManagement; use App\Models\Auth\User; use App\Models\List\Playlist; use App\Models\List\Playlist\PlaylistTrack; @@ -17,6 +17,7 @@ use App\Models\Wiki\Video; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -36,7 +37,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -58,7 +59,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -84,7 +85,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory() ->for(User::factory()) @@ -105,7 +106,7 @@ class TrackStoreTest extends TestCase /** * The Track Store Endpoint shall forbid users from creating playlist tracks - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -113,7 +114,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -142,7 +143,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -168,7 +169,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -211,7 +212,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -248,7 +249,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -285,7 +286,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -322,7 +323,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -372,7 +373,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -423,7 +424,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -474,7 +475,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -515,7 +516,7 @@ class TrackStoreTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to create playlist tracks - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -523,7 +524,7 @@ class TrackStoreTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( @@ -560,7 +561,7 @@ class TrackStoreTest extends TestCase $trackLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_TRACKS_QUALIFIED, $trackLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::CREATE()->format(PlaylistTrack::class))->createOne(); @@ -594,7 +595,7 @@ class TrackStoreTest extends TestCase $trackLimit = $this->faker->randomDigitNotNull(); Config::set(PlaylistConstants::MAX_TRACKS_QUALIFIED, $trackLimit); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( diff --git a/tests/Feature/Http/Api/List/Playlist/Track/TrackUpdateTest.php b/tests/Feature/Http/Api/List/Playlist/Track/TrackUpdateTest.php index c16792e22..0c1cf8b4b 100644 --- a/tests/Feature/Http/Api/List/Playlist/Track/TrackUpdateTest.php +++ b/tests/Feature/Http/Api/List/Playlist/Track/TrackUpdateTest.php @@ -4,19 +4,19 @@ 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\Events\List\Playlist\PlaylistCreated; use App\Events\List\Playlist\Track\TrackCreated; +use App\Features\AllowPlaylistManagement; 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\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -36,7 +36,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -63,7 +63,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); @@ -94,7 +94,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory() ->for(User::factory()) @@ -127,7 +127,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -163,7 +163,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -205,7 +205,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -243,7 +243,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -285,7 +285,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -323,7 +323,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -364,7 +364,7 @@ class TrackUpdateTest extends TestCase /** * The Playlist Update Endpoint shall forbid users from updating playlists - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -372,7 +372,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -407,7 +407,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -454,7 +454,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -489,7 +489,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -539,7 +539,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -589,7 +589,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -639,7 +639,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -689,7 +689,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -739,7 +739,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -789,7 +789,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -839,7 +839,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory()->withPermissions(CrudPermission::UPDATE()->format(PlaylistTrack::class))->createOne(); @@ -882,7 +882,7 @@ class TrackUpdateTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to update playlist tracks - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -890,7 +890,7 @@ class TrackUpdateTest extends TestCase { Event::fakeExcept([PlaylistCreated::class, TrackCreated::class]); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( diff --git a/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageDestroyTest.php b/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageDestroyTest.php index 9cec19261..8268f3990 100644 --- a/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageDestroyTest.php +++ b/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageDestroyTest.php @@ -4,17 +4,17 @@ 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\Events\List\Playlist\PlaylistCreated; +use App\Features\AllowPlaylistManagement; 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\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -34,7 +34,7 @@ class PlaylistImageDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlistImage = PlaylistImage::factory() ->for(Playlist::factory()) @@ -55,7 +55,7 @@ class PlaylistImageDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlistImage = PlaylistImage::factory() ->for(Playlist::factory()) @@ -80,7 +80,7 @@ class PlaylistImageDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlistImage = PlaylistImage::factory() ->for(Playlist::factory()->for(User::factory())) @@ -102,7 +102,7 @@ class PlaylistImageDestroyTest extends TestCase /** * The Playlist Image Destroy Endpoint shall forbid users from destroying playlist images - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -110,7 +110,7 @@ class PlaylistImageDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -139,7 +139,7 @@ class PlaylistImageDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -169,7 +169,7 @@ class PlaylistImageDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $user = User::factory() ->withPermissions( @@ -193,7 +193,7 @@ class PlaylistImageDestroyTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to destroy playlist images - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -201,7 +201,7 @@ class PlaylistImageDestroyTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $user = User::factory() ->withPermissions( diff --git a/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageStoreTest.php b/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageStoreTest.php index 42acf1ce0..f0f577a74 100644 --- a/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageStoreTest.php +++ b/tests/Feature/Http/Api/Pivot/List/PlaylistImage/PlaylistImageStoreTest.php @@ -4,17 +4,17 @@ 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\Events\List\Playlist\PlaylistCreated; +use App\Features\AllowPlaylistManagement; 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\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -34,7 +34,7 @@ class PlaylistImageStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); $image = Image::factory()->createOne(); @@ -53,7 +53,7 @@ class PlaylistImageStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); $image = Image::factory()->createOne(); @@ -69,7 +69,7 @@ class PlaylistImageStoreTest extends TestCase /** * The Playlist Image Store Endpoint shall forbid users from creating playlist images - * if the 'flags.allow_playlist_management' property is disabled. + * if the Allow Playlist Management feature is inactive. * * @return void */ @@ -77,7 +77,7 @@ class PlaylistImageStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, false); + Feature::deactivate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); $image = Image::factory()->createOne(); @@ -105,7 +105,7 @@ class PlaylistImageStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, true); + Feature::activate(AllowPlaylistManagement::class); $playlist = Playlist::factory()->createOne(); $image = Image::factory()->createOne(); @@ -127,7 +127,7 @@ class PlaylistImageStoreTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to create playlist images - * even if the 'flags.allow_playlist_management' property is disabled. + * even if the Allow Playlist Management feature is inactive. * * @return void */ @@ -135,7 +135,7 @@ class PlaylistImageStoreTest extends TestCase { Event::fakeExcept(PlaylistCreated::class); - Config::set(FlagConstants::ALLOW_PLAYLIST_MANAGEMENT_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowPlaylistManagement::class, $this->faker->boolean()); $playlist = Playlist::factory()->createOne(); $image = Image::factory()->createOne(); diff --git a/tests/Feature/Http/Wiki/Audio/AudioTest.php b/tests/Feature/Http/Wiki/Audio/AudioTest.php index baa298a9e..69a5b4b96 100644 --- a/tests/Feature/Http/Wiki/Audio/AudioTest.php +++ b/tests/Feature/Http/Wiki/Audio/AudioTest.php @@ -5,15 +5,17 @@ declare(strict_types=1); namespace Tests\Feature\Http\Wiki\Audio; use App\Constants\Config\AudioConstants; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Enums\Auth\SpecialPermission; use App\Enums\Http\StreamingMethod; +use App\Features\AllowAudioStreams; use App\Models\Auth\User; use App\Models\Wiki\Audio; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Symfony\Component\HttpFoundation\StreamedResponse; use Tests\TestCase; @@ -26,7 +28,7 @@ class AudioTest extends TestCase use WithFaker; /** - * If audio streaming is disabled through the 'flags.allow_audio_streams' property, + * If audio streaming is disabled through the Allow Audio Streams feature, * the user shall receive a forbidden exception. * * @return void @@ -35,7 +37,7 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, false); + Feature::deactivate(AllowAudioStreams::class); $audio = Audio::factory()->createOne(); @@ -46,7 +48,7 @@ class AudioTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to stream audio - * even if the 'flags.allow_audio_streams' property is disabled. + * even if the Allow Audio Streams feature is disabled. * * @return void */ @@ -54,7 +56,7 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowAudioStreams::class, $this->faker->boolean()); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::getRandomValue()); $audio = Audio::factory()->createOne(); @@ -77,7 +79,7 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowAudioStreams::class); $audio = Audio::factory()->createOne(); @@ -97,8 +99,8 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, true); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, false); + Feature::activate(AllowAudioStreams::class); + Feature::deactivate(FeatureConstants::ALLOW_VIEW_RECORDING); $audio = Audio::factory()->createOne(); @@ -116,8 +118,8 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, true); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, true); + Feature::activate(AllowAudioStreams::class); + Feature::activate(FeatureConstants::ALLOW_VIEW_RECORDING); $audio = Audio::factory()->createOne(); @@ -135,8 +137,8 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, true); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, true); + Feature::activate(AllowAudioStreams::class); + Feature::activate(FeatureConstants::ALLOW_VIEW_RECORDING); $audio = Audio::factory()->createOne(); @@ -156,7 +158,7 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowAudioStreams::class); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, $this->faker->word()); $audio = Audio::factory()->createOne(); @@ -175,7 +177,7 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowAudioStreams::class); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::RESPONSE); $audio = Audio::factory()->createOne(); @@ -194,7 +196,7 @@ class AudioTest extends TestCase { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_AUDIO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowAudioStreams::class); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::NGINX); $audio = Audio::factory()->createOne(); diff --git a/tests/Feature/Http/Wiki/Video/Script/ScriptTest.php b/tests/Feature/Http/Wiki/Video/Script/ScriptTest.php index cf7f91c9b..1df6b0b2a 100644 --- a/tests/Feature/Http/Wiki/Video/Script/ScriptTest.php +++ b/tests/Feature/Http/Wiki/Video/Script/ScriptTest.php @@ -4,15 +4,16 @@ declare(strict_types=1); namespace Tests\Feature\Http\Wiki\Video\Script; -use App\Constants\Config\FlagConstants; use App\Constants\Config\VideoConstants; use App\Enums\Auth\SpecialPermission; +use App\Features\AllowScriptDownloading; use App\Models\Auth\User; use App\Models\Wiki\Video\VideoScript; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Http\Testing\File; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Tests\TestCase; @@ -24,14 +25,14 @@ class ScriptTest extends TestCase use WithFaker; /** - * If script downloading is disabled through the 'flags.allow_script_downloading' property, + * If script downloading is disabled through the Allow Script Downloading feature, * the user shall receive a forbidden exception. * * @return void */ public function testScriptDownloadingNotAllowedForbidden(): void { - Config::set(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED, false); + Feature::deactivate(AllowScriptDownloading::class); $script = VideoScript::factory()->createOne(); @@ -42,13 +43,13 @@ class ScriptTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to download scripts - * even if the 'flags.allow_script_downloading' property is disabled. + * even if the Allow Script Downloading feature is disabled. * * @return void */ public function testVideoStreamingPermittedForBypass(): void { - Config::set(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowScriptDownloading::class, $this->faker->boolean()); $fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.txt'); @@ -74,7 +75,7 @@ class ScriptTest extends TestCase */ public function testCannotStreamSoftDeletedVideo(): void { - Config::set(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowScriptDownloading::class); $script = VideoScript::factory()->createOne(); @@ -92,7 +93,7 @@ class ScriptTest extends TestCase */ public function testDownloadedThroughResponse(): void { - Config::set(FlagConstants::ALLOW_SCRIPT_DOWNLOADING_FLAG_QUALIFIED, true); + Feature::activate(AllowScriptDownloading::class); $fs = Storage::fake(Config::get(VideoConstants::SCRIPT_DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.txt'); diff --git a/tests/Feature/Http/Wiki/Video/VideoTest.php b/tests/Feature/Http/Wiki/Video/VideoTest.php index f67903ca9..cfe807a6d 100644 --- a/tests/Feature/Http/Wiki/Video/VideoTest.php +++ b/tests/Feature/Http/Wiki/Video/VideoTest.php @@ -4,16 +4,18 @@ declare(strict_types=1); namespace Tests\Feature\Http\Wiki\Video; -use App\Constants\Config\FlagConstants; use App\Constants\Config\VideoConstants; +use App\Constants\FeatureConstants; use App\Enums\Auth\SpecialPermission; use App\Enums\Http\StreamingMethod; +use App\Features\AllowVideoStreams; use App\Models\Auth\User; use App\Models\Wiki\Video; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; +use Laravel\Pennant\Feature; use Laravel\Sanctum\Sanctum; use Symfony\Component\HttpFoundation\StreamedResponse; use Tests\TestCase; @@ -26,7 +28,7 @@ class VideoTest extends TestCase use WithFaker; /** - * If video streaming is disabled through the 'flags.allow_video_streams' property, + * If video streaming is disabled through the Allow Video Streams feature, * the user shall receive a forbidden exception. * * @return void @@ -35,7 +37,7 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, false); + Feature::deactivate(AllowVideoStreams::class); $video = Video::factory()->createOne(); @@ -53,7 +55,7 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowVideoStreams::class); $video = Video::factory()->createOne(); @@ -73,8 +75,8 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, true); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, false); + Feature::activate(AllowVideoStreams::class); + Feature::deactivate(FeatureConstants::ALLOW_VIEW_RECORDING); $video = Video::factory()->createOne(); @@ -85,7 +87,7 @@ class VideoTest extends TestCase /** * Users with the bypass feature flag permission shall be permitted to stream video - * even if the 'flags.allow_video_streams' property is disabled. + * even if the Allow Video Streams feature is disabled. * * @return void */ @@ -93,7 +95,7 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, $this->faker->boolean()); + Feature::activate(AllowVideoStreams::class, $this->faker->boolean()); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::getRandomValue()); $video = Video::factory()->createOne(); @@ -116,8 +118,8 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, true); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, true); + Feature::activate(AllowVideoStreams::class); + Feature::activate(FeatureConstants::ALLOW_VIEW_RECORDING); $video = Video::factory()->createOne(); @@ -135,8 +137,8 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, true); - Config::set(FlagConstants::ALLOW_VIEW_RECORDING_FLAG_QUALIFIED, true); + Feature::activate(AllowVideoStreams::class); + Feature::activate(FeatureConstants::ALLOW_VIEW_RECORDING); $video = Video::factory()->createOne(); @@ -156,7 +158,7 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowVideoStreams::class); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, $this->faker->word()); $video = Video::factory()->createOne(); @@ -175,7 +177,7 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowVideoStreams::class); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::RESPONSE); $video = Video::factory()->createOne(); @@ -194,7 +196,7 @@ class VideoTest extends TestCase { Storage::fake(Config::get(VideoConstants::DEFAULT_DISK_QUALIFIED)); - Config::set(FlagConstants::ALLOW_VIDEO_STREAMS_FLAG_QUALIFIED, true); + Feature::activate(AllowVideoStreams::class); Config::set(VideoConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::NGINX); $video = Video::factory()->createOne(); diff --git a/tests/Feature/Jobs/Admin/AnnouncementTest.php b/tests/Feature/Jobs/Admin/AnnouncementTest.php index 0f04678b5..435c5e844 100644 --- a/tests/Feature/Jobs/Admin/AnnouncementTest.php +++ b/tests/Feature/Jobs/Admin/AnnouncementTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Admin; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Admin\Announcement\AnnouncementCreated; use App\Events\Admin\Announcement\AnnouncementDeleted; use App\Events\Admin\Announcement\AnnouncementRestored; @@ -12,8 +12,8 @@ use App\Events\Admin\Announcement\AnnouncementUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Admin\Announcement; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class AnnouncementTest extends TestCase */ public function testAnnouncementCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnnouncementCreated::class); @@ -46,7 +46,7 @@ class AnnouncementTest extends TestCase { $announcement = Announcement::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnnouncementDeleted::class); @@ -64,7 +64,7 @@ class AnnouncementTest extends TestCase { $announcement = Announcement::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnnouncementRestored::class); @@ -82,7 +82,7 @@ class AnnouncementTest extends TestCase { $announcement = Announcement::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnnouncementUpdated::class); diff --git a/tests/Feature/Jobs/Admin/DumpTest.php b/tests/Feature/Jobs/Admin/DumpTest.php index ca5a251c7..c6f9c720d 100644 --- a/tests/Feature/Jobs/Admin/DumpTest.php +++ b/tests/Feature/Jobs/Admin/DumpTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Admin; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Admin\Dump\DumpCreated; use App\Events\Admin\Dump\DumpDeleted; use App\Events\Admin\Dump\DumpRestored; @@ -12,8 +12,8 @@ use App\Events\Admin\Dump\DumpUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Admin\Dump; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class DumpTest extends TestCase */ public function testDumpCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(DumpCreated::class); @@ -46,7 +46,7 @@ class DumpTest extends TestCase { $dump = Dump::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(DumpDeleted::class); @@ -64,7 +64,7 @@ class DumpTest extends TestCase { $dump = Dump::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(DumpRestored::class); @@ -82,7 +82,7 @@ class DumpTest extends TestCase { $dump = Dump::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(DumpUpdated::class); diff --git a/tests/Feature/Jobs/Admin/FeatureTest.php b/tests/Feature/Jobs/Admin/FeatureTest.php new file mode 100644 index 000000000..b1abb809a --- /dev/null +++ b/tests/Feature/Jobs/Admin/FeatureTest.php @@ -0,0 +1,76 @@ +createOne(); + + Bus::assertDispatched(SendDiscordNotificationJob::class); + } + + /** + * When a feature is deleted, a SendDiscordNotification job shall be dispatched. + * + * @return void + */ + public function testFeatureDeletedSendsDiscordNotification(): void + { + $feature = FeatureModel::factory()->createOne(); + + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); + Bus::fake(SendDiscordNotificationJob::class); + Event::fakeExcept(FeatureDeleted::class); + + $feature->delete(); + + Bus::assertDispatched(SendDiscordNotificationJob::class); + } + + /** + * When a feature is updated, a SendDiscordNotification job shall be dispatched. + * + * @return void + */ + public function testFeatureUpdatedSendsDiscordNotification(): void + { + $feature = FeatureModel::factory()->createOne(); + + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); + Bus::fake(SendDiscordNotificationJob::class); + Event::fakeExcept(FeatureUpdated::class); + + $feature->update([ + FeatureModel::ATTRIBUTE_VALUE => ! $feature->value, + ]); + + Bus::assertDispatched(SendDiscordNotificationJob::class); + } +} diff --git a/tests/Feature/Jobs/Admin/SettingTest.php b/tests/Feature/Jobs/Admin/SettingTest.php index 1e9751440..fe0e1f271 100644 --- a/tests/Feature/Jobs/Admin/SettingTest.php +++ b/tests/Feature/Jobs/Admin/SettingTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Admin; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Admin\Setting\SettingCreated; use App\Events\Admin\Setting\SettingDeleted; use App\Events\Admin\Setting\SettingUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Admin\Setting; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -27,7 +27,7 @@ class SettingTest extends TestCase */ public function testSettingCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SettingCreated::class); @@ -45,7 +45,7 @@ class SettingTest extends TestCase { $setting = Setting::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SettingDeleted::class); @@ -63,7 +63,7 @@ class SettingTest extends TestCase { $setting = Setting::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SettingUpdated::class); diff --git a/tests/Feature/Jobs/Auth/UserTest.php b/tests/Feature/Jobs/Auth/UserTest.php index 17e984ac0..8c30de43a 100644 --- a/tests/Feature/Jobs/Auth/UserTest.php +++ b/tests/Feature/Jobs/Auth/UserTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Auth; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Auth\User\UserCreated; use App\Events\Auth\User\UserDeleted; use App\Events\Auth\User\UserRestored; @@ -12,8 +12,8 @@ use App\Events\Auth\User\UserUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Auth\User; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class UserTest extends TestCase */ public function testUserCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(UserCreated::class); @@ -46,7 +46,7 @@ class UserTest extends TestCase { $user = User::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(UserDeleted::class); @@ -64,7 +64,7 @@ class UserTest extends TestCase { $user = User::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(UserRestored::class); @@ -82,7 +82,7 @@ class UserTest extends TestCase { $user = User::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(UserUpdated::class); diff --git a/tests/Feature/Jobs/Billing/BalanceTest.php b/tests/Feature/Jobs/Billing/BalanceTest.php index 3258433b9..331c6e3e9 100644 --- a/tests/Feature/Jobs/Billing/BalanceTest.php +++ b/tests/Feature/Jobs/Billing/BalanceTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Billing; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Billing\Balance\BalanceCreated; use App\Events\Billing\Balance\BalanceDeleted; use App\Events\Billing\Balance\BalanceRestored; @@ -12,8 +12,8 @@ use App\Events\Billing\Balance\BalanceUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Billing\Balance; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class BalanceTest extends TestCase */ public function testBalanceCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(BalanceCreated::class); @@ -46,7 +46,7 @@ class BalanceTest extends TestCase { $balance = Balance::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(BalanceDeleted::class); @@ -64,7 +64,7 @@ class BalanceTest extends TestCase { $balance = Balance::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(BalanceRestored::class); @@ -82,7 +82,7 @@ class BalanceTest extends TestCase { $balance = Balance::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(BalanceUpdated::class); diff --git a/tests/Feature/Jobs/Billing/TransactionTest.php b/tests/Feature/Jobs/Billing/TransactionTest.php index 579b4801b..39b7f9811 100644 --- a/tests/Feature/Jobs/Billing/TransactionTest.php +++ b/tests/Feature/Jobs/Billing/TransactionTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Billing; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Billing\Transaction\TransactionCreated; use App\Events\Billing\Transaction\TransactionDeleted; use App\Events\Billing\Transaction\TransactionRestored; @@ -12,8 +12,8 @@ use App\Events\Billing\Transaction\TransactionUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Billing\Transaction; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class TransactionTest extends TestCase */ public function testTransactionCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TransactionCreated::class); @@ -46,7 +46,7 @@ class TransactionTest extends TestCase { $transaction = Transaction::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TransactionDeleted::class); @@ -64,7 +64,7 @@ class TransactionTest extends TestCase { $transaction = Transaction::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TransactionRestored::class); @@ -82,7 +82,7 @@ class TransactionTest extends TestCase { $transaction = Transaction::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TransactionUpdated::class); diff --git a/tests/Feature/Jobs/Document/PageTest.php b/tests/Feature/Jobs/Document/PageTest.php index 475fdee9c..79ae44ea2 100644 --- a/tests/Feature/Jobs/Document/PageTest.php +++ b/tests/Feature/Jobs/Document/PageTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Document; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Document\Page\PageCreated; use App\Events\Document\Page\PageDeleted; use App\Events\Document\Page\PageRestored; @@ -12,8 +12,8 @@ use App\Events\Document\Page\PageUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Document\Page; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class PageTest extends TestCase */ public function testPageCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PageCreated::class); @@ -46,7 +46,7 @@ class PageTest extends TestCase { $page = Page::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PageDeleted::class); @@ -64,7 +64,7 @@ class PageTest extends TestCase { $page = Page::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PageRestored::class); @@ -82,7 +82,7 @@ class PageTest extends TestCase { $page = Page::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PageUpdated::class); diff --git a/tests/Feature/Jobs/List/Playlist/TrackTest.php b/tests/Feature/Jobs/List/Playlist/TrackTest.php index 7cb23b32f..a7891d6dc 100644 --- a/tests/Feature/Jobs/List/Playlist/TrackTest.php +++ b/tests/Feature/Jobs/List/Playlist/TrackTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\List\Playlist; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\List\Playlist\Track\TrackCreated; use App\Events\List\Playlist\Track\TrackDeleted; use App\Events\List\Playlist\Track\TrackRestored; @@ -14,8 +14,8 @@ use App\Models\List\Playlist; use App\Models\List\Playlist\PlaylistTrack; use App\Models\Wiki\Video; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -32,7 +32,7 @@ class TrackTest extends TestCase { $playlist = Playlist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TrackCreated::class); @@ -56,7 +56,7 @@ class TrackTest extends TestCase ->for($playlist) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TrackDeleted::class); @@ -78,7 +78,7 @@ class TrackTest extends TestCase ->for($playlist) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TrackRestored::class); @@ -100,7 +100,7 @@ class TrackTest extends TestCase ->for($playlist) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(TrackUpdated::class); diff --git a/tests/Feature/Jobs/List/PlaylistTest.php b/tests/Feature/Jobs/List/PlaylistTest.php index 9e86a4c3f..7e01828dc 100644 --- a/tests/Feature/Jobs/List/PlaylistTest.php +++ b/tests/Feature/Jobs/List/PlaylistTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\List; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\List\Playlist\PlaylistCreated; use App\Events\List\Playlist\PlaylistDeleted; use App\Events\List\Playlist\PlaylistRestored; @@ -12,8 +12,8 @@ use App\Events\List\Playlist\PlaylistUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\List\Playlist; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class PlaylistTest extends TestCase */ public function testPlaylistCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PlaylistCreated::class); @@ -46,7 +46,7 @@ class PlaylistTest extends TestCase { $playlist = Playlist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PlaylistDeleted::class); @@ -64,7 +64,7 @@ class PlaylistTest extends TestCase { $playlist = Playlist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PlaylistRestored::class); @@ -82,7 +82,7 @@ class PlaylistTest extends TestCase { $playlist = Playlist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PlaylistUpdated::class); diff --git a/tests/Feature/Jobs/Pivot/List/PlaylistImageTest.php b/tests/Feature/Jobs/Pivot/List/PlaylistImageTest.php index f91b9b2a3..f42956e24 100644 --- a/tests/Feature/Jobs/Pivot/List/PlaylistImageTest.php +++ b/tests/Feature/Jobs/Pivot/List/PlaylistImageTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\List; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\List\PlaylistImage\PlaylistImageCreated; use App\Events\Pivot\List\PlaylistImage\PlaylistImageDeleted; use App\Jobs\SendDiscordNotificationJob; use App\Models\List\Playlist; use App\Models\Wiki\Image; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -30,7 +30,7 @@ class PlaylistImageTest extends TestCase $playlist = Playlist::factory()->createOne(); $image = Image::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PlaylistImageCreated::class); @@ -51,7 +51,7 @@ class PlaylistImageTest extends TestCase $playlist->images()->attach($image); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(PlaylistImageDeleted::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/AnimeImageTest.php b/tests/Feature/Jobs/Pivot/Wiki/AnimeImageTest.php index 6229d4106..5a8db38a5 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/AnimeImageTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/AnimeImageTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\AnimeImage\AnimeImageCreated; use App\Events\Pivot\Wiki\AnimeImage\AnimeImageDeleted; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Anime; use App\Models\Wiki\Image; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -30,7 +30,7 @@ class AnimeImageTest extends TestCase $anime = Anime::factory()->createOne(); $image = Image::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeImageCreated::class); @@ -51,7 +51,7 @@ class AnimeImageTest extends TestCase $anime->images()->attach($image); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeImageDeleted::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/AnimeResourceTest.php b/tests/Feature/Jobs/Pivot/Wiki/AnimeResourceTest.php index 8cb35931c..a8dc1e83d 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/AnimeResourceTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/AnimeResourceTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceCreated; use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceDeleted; use App\Events\Pivot\Wiki\AnimeResource\AnimeResourceUpdated; @@ -13,8 +13,8 @@ use App\Models\Wiki\Anime; use App\Models\Wiki\ExternalResource; use App\Pivots\Wiki\AnimeResource; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -32,7 +32,7 @@ class AnimeResourceTest extends TestCase $anime = Anime::factory()->createOne(); $resource = ExternalResource::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeResourceCreated::class); @@ -53,7 +53,7 @@ class AnimeResourceTest extends TestCase $anime->resources()->attach($resource); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeResourceDeleted::class); @@ -82,7 +82,7 @@ class AnimeResourceTest extends TestCase ->for($resource, 'resource') ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeResourceUpdated::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/AnimeSeriesTest.php b/tests/Feature/Jobs/Pivot/Wiki/AnimeSeriesTest.php index d22cecd03..6293ef71c 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/AnimeSeriesTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/AnimeSeriesTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\AnimeSeries\AnimeSeriesCreated; use App\Events\Pivot\Wiki\AnimeSeries\AnimeSeriesDeleted; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Anime; use App\Models\Wiki\Series; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -30,7 +30,7 @@ class AnimeSeriesTest extends TestCase $anime = Anime::factory()->createOne(); $series = Series::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeSeriesCreated::class); @@ -51,7 +51,7 @@ class AnimeSeriesTest extends TestCase $anime->series()->attach($series); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeSeriesDeleted::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/AnimeStudioTest.php b/tests/Feature/Jobs/Pivot/Wiki/AnimeStudioTest.php index 852f05736..9b00550dc 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/AnimeStudioTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/AnimeStudioTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\AnimeStudio\AnimeStudioCreated; use App\Events\Pivot\Wiki\AnimeStudio\AnimeStudioDeleted; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Anime; use App\Models\Wiki\Studio; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -30,7 +30,7 @@ class AnimeStudioTest extends TestCase $anime = Anime::factory()->createOne(); $studio = Studio::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeStudioCreated::class); @@ -51,7 +51,7 @@ class AnimeStudioTest extends TestCase $anime->studios()->attach($studio); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeStudioDeleted::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/AnimeThemeEntryVideoTest.php b/tests/Feature/Jobs/Pivot/Wiki/AnimeThemeEntryVideoTest.php index d2904fc63..bf414a527 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/AnimeThemeEntryVideoTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/AnimeThemeEntryVideoTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\AnimeThemeEntryVideo\AnimeThemeEntryVideoCreated; use App\Events\Pivot\Wiki\AnimeThemeEntryVideo\AnimeThemeEntryVideoDeleted; use App\Jobs\SendDiscordNotificationJob; @@ -13,8 +13,8 @@ use App\Models\Wiki\Anime\AnimeTheme; use App\Models\Wiki\Anime\Theme\AnimeThemeEntry; use App\Models\Wiki\Video; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -34,7 +34,7 @@ class AnimeThemeEntryVideoTest extends TestCase ->for(AnimeTheme::factory()->for(Anime::factory())) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeThemeEntryVideoCreated::class); @@ -57,7 +57,7 @@ class AnimeThemeEntryVideoTest extends TestCase $video->animethemeentries()->attach($entry); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeThemeEntryVideoDeleted::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/ArtistImageTest.php b/tests/Feature/Jobs/Pivot/Wiki/ArtistImageTest.php index b1782df8d..7617ef956 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/ArtistImageTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/ArtistImageTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\ArtistImage\ArtistImageCreated; use App\Events\Pivot\Wiki\ArtistImage\ArtistImageDeleted; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Artist; use App\Models\Wiki\Image; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -30,7 +30,7 @@ class ArtistImageTest extends TestCase $artist = Artist::factory()->createOne(); $image = Image::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistImageCreated::class); @@ -51,7 +51,7 @@ class ArtistImageTest extends TestCase $artist->images()->attach($image); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistImageDeleted::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/ArtistMemberTest.php b/tests/Feature/Jobs/Pivot/Wiki/ArtistMemberTest.php index 4b78e6925..c4c53b142 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/ArtistMemberTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/ArtistMemberTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\ArtistMember\ArtistMemberCreated; use App\Events\Pivot\Wiki\ArtistMember\ArtistMemberDeleted; use App\Events\Pivot\Wiki\ArtistMember\ArtistMemberUpdated; @@ -12,8 +12,8 @@ use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Artist; use App\Pivots\Wiki\ArtistMember; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -31,7 +31,7 @@ class ArtistMemberTest extends TestCase $artist = Artist::factory()->createOne(); $member = Artist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistMemberCreated::class); @@ -52,7 +52,7 @@ class ArtistMemberTest extends TestCase $artist->members()->attach($member); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistMemberDeleted::class); @@ -81,7 +81,7 @@ class ArtistMemberTest extends TestCase ->for($member, 'member') ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistMemberUpdated::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/ArtistResourceTest.php b/tests/Feature/Jobs/Pivot/Wiki/ArtistResourceTest.php index 4d1c40dc7..07a10b251 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/ArtistResourceTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/ArtistResourceTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\ArtistResource\ArtistResourceCreated; use App\Events\Pivot\Wiki\ArtistResource\ArtistResourceDeleted; use App\Events\Pivot\Wiki\ArtistResource\ArtistResourceUpdated; @@ -13,8 +13,8 @@ use App\Models\Wiki\Artist; use App\Models\Wiki\ExternalResource; use App\Pivots\Wiki\ArtistResource; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -32,7 +32,7 @@ class ArtistResourceTest extends TestCase $artist = Artist::factory()->createOne(); $resource = ExternalResource::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistResourceCreated::class); @@ -53,7 +53,7 @@ class ArtistResourceTest extends TestCase $artist->resources()->attach($resource); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistResourceDeleted::class); @@ -82,7 +82,7 @@ class ArtistResourceTest extends TestCase ->for($resource, 'resource') ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistResourceUpdated::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/ArtistSongTest.php b/tests/Feature/Jobs/Pivot/Wiki/ArtistSongTest.php index 238473ac6..76c133973 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/ArtistSongTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/ArtistSongTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\ArtistSong\ArtistSongCreated; use App\Events\Pivot\Wiki\ArtistSong\ArtistSongDeleted; use App\Events\Pivot\Wiki\ArtistSong\ArtistSongUpdated; @@ -13,8 +13,8 @@ use App\Models\Wiki\Artist; use App\Models\Wiki\Song; use App\Pivots\Wiki\ArtistSong; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -32,7 +32,7 @@ class ArtistSongTest extends TestCase $artist = Artist::factory()->createOne(); $song = Song::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistSongCreated::class); @@ -53,7 +53,7 @@ class ArtistSongTest extends TestCase $artist->songs()->attach($song); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistSongDeleted::class); @@ -82,7 +82,7 @@ class ArtistSongTest extends TestCase ->for($song, 'song') ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistSongUpdated::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/StudioImageTest.php b/tests/Feature/Jobs/Pivot/Wiki/StudioImageTest.php index 397f04593..dd581d84d 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/StudioImageTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/StudioImageTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\StudioImage\StudioImageCreated; use App\Events\Pivot\Wiki\StudioImage\StudioImageDeleted; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Image; use App\Models\Wiki\Studio; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -30,7 +30,7 @@ class StudioImageTest extends TestCase $studio = Studio::factory()->createOne(); $image = Image::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioImageCreated::class); @@ -51,7 +51,7 @@ class StudioImageTest extends TestCase $studio->images()->attach($image); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioImageDeleted::class); diff --git a/tests/Feature/Jobs/Pivot/Wiki/StudioResourceTest.php b/tests/Feature/Jobs/Pivot/Wiki/StudioResourceTest.php index 6166d9156..2ab5abbde 100644 --- a/tests/Feature/Jobs/Pivot/Wiki/StudioResourceTest.php +++ b/tests/Feature/Jobs/Pivot/Wiki/StudioResourceTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Pivot\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Pivot\Wiki\StudioResource\StudioResourceCreated; use App\Events\Pivot\Wiki\StudioResource\StudioResourceDeleted; use App\Events\Pivot\Wiki\StudioResource\StudioResourceUpdated; @@ -13,8 +13,8 @@ use App\Models\Wiki\ExternalResource; use App\Models\Wiki\Studio; use App\Pivots\Wiki\StudioResource; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -32,7 +32,7 @@ class StudioResourceTest extends TestCase $studio = Studio::factory()->createOne(); $resource = ExternalResource::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioResourceCreated::class); @@ -53,7 +53,7 @@ class StudioResourceTest extends TestCase $studio->resources()->attach($resource); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioResourceDeleted::class); @@ -82,7 +82,7 @@ class StudioResourceTest extends TestCase ->for($resource, 'resource') ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioResourceUpdated::class); diff --git a/tests/Feature/Jobs/SendDiscordNotificationTest.php b/tests/Feature/Jobs/SendDiscordNotificationTest.php index 68c1396a3..ae6ed374d 100644 --- a/tests/Feature/Jobs/SendDiscordNotificationTest.php +++ b/tests/Feature/Jobs/SendDiscordNotificationTest.php @@ -4,15 +4,15 @@ declare(strict_types=1); namespace Tests\Feature\Jobs; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Contracts\Events\DiscordMessageEvent; use App\Jobs\Middleware\RateLimited; use App\Jobs\SendDiscordNotificationJob; use App\Notifications\DiscordNotification; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Notifications\AnonymousNotifiable; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Notification; +use Laravel\Pennant\Feature; use NotificationChannels\Discord\DiscordMessage; use Tests\TestCase; @@ -28,7 +28,7 @@ class SendDiscordNotificationTest extends TestCase */ public function testSendDiscordNotificationJobSendsNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Notification::fake(); $event = new class implements DiscordMessageEvent @@ -54,6 +54,16 @@ class SendDiscordNotificationTest extends TestCase { return ''; } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } }; $job = new SendDiscordNotificationJob($event); @@ -96,6 +106,16 @@ class SendDiscordNotificationTest extends TestCase { return ''; } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } }; $job = new SendDiscordNotificationJob($event); diff --git a/tests/Feature/Jobs/Wiki/Anime/SynonymTest.php b/tests/Feature/Jobs/Wiki/Anime/SynonymTest.php index 7bad4c2e0..2637711f5 100644 --- a/tests/Feature/Jobs/Wiki/Anime/SynonymTest.php +++ b/tests/Feature/Jobs/Wiki/Anime/SynonymTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki\Anime; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Anime\Synonym\SynonymCreated; use App\Events\Wiki\Anime\Synonym\SynonymDeleted; use App\Events\Wiki\Anime\Synonym\SynonymRestored; @@ -13,8 +13,8 @@ use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Anime; use App\Models\Wiki\Anime\AnimeSynonym; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -31,7 +31,7 @@ class SynonymTest extends TestCase { $anime = Anime::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SynonymCreated::class); @@ -51,7 +51,7 @@ class SynonymTest extends TestCase ->for(Anime::factory()) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SynonymDeleted::class); @@ -71,7 +71,7 @@ class SynonymTest extends TestCase ->for(Anime::factory()) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SynonymRestored::class); @@ -95,7 +95,7 @@ class SynonymTest extends TestCase ->for(Anime::factory()) ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SynonymUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/Anime/Theme/EntryTest.php b/tests/Feature/Jobs/Wiki/Anime/Theme/EntryTest.php index 5e617f00e..2eef7bbf4 100644 --- a/tests/Feature/Jobs/Wiki/Anime/Theme/EntryTest.php +++ b/tests/Feature/Jobs/Wiki/Anime/Theme/EntryTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki\Anime\Theme; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Anime\Theme\Entry\EntryCreated; use App\Events\Wiki\Anime\Theme\Entry\EntryDeleted; use App\Events\Wiki\Anime\Theme\Entry\EntryRestored; @@ -14,8 +14,8 @@ use App\Models\Wiki\Anime; use App\Models\Wiki\Anime\AnimeTheme; use App\Models\Wiki\Anime\Theme\AnimeThemeEntry; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -34,7 +34,7 @@ class EntryTest extends TestCase ->for(Anime::factory()) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(EntryCreated::class); @@ -54,7 +54,7 @@ class EntryTest extends TestCase ->for(AnimeTheme::factory()->for(Anime::factory())) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(EntryDeleted::class); @@ -74,7 +74,7 @@ class EntryTest extends TestCase ->for(AnimeTheme::factory()->for(Anime::factory())) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(EntryRestored::class); @@ -98,7 +98,7 @@ class EntryTest extends TestCase ->for(AnimeTheme::factory()->for(Anime::factory())) ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(EntryUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/Anime/ThemeTest.php b/tests/Feature/Jobs/Wiki/Anime/ThemeTest.php index f7d20020a..4cbef5bb9 100644 --- a/tests/Feature/Jobs/Wiki/Anime/ThemeTest.php +++ b/tests/Feature/Jobs/Wiki/Anime/ThemeTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki\Anime; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Anime\Theme\ThemeCreated; use App\Events\Wiki\Anime\Theme\ThemeDeleted; use App\Events\Wiki\Anime\Theme\ThemeRestored; @@ -13,8 +13,8 @@ use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Anime; use App\Models\Wiki\Anime\AnimeTheme; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -31,7 +31,7 @@ class ThemeTest extends TestCase { $anime = Anime::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ThemeCreated::class); @@ -51,7 +51,7 @@ class ThemeTest extends TestCase ->for(Anime::factory()) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ThemeDeleted::class); @@ -71,7 +71,7 @@ class ThemeTest extends TestCase ->for(Anime::factory()) ->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ThemeRestored::class); @@ -95,7 +95,7 @@ class ThemeTest extends TestCase ->for(Anime::factory()) ->makeOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ThemeUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/AnimeTest.php b/tests/Feature/Jobs/Wiki/AnimeTest.php index fdd97e580..56bf4a86a 100644 --- a/tests/Feature/Jobs/Wiki/AnimeTest.php +++ b/tests/Feature/Jobs/Wiki/AnimeTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Anime\AnimeCreated; use App\Events\Wiki\Anime\AnimeDeleted; use App\Events\Wiki\Anime\AnimeRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Anime\AnimeUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Anime; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class AnimeTest extends TestCase */ public function testAnimeCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeCreated::class); @@ -46,7 +46,7 @@ class AnimeTest extends TestCase { $anime = Anime::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeDeleted::class); @@ -64,7 +64,7 @@ class AnimeTest extends TestCase { $anime = Anime::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeRestored::class); @@ -82,7 +82,7 @@ class AnimeTest extends TestCase { $anime = Anime::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AnimeUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/ArtistTest.php b/tests/Feature/Jobs/Wiki/ArtistTest.php index 1f6bc7ff2..ecec43272 100644 --- a/tests/Feature/Jobs/Wiki/ArtistTest.php +++ b/tests/Feature/Jobs/Wiki/ArtistTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Artist\ArtistCreated; use App\Events\Wiki\Artist\ArtistDeleted; use App\Events\Wiki\Artist\ArtistRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Artist\ArtistUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Artist; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class ArtistTest extends TestCase */ public function testArtistCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistCreated::class); @@ -46,7 +46,7 @@ class ArtistTest extends TestCase { $artist = Artist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistDeleted::class); @@ -64,7 +64,7 @@ class ArtistTest extends TestCase { $artist = Artist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistRestored::class); @@ -82,7 +82,7 @@ class ArtistTest extends TestCase { $artist = Artist::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ArtistUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/AudioTest.php b/tests/Feature/Jobs/Wiki/AudioTest.php index a01d10911..498c87410 100644 --- a/tests/Feature/Jobs/Wiki/AudioTest.php +++ b/tests/Feature/Jobs/Wiki/AudioTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Audio\AudioCreated; use App\Events\Wiki\Audio\AudioDeleted; use App\Events\Wiki\Audio\AudioRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Audio\AudioUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Audio; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class AudioTest extends TestCase */ public function testAudioCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AudioCreated::class); @@ -46,7 +46,7 @@ class AudioTest extends TestCase { $audio = Audio::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AudioDeleted::class); @@ -64,7 +64,7 @@ class AudioTest extends TestCase { $audio = Audio::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AudioRestored::class); @@ -82,7 +82,7 @@ class AudioTest extends TestCase { $audio = Audio::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(AudioUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/ExternalResourceTest.php b/tests/Feature/Jobs/Wiki/ExternalResourceTest.php index 1dbd0dcac..d05dbcbd7 100644 --- a/tests/Feature/Jobs/Wiki/ExternalResourceTest.php +++ b/tests/Feature/Jobs/Wiki/ExternalResourceTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\ExternalResource\ExternalResourceCreated; use App\Events\Wiki\ExternalResource\ExternalResourceDeleted; use App\Events\Wiki\ExternalResource\ExternalResourceRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\ExternalResource\ExternalResourceUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\ExternalResource; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class ExternalResourceTest extends TestCase */ public function testResourceCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ExternalResourceCreated::class); @@ -46,7 +46,7 @@ class ExternalResourceTest extends TestCase { $resource = ExternalResource::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ExternalResourceDeleted::class); @@ -64,7 +64,7 @@ class ExternalResourceTest extends TestCase { $resource = ExternalResource::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ExternalResourceRestored::class); @@ -82,7 +82,7 @@ class ExternalResourceTest extends TestCase { $resource = ExternalResource::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ExternalResourceUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/ImageTest.php b/tests/Feature/Jobs/Wiki/ImageTest.php index 1a62f436c..ed7d3697c 100644 --- a/tests/Feature/Jobs/Wiki/ImageTest.php +++ b/tests/Feature/Jobs/Wiki/ImageTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Image\ImageCreated; use App\Events\Wiki\Image\ImageDeleted; use App\Events\Wiki\Image\ImageRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Image\ImageUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Image; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class ImageTest extends TestCase */ public function testImageCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ImageCreated::class); @@ -46,7 +46,7 @@ class ImageTest extends TestCase { $image = Image::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ImageDeleted::class); @@ -64,7 +64,7 @@ class ImageTest extends TestCase { $image = Image::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ImageRestored::class); @@ -82,7 +82,7 @@ class ImageTest extends TestCase { $image = Image::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(ImageUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/SeriesTest.php b/tests/Feature/Jobs/Wiki/SeriesTest.php index 777a7ae3c..5f0dca4ce 100644 --- a/tests/Feature/Jobs/Wiki/SeriesTest.php +++ b/tests/Feature/Jobs/Wiki/SeriesTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Series\SeriesCreated; use App\Events\Wiki\Series\SeriesDeleted; use App\Events\Wiki\Series\SeriesRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Series\SeriesUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Series; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class SeriesTest extends TestCase */ public function testSeriesCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SeriesCreated::class); @@ -46,7 +46,7 @@ class SeriesTest extends TestCase { $series = Series::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SeriesDeleted::class); @@ -64,7 +64,7 @@ class SeriesTest extends TestCase { $series = Series::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SeriesRestored::class); @@ -82,7 +82,7 @@ class SeriesTest extends TestCase { $series = Series::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SeriesUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/SongTest.php b/tests/Feature/Jobs/Wiki/SongTest.php index 194db48d0..d95954242 100644 --- a/tests/Feature/Jobs/Wiki/SongTest.php +++ b/tests/Feature/Jobs/Wiki/SongTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Song\SongCreated; use App\Events\Wiki\Song\SongDeleted; use App\Events\Wiki\Song\SongRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Song\SongUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Song; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class SongTest extends TestCase */ public function testSongCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SongCreated::class); @@ -46,7 +46,7 @@ class SongTest extends TestCase { $song = Song::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SongDeleted::class); @@ -64,7 +64,7 @@ class SongTest extends TestCase { $song = Song::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SongRestored::class); @@ -82,7 +82,7 @@ class SongTest extends TestCase { $song = Song::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(SongUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/StudioTest.php b/tests/Feature/Jobs/Wiki/StudioTest.php index 011fb058f..72a63050c 100644 --- a/tests/Feature/Jobs/Wiki/StudioTest.php +++ b/tests/Feature/Jobs/Wiki/StudioTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Studio\StudioCreated; use App\Events\Wiki\Studio\StudioDeleted; use App\Events\Wiki\Studio\StudioRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Studio\StudioUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Studio; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class StudioTest extends TestCase */ public function testStudioCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioCreated::class); @@ -46,7 +46,7 @@ class StudioTest extends TestCase { $studio = Studio::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioDeleted::class); @@ -64,7 +64,7 @@ class StudioTest extends TestCase { $studio = Studio::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioRestored::class); @@ -82,7 +82,7 @@ class StudioTest extends TestCase { $studio = Studio::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(StudioUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/Video/ScriptTest.php b/tests/Feature/Jobs/Wiki/Video/ScriptTest.php index c419b8c0e..7b2934c5f 100644 --- a/tests/Feature/Jobs/Wiki/Video/ScriptTest.php +++ b/tests/Feature/Jobs/Wiki/Video/ScriptTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki\Video; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Video\Script\VideoScriptCreated; use App\Events\Wiki\Video\Script\VideoScriptDeleted; use App\Events\Wiki\Video\Script\VideoScriptRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Video\Script\VideoScriptUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Video\VideoScript; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class ScriptTest extends TestCase */ public function testVideoCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoScriptCreated::class); @@ -46,7 +46,7 @@ class ScriptTest extends TestCase { $script = VideoScript::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoScriptDeleted::class); @@ -64,7 +64,7 @@ class ScriptTest extends TestCase { $script = VideoScript::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoScriptRestored::class); @@ -82,7 +82,7 @@ class ScriptTest extends TestCase { $script = VideoScript::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoScriptUpdated::class); diff --git a/tests/Feature/Jobs/Wiki/VideoTest.php b/tests/Feature/Jobs/Wiki/VideoTest.php index 890c0c6c5..b27387b84 100644 --- a/tests/Feature/Jobs/Wiki/VideoTest.php +++ b/tests/Feature/Jobs/Wiki/VideoTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Tests\Feature\Jobs\Wiki; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Events\Wiki\Video\VideoCreated; use App\Events\Wiki\Video\VideoDeleted; use App\Events\Wiki\Video\VideoRestored; @@ -12,8 +12,8 @@ use App\Events\Wiki\Video\VideoUpdated; use App\Jobs\SendDiscordNotificationJob; use App\Models\Wiki\Video; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Event; +use Laravel\Pennant\Feature; use Tests\TestCase; /** @@ -28,7 +28,7 @@ class VideoTest extends TestCase */ public function testVideoCreatedSendsDiscordNotification(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoCreated::class); @@ -46,7 +46,7 @@ class VideoTest extends TestCase { $video = Video::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoDeleted::class); @@ -64,7 +64,7 @@ class VideoTest extends TestCase { $video = Video::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoRestored::class); @@ -82,7 +82,7 @@ class VideoTest extends TestCase { $video = Video::factory()->createOne(); - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); Event::fakeExcept(VideoUpdated::class); diff --git a/tests/Feature/Listeners/SendDiscordNotificationTest.php b/tests/Feature/Listeners/SendDiscordNotificationTest.php index 2f08f2ba1..df372a913 100644 --- a/tests/Feature/Listeners/SendDiscordNotificationTest.php +++ b/tests/Feature/Listeners/SendDiscordNotificationTest.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace Tests\Feature\Listeners; -use App\Constants\Config\FlagConstants; +use App\Constants\FeatureConstants; use App\Contracts\Events\DiscordMessageEvent; use App\Jobs\SendDiscordNotificationJob; use App\Listeners\SendDiscordNotification; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Support\Facades\Bus; -use Illuminate\Support\Facades\Config; +use Laravel\Pennant\Feature; use NotificationChannels\Discord\DiscordMessage; use Tests\TestCase; @@ -20,14 +20,14 @@ use Tests\TestCase; class SendDiscordNotificationTest extends TestCase { /** - * If discord notifications are disabled through the 'flags.allow_discord_notifications' property, + * If discord notifications are disabled through the Allow Discord Notifications feature, * discord notification jobs shall not be dispatched. * * @return void */ public function testDiscordNotificationsNotAllowed(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, false); + Feature::deactivate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); $event = new class implements DiscordMessageEvent @@ -53,6 +53,16 @@ class SendDiscordNotificationTest extends TestCase { return ''; } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } }; $listener = new SendDiscordNotification(); @@ -63,14 +73,14 @@ class SendDiscordNotificationTest extends TestCase } /** - * If discord notifications are enabled through the 'flags.allow_discord_notifications' property, + * If discord notifications are enabled through the Allow Discord Notifications feature, * discord notification jobs shall be dispatched. * * @return void */ public function testDiscordNotificationsAllowed(): void { - Config::set(FlagConstants::ALLOW_DISCORD_NOTIFICATIONS_FLAG_QUALIFIED, true); + Feature::activate(FeatureConstants::ALLOW_DISCORD_NOTIFICATIONS); Bus::fake(SendDiscordNotificationJob::class); $event = new class implements DiscordMessageEvent @@ -96,6 +106,16 @@ class SendDiscordNotificationTest extends TestCase { return ''; } + + /** + * Determine if the message should be sent. + * + * @return bool + */ + public function shouldSendDiscordMessage(): bool + { + return true; + } }; $listener = new SendDiscordNotification(); diff --git a/tests/Unit/Models/Admin/FeatureTest.php b/tests/Unit/Models/Admin/FeatureTest.php new file mode 100644 index 000000000..9cbd528c7 --- /dev/null +++ b/tests/Unit/Models/Admin/FeatureTest.php @@ -0,0 +1,55 @@ +createOne(); + + static::assertIsString($feature->getName()); + } + + /** + * Feature shall indicate if the scope is null. + * + * @return void + */ + public function testNullableScope(): void + { + $feature = Feature::factory()->createOne(); + + static::assertTrue($feature->isNullScope()); + } + + /** + * Feature shall indicate if the scope is not null. + * + * @return void + */ + public function testNonNullScope(): void + { + $feature = Feature::factory()->createOne([ + Feature::ATTRIBUTE_SCOPE => $this->faker->word(), + ]); + + static::assertFalse($feature->isNullScope()); + } +}