Files
coolify/tests/Feature/GitlabRepositoryListingTest.php
T
Andras BacsaiandClaude Opus 5.5 a79ee909c6 chore: remove unused components and markup-only tests
- Delete Blade components, component classes, Livewire components and
  views that nothing uses after the redesign.
- Delete tests that only compare Blade/CSS source text; keep the source
  checks for authorization gates, stable wire:key values and escaping.
- Update stale tests to the current UI and behaviour.
- Update DESIGN.md to the current navigation and layout.
- Add a lesson: test behaviour, not source markup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 00:18:16 +02:00

62 lines
2.2 KiB
PHP

<?php
use App\Models\GitlabApp;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Facades\Http;
beforeEach(function () {
Model::encryptUsing(new Encrypter(str_repeat('a', 32), 'AES-256-CBC'));
});
afterEach(function () {
Model::encryptUsing(null);
});
/**
* Http::GitSource() pins DNS before Http::fake() answers, so use a public IP
* literal that needs no DNS lookup. No request leaves the test.
*/
function gitlabListingApiUrl(): string
{
return 'https://1.1.1.1/api/v4';
}
it('returns a stable shape with has_more false when GitLab repo listing fails', function () {
Http::fake(['*' => Http::response(['message' => '401 Unauthorized'], 401)]);
$source = new GitlabApp([
'api_url' => gitlabListingApiUrl(),
'access_token' => str_repeat('t', 20), // ggignore
'refresh_token' => str_repeat('r', 20), // ggignore
'expires_at' => time() + 3600,
]);
$result = loadGitlabRepositories($source);
expect($result)->toHaveKeys(['total_count', 'has_more', 'repositories']);
expect($result['has_more'])->toBeFalse();
expect($result['repositories'])->toBe([]);
});
it('limits GitLab repositories to the exact group and its descendants', function () {
Http::fake(['*' => Http::response([
['id' => 1, 'name' => 'a', 'path_with_namespace' => 'team/a', 'namespace' => ['full_path' => 'team', 'kind' => 'group']],
['id' => 2, 'name' => 'b', 'path_with_namespace' => 'team/sub/b', 'namespace' => ['full_path' => 'team/sub', 'kind' => 'group']],
['id' => 3, 'name' => 'c', 'path_with_namespace' => 'team-secret/c', 'namespace' => ['full_path' => 'team-secret', 'kind' => 'group']],
], 200)]);
$source = new GitlabApp([
'api_url' => gitlabListingApiUrl(),
'access_token' => str_repeat('t', 20), // ggignore
'refresh_token' => str_repeat('r', 20), // ggignore
'expires_at' => time() + 3600,
'group_name' => 'team',
]);
$paths = collect(loadGitlabRepositories($source)['repositories'])->pluck('path_with_namespace')->all();
expect($paths)->toContain('team/a', 'team/sub/b');
expect($paths)->not->toContain('team-secret/c');
});