diff --git a/app/Filament/Resources/PluginResource.php b/app/Filament/Resources/PluginResource.php index 7a9875e1..8e6abc0d 100644 --- a/app/Filament/Resources/PluginResource.php +++ b/app/Filament/Resources/PluginResource.php @@ -339,6 +339,12 @@ public static function table(Table $table): Table ->label('Submitted') ->dateTime() ->sortable(), + + Tables\Columns\TextColumn::make('approved_at') + ->label('Approved') + ->dateTime() + ->placeholder('-') + ->sortable(), ]) ->filters([ Tables\Filters\SelectFilter::make('status') diff --git a/app/Notifications/NewPluginAvailable.php b/app/Notifications/NewPluginAvailable.php index c031a396..4701b5b0 100644 --- a/app/Notifications/NewPluginAvailable.php +++ b/app/Notifications/NewPluginAvailable.php @@ -19,6 +19,9 @@ public function __construct( ) {} /** + * New plugins are announced in-app only. Emailing every opted-in user on + * every approval was far too much mail for something that isn't urgent. + * * @return array */ public function via(object $notifiable): array @@ -27,7 +30,7 @@ public function via(object $notifiable): array return []; } - return ['mail', 'database']; + return ['database']; } public function toMail(object $notifiable): MailMessage diff --git a/tests/Feature/Filament/PluginResourceTest.php b/tests/Feature/Filament/PluginResourceTest.php index 739c80de..514efbbe 100644 --- a/tests/Feature/Filament/PluginResourceTest.php +++ b/tests/Feature/Filament/PluginResourceTest.php @@ -4,6 +4,7 @@ use App\Filament\Resources\PluginResource; use App\Filament\Resources\PluginResource\Pages\EditPlugin; +use App\Filament\Resources\PluginResource\Pages\ListPlugins; use App\Filament\Resources\UserResource; use App\Models\Plugin; use App\Models\User; @@ -129,6 +130,21 @@ public function test_free_plugin_license_links_to_github(): void $response->assertSee('https://github.com/acme/free-license-222/blob/main/LICENSE'); } + public function test_plugins_table_can_be_sorted_by_approved_at(): void + { + $oldest = Plugin::factory()->approved()->create(['approved_at' => now()->subDays(10)]); + $newest = Plugin::factory()->approved()->create(['approved_at' => now()->subDay()]); + $middle = Plugin::factory()->approved()->create(['approved_at' => now()->subDays(5)]); + + Livewire::actingAs($this->admin) + ->test(ListPlugins::class) + ->assertCanRenderTableColumn('approved_at') + ->sortTable('approved_at', 'desc') + ->assertCanSeeTableRecords([$newest, $middle, $oldest], inOrder: true) + ->sortTable('approved_at', 'asc') + ->assertCanSeeTableRecords([$oldest, $middle, $newest], inOrder: true); + } + public function test_submission_info_shows_go_to_user_action(): void { $user = User::factory()->create(); diff --git a/tests/Feature/Notifications/NewPluginAvailableTest.php b/tests/Feature/Notifications/NewPluginAvailableTest.php index 07c14157..04005bd0 100644 --- a/tests/Feature/Notifications/NewPluginAvailableTest.php +++ b/tests/Feature/Notifications/NewPluginAvailableTest.php @@ -64,14 +64,26 @@ public function test_via_returns_empty_array_when_user_opted_out(): void $this->assertEmpty($notification->via($user)); } - public function test_via_returns_mail_and_database_when_user_opted_in(): void + public function test_via_returns_database_only_when_user_opted_in(): void { $user = User::factory()->create(['receives_new_plugin_notifications' => true]); $plugin = Plugin::factory()->for($user)->create(); $notification = new NewPluginAvailable($plugin); - $this->assertEquals(['mail', 'database'], $notification->via($user)); + $this->assertEquals(['database'], $notification->via($user)); + } + + public function test_via_never_includes_the_mail_channel(): void + { + $optedIn = User::factory()->create(['receives_new_plugin_notifications' => true]); + $optedOut = User::factory()->create(['receives_new_plugin_notifications' => false]); + $plugin = Plugin::factory()->create(); + + $notification = new NewPluginAvailable($plugin); + + $this->assertNotContains('mail', $notification->via($optedIn)); + $this->assertNotContains('mail', $notification->via($optedOut)); } public function test_mail_contains_plugin_name(): void