diff --git a/app/Filament/Resources/PluginBundleResource.php b/app/Filament/Resources/PluginBundleResource.php index 45b45329..3b758450 100644 --- a/app/Filament/Resources/PluginBundleResource.php +++ b/app/Filament/Resources/PluginBundleResource.php @@ -187,6 +187,7 @@ public static function table(Table $table): Table ->mapWithKeys(fn (User $user) => [$user->id => "{$user->name} ({$user->email})"]) ->toArray(); }) + ->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->name) ->required(), ]) ->action(function (PluginBundle $record, array $data): void { diff --git a/package-lock.json b/package-lock.json index 276d5e40..135b7064 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "nativephp", + "name": "brave-lemur", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/tests/Feature/Filament/GrantBundleToUserActionTest.php b/tests/Feature/Filament/GrantBundleToUserActionTest.php new file mode 100644 index 00000000..43d2237c --- /dev/null +++ b/tests/Feature/Filament/GrantBundleToUserActionTest.php @@ -0,0 +1,54 @@ +admin = User::factory()->create(['email' => 'admin@test.com']); + config(['filament.users' => ['admin@test.com']]); + + $this->bundle = PluginBundle::factory()->active()->create(); + } + + public function test_grant_to_user_action_can_be_called_with_user_id(): void + { + $recipient = User::factory()->create(); + $plugins = Plugin::factory()->count(2)->approved()->create(); + $this->bundle->plugins()->attach($plugins->pluck('id')); + + Livewire::actingAs($this->admin) + ->test(ListPluginBundles::class) + ->callAction( + TestAction::make('grantToUser')->table($this->bundle), + data: ['user_id' => $recipient->id], + ) + ->assertHasNoFormErrors(); + + foreach ($plugins as $plugin) { + $this->assertDatabaseHas('plugin_licenses', [ + 'user_id' => $recipient->id, + 'plugin_id' => $plugin->id, + 'plugin_bundle_id' => $this->bundle->id, + ]); + } + } +}