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
31 changes: 31 additions & 0 deletions app/Filament/Resources/PluginResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Enums\PluginType;
use App\Filament\Resources\PluginResource\Pages;
use App\Filament\Resources\PluginResource\RelationManagers;
use App\Jobs\SyncPluginReleases;
use App\Models\Plugin;
use App\Models\PluginLicense;
use App\Models\User;
Expand Down Expand Up @@ -297,6 +298,36 @@ public static function table(Table $table): Table
->modalDescription(fn (Plugin $record) => "Grant '{$record->name}' to a user for free.")
->modalSubmitActionLabel('Grant'),

Tables\Actions\Action::make('convertToPaid')
->label('Convert to Paid')
->icon('heroicon-o-currency-dollar')
->color('success')
->visible(fn (Plugin $record) => $record->isFree())
->form([
Forms\Components\Select::make('tier')
->label('Pricing Tier')
->options(PluginTier::class)
->required()
->helperText('This sets the pricing for the plugin.'),
])
->action(function (Plugin $record, array $data): void {
$record->update([
'type' => PluginType::Paid,
'tier' => $data['tier'],
]);

SyncPluginReleases::dispatch($record);

Notification::make()
->title("Converted '{$record->name}' to paid")
->body('Plugin type updated, prices synced, and Satis ingestion queued.')
->success()
->send();
})
->modalHeading('Convert Plugin to Paid')
->modalDescription(fn (Plugin $record) => "This will convert '{$record->name}' from free to paid, set up pricing, and trigger a Satis build so it's available via Composer.")
->modalSubmitActionLabel('Convert & Ingest'),

Tables\Actions\ViewAction::make(),
])
->label('More')
Expand Down
71 changes: 71 additions & 0 deletions tests/Feature/Filament/ConvertPluginToPaidTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Tests\Feature\Filament;

use App\Enums\PluginTier;
use App\Enums\PluginType;
use App\Filament\Resources\PluginResource\Pages\ListPlugins;
use App\Jobs\SyncPluginReleases;
use App\Models\Plugin;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
use Tests\TestCase;

class ConvertPluginToPaidTest extends TestCase
{
use RefreshDatabase;

private User $admin;

protected function setUp(): void
{
parent::setUp();

$this->admin = User::factory()->create(['email' => 'admin@test.com']);
config(['filament.users' => ['admin@test.com']]);
}

public function test_convert_to_paid_changes_type_and_dispatches_satis(): void
{
Bus::fake([SyncPluginReleases::class]);

$plugin = Plugin::factory()->free()->approved()->create();

Livewire::actingAs($this->admin)
->test(ListPlugins::class)
->callTableAction('convertToPaid', $plugin, data: [
'tier' => PluginTier::Silver->value,
])
->assertNotified();

$plugin->refresh();

$this->assertEquals(PluginType::Paid, $plugin->type);
$this->assertEquals(PluginTier::Silver, $plugin->tier);
$this->assertTrue($plugin->prices()->exists());

Bus::assertDispatched(SyncPluginReleases::class, function ($job) use ($plugin) {
return $job->plugin->is($plugin);
});
}

public function test_convert_to_paid_is_not_visible_on_paid_plugins(): void
{
$plugin = Plugin::factory()->paid()->approved()->create();

Livewire::actingAs($this->admin)
->test(ListPlugins::class)
->assertTableActionHidden('convertToPaid', $plugin);
}

public function test_convert_to_paid_is_visible_on_free_plugins(): void
{
$plugin = Plugin::factory()->free()->approved()->create();

Livewire::actingAs($this->admin)
->test(ListPlugins::class)
->assertTableActionVisible('convertToPaid', $plugin);
}
}
Loading