From 12cc3f27f850fb1e06c1d4fc3e73c4499f369421 Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Tue, 22 Sep 2026 14:12:03 +0200 Subject: [PATCH] Add check for premium to telemetry and update lookup --- app/Service/ApiService.php | 8 ++++++++ .../SelfHost/SelfHostCheckForUpdateCommandTest.php | 6 ++++++ .../Commands/SelfHost/SelfHostTelemetryCommandTest.php | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/app/Service/ApiService.php b/app/Service/ApiService.php index 8dd4aea8..7ded19a6 100644 --- a/app/Service/ApiService.php +++ b/app/Service/ApiService.php @@ -15,12 +15,18 @@ use App\Models\User; use Exception; use Illuminate\Support\Facades\Http; use Log; +use Nwidart\Modules\Facades\Module; use Throwable; class ApiService { private const string API_URL = 'https://app.solidtime.io/api/v1'; + private function isPremium(): bool + { + return Module::has('Invoicing'); + } + public function checkForUpdate(): ?string { try { @@ -31,6 +37,7 @@ class ApiService 'version' => config('app.version'), 'build' => config('app.build'), 'url' => config('app.url'), + 'is_premium' => $this->isPremium(), ]); if ($response->status() === 200 && isset($response->json()['version']) && is_string($response->json()['version'])) { @@ -62,6 +69,7 @@ class ApiService 'version' => config('app.version'), 'build' => config('app.build'), 'url' => config('app.url'), + 'is_premium' => $this->isPremium(), // telemetry data 'user_count' => User::count(), 'organization_count' => Organization::count(), diff --git a/tests/Unit/Console/Commands/SelfHost/SelfHostCheckForUpdateCommandTest.php b/tests/Unit/Console/Commands/SelfHost/SelfHostCheckForUpdateCommandTest.php index 880334c8..9c2c4d9a 100644 --- a/tests/Unit/Console/Commands/SelfHost/SelfHostCheckForUpdateCommandTest.php +++ b/tests/Unit/Console/Commands/SelfHost/SelfHostCheckForUpdateCommandTest.php @@ -9,6 +9,7 @@ use App\Service\ApiService; use Cache; use Illuminate\Console\Command; use Illuminate\Http\Client\ConnectionException; +use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Http; use PHPUnit\Framework\Attributes\CoversClass; @@ -32,6 +33,11 @@ class SelfHostCheckForUpdateCommandTest extends TestCase $this->assertSame(Command::SUCCESS, $exitCode); $output = Artisan::output(); $this->assertSame('1.2.3', Cache::get('latest_version')); + Http::assertSent(function (Request $request): bool { + $data = $request->data(); + + return array_key_exists('is_premium', $data) && is_bool($data['is_premium']); + }); } public function test_checks_for_update_fails_gracefully_if_response_has_error_status_code(): void diff --git a/tests/Unit/Console/Commands/SelfHost/SelfHostTelemetryCommandTest.php b/tests/Unit/Console/Commands/SelfHost/SelfHostTelemetryCommandTest.php index 1507c628..cc9494a4 100644 --- a/tests/Unit/Console/Commands/SelfHost/SelfHostTelemetryCommandTest.php +++ b/tests/Unit/Console/Commands/SelfHost/SelfHostTelemetryCommandTest.php @@ -8,6 +8,7 @@ use App\Console\Commands\SelfHost\SelfHostTelemetryCommand; use App\Service\ApiService; use Illuminate\Console\Command; use Illuminate\Http\Client\ConnectionException; +use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Http; use PHPUnit\Framework\Attributes\CoversClass; @@ -31,6 +32,11 @@ class SelfHostTelemetryCommandTest extends TestCase $this->assertSame(Command::SUCCESS, $exitCode); $output = Artisan::output(); $this->assertSame('', $output); + Http::assertSent(function (Request $request): bool { + $data = $request->data(); + + return array_key_exists('is_premium', $data) && is_bool($data['is_premium']); + }); } public function test_telemetry_sends_fails_gracefully_if_response_has_error_status_code(): void