Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/Filament/Resources/PluginResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 4 additions & 1 deletion app/Notifications/NewPluginAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string>
*/
public function via(object $notifiable): array
Expand All @@ -27,7 +30,7 @@ public function via(object $notifiable): array
return [];
}

return ['mail', 'database'];
return ['database'];
}

public function toMail(object $notifiable): MailMessage
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/Filament/PluginResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 14 additions & 2 deletions tests/Feature/Notifications/NewPluginAvailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down