0]); $this->team = Team::factory()->create(); $this->user = User::factory()->create(); $this->team->members()->attach($this->user->id, ['role' => 'owner']); $this->actingAs($this->user); session(['currentTeam' => $this->team]); $privateKeyId = DB::table('private_keys')->insertGetId([ 'uuid' => fake()->uuid(), 'name' => 'test-key', 'private_key' => encrypt('test-key-content'), 'team_id' => $this->team->id, 'created_at' => now(), 'updated_at' => now(), ]); $this->githubApp = GithubApp::create([ 'name' => 'Test App', 'app_id' => 123456, 'installation_id' => null, 'client_id' => 'Iv1.abc', 'client_secret' => 'secret', 'webhook_secret' => 'hook-secret', 'private_key_id' => $privateKeyId, 'team_id' => $this->team->id, 'api_url' => 'https://api.github.com', 'html_url' => 'https://github.com', 'organization' => 'test-org', 'organization_self_hosted_runners' => 'write', ]); $this->server = Server::factory()->create([ 'team_id' => $this->team->id, 'private_key_id' => $privateKeyId, ]); }); it('stores the normalized runner group name when saving github runner config', function () { Livewire::test(GithubRunners::class, ['server_uuid' => $this->server->uuid]) ->set('selectedGithubAppId', $this->githubApp->id) ->set('runnerGroupName', ' Team Runners Primary ') ->call('submit') ->assertHasNoErrors(); $this->githubApp->refresh(); expect($this->githubApp->runner_group_name)->toBe('Team Runners Primary'); }); it('generates a default runner group name when the field is empty', function () { $this->githubApp->update(['runner_group_name' => 'Existing Name']); Livewire::test(GithubRunners::class, ['server_uuid' => $this->server->uuid]) ->set('selectedGithubAppId', $this->githubApp->id) ->set('runnerGroupName', ' ') ->call('submit') ->assertHasNoErrors(); $this->githubApp->refresh(); expect($this->githubApp->runner_group_name)->toStartWith('Coolify-'); }); it('syncs runner group name to github api when saving from ui', function () use ($validKey) { $validPrivateKey = PrivateKey::create([ 'name' => 'valid-runner-key', 'private_key' => $validKey, 'team_id' => $this->team->id, ]); $this->githubApp->update([ 'installation_id' => 222, 'private_key_id' => $validPrivateKey->id, 'runner_group_id' => 88, 'runner_group_name' => 'Old Name', ]); GithubRunnerConfig::create([ 'server_id' => $this->server->id, 'github_app_id' => $this->githubApp->id, 'labels' => ['self-hosted', 'coolify'], 'max_runners' => 4, 'capacity_wait_timeout' => 60, 'runner_user' => 'runner', 'runner_base_dir' => '/opt/github-runners', 'is_enabled' => true, ]); Http::preventStrayRequests(); Http::fake([ 'https://api.github.com/zen' => Http::response('Keep it logically awesome.', 200, ['Date' => now()->toRfc7231String()]), 'https://api.github.com/app/installations/222/access_tokens' => Http::response(['token' => 'ghs_test_token'], 200), 'https://api.github.com/orgs/test-org/actions/runner-groups/88' => Http::response([], 200), ]); Livewire::test(GithubRunners::class, ['server_uuid' => $this->server->uuid]) ->assertSet('selectedGithubAppId', $this->githubApp->id) ->set('selectedGithubAppId', $this->githubApp->id) ->set('runnerGroupName', 'New Synced Name') ->call('submit') ->assertHasNoErrors(); $this->githubApp->refresh(); expect($this->githubApp->runner_group_name)->toBe('New Synced Name'); $recordedRequests = collect(Http::recorded()) ->map(fn (array $entry) => $entry[0]->method().' '.$entry[0]->url()) ->values() ->all(); \PHPUnit\Framework\Assert::assertContains( 'PATCH https://api.github.com/orgs/test-org/actions/runner-groups/88', $recordedRequests, 'Recorded requests: '.json_encode($recordedRequests) ); }); it('does not sync runner group name to github api when field is not dirty', function () use ($validKey) { $validPrivateKey = PrivateKey::create([ 'name' => 'valid-runner-key-no-dirty', 'private_key' => $validKey, 'team_id' => $this->team->id, ]); $this->githubApp->update([ 'installation_id' => 222, 'private_key_id' => $validPrivateKey->id, 'runner_group_id' => 88, 'runner_group_name' => 'Same Name', ]); GithubRunnerConfig::create([ 'server_id' => $this->server->id, 'github_app_id' => $this->githubApp->id, 'labels' => ['self-hosted', 'coolify'], 'max_runners' => 4, 'capacity_wait_timeout' => 60, 'runner_user' => 'runner', 'runner_base_dir' => '/opt/github-runners', 'is_enabled' => true, ]); Http::preventStrayRequests(); Http::fake(); Livewire::test(GithubRunners::class, ['server_uuid' => $this->server->uuid]) ->assertSet('selectedGithubAppId', $this->githubApp->id) ->assertSet('runnerGroupName', 'Same Name') ->call('submit') ->assertHasNoErrors(); Http::assertNothingSent(); }); it('generates and syncs a default runner group name to github when field is empty', function () use ($validKey) { $validPrivateKey = PrivateKey::create([ 'name' => 'valid-runner-key-empty-sync', 'private_key' => $validKey, 'team_id' => $this->team->id, ]); $this->githubApp->update([ 'installation_id' => 222, 'private_key_id' => $validPrivateKey->id, 'runner_group_id' => 88, 'runner_group_name' => 'Existing Name', ]); GithubRunnerConfig::create([ 'server_id' => $this->server->id, 'github_app_id' => $this->githubApp->id, 'labels' => ['self-hosted', 'coolify'], 'max_runners' => 4, 'capacity_wait_timeout' => 60, 'runner_user' => 'runner', 'runner_base_dir' => '/opt/github-runners', 'is_enabled' => true, ]); Http::preventStrayRequests(); Http::fake([ 'https://api.github.com/zen' => Http::response('Keep it logically awesome.', 200, ['Date' => now()->toRfc7231String()]), 'https://api.github.com/app/installations/222/access_tokens' => Http::response(['token' => 'ghs_test_token'], 200), 'https://api.github.com/orgs/test-org/actions/runner-groups/88' => Http::response([], 200), ]); Livewire::test(GithubRunners::class, ['server_uuid' => $this->server->uuid]) ->assertSet('selectedGithubAppId', $this->githubApp->id) ->set('runnerGroupName', ' ') ->call('submit') ->assertHasNoErrors(); $this->githubApp->refresh(); expect($this->githubApp->runner_group_name)->toStartWith('Coolify-'); $recordedRequests = collect(Http::recorded()) ->map(fn (array $entry) => $entry[0]->method().' '.$entry[0]->url()) ->values() ->all(); \PHPUnit\Framework\Assert::assertContains( 'PATCH https://api.github.com/orgs/test-org/actions/runner-groups/88', $recordedRequests, 'Recorded requests: '.json_encode($recordedRequests) ); });