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
11 changes: 8 additions & 3 deletions app/Services/SatisService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services;

use App\Enums\PluginType;
use App\Models\Plugin;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
Expand All @@ -25,7 +26,7 @@ public function buildAll(?string $githubToken = null): array
{
$plugins = $this->getApprovedPlugins();

return $this->triggerBuild($plugins, $githubToken);
return $this->triggerBuild($plugins, $githubToken, fullBuild: true);
}

/**
Expand Down Expand Up @@ -107,6 +108,7 @@ protected function getApprovedPlugins(): array
{
return Plugin::query()
->approved()
->where('type', PluginType::Paid)
->get()
->map(fn (Plugin $plugin) => [
'name' => $plugin->name,
Expand All @@ -120,7 +122,7 @@ protected function getApprovedPlugins(): array
/**
* @param array<int, array{name: string, repository_url: string, type: string, is_official?: bool}> $plugins
*/
protected function triggerBuild(array $plugins, ?string $githubToken = null): array
protected function triggerBuild(array $plugins, ?string $githubToken = null, bool $fullBuild = false): array
{
if (! $this->apiUrl || ! $this->apiKey) {
return [
Expand All @@ -139,7 +141,10 @@ protected function triggerBuild(array $plugins, ?string $githubToken = null): ar
$githubToken ??= config('services.github.token');

try {
$payload = ['plugins' => $plugins];
$payload = [
'plugins' => $plugins,
'full_build' => $fullBuild,
];

if ($githubToken) {
$payload['github_token'] = $githubToken;
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/SatisSync/SatisSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Services\SatisService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Http;
use Livewire\Livewire;
use Tests\TestCase;

Expand Down Expand Up @@ -124,4 +125,29 @@ public function test_is_satis_synced_returns_true_when_synced(): void

$this->assertTrue($plugin->isSatisSynced());
}

public function test_build_all_only_includes_paid_plugins(): void
{
Http::fake(['*' => Http::response(['job_id' => 'test-123', 'message' => 'Build started'], 200)]);

config(['services.satis.url' => 'https://satis.test', 'services.satis.api_key' => 'test-key']);

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

$service = new SatisService;
$result = $service->buildAll();

$this->assertTrue($result['success']);
$this->assertEquals(1, $result['plugins_count']);

Http::assertSent(function ($request) use ($paidPlugin) {
$data = $request->data();
$plugins = $data['plugins'] ?? [];

return count($plugins) === 1
&& $plugins[0]['name'] === $paidPlugin->name
&& $data['full_build'] === true;
});
}
}
Loading