- Implemented the `show` page for managing URL apps with functionalities like updating name, logo, access URL, and connection status. - Added `UrlAppViewTest` for feature testing, ensuring role-based access, and validation of edit actions. - Updated navigation to route URL apps to their respective management views. - Enhanced `OidcService` to handle updated app settings and redirect URIs.
103 lines
3.5 KiB
PHP
103 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\{ConnectedApp, ConnectionProtocol, ConnectionStatus, User};
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->seed(Database\Seeders\PermissionSeeder::class);
|
|
$this->seed(Database\Seeders\DefaultRoleWithPermissionSeeder::class);
|
|
$this->seed(Database\Seeders\ConnectionProtocolSeeder::class);
|
|
$this->seed(Database\Seeders\ConnectionProviderSeeder::class);
|
|
$this->seed(Database\Seeders\ConnectionStatusSeeder::class);
|
|
|
|
$this->urlProtocol = ConnectionProtocol::query()->where('name', 'url')->firstOrFail();
|
|
$this->status = ConnectionStatus::query()->where('name', 'connected')->firstOrFail();
|
|
|
|
$this->connectedApp = ConnectedApp::query()->create([
|
|
'name' => 'Test URL App',
|
|
'slug' => 'test-url-app',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
'connection_provider_id' => 0,
|
|
'connection_status_id' => $this->status->id,
|
|
'settings' => [
|
|
'access_url' => 'https://test-url-app.example.com',
|
|
'is_connected_to_microsoft' => false,
|
|
],
|
|
]);
|
|
});
|
|
|
|
it('authorizes only admin users to view the URL show page', function (): void {
|
|
$user = User::factory()->create();
|
|
$user->assignRole('user');
|
|
|
|
Livewire::actingAs($user)
|
|
->test('pages::apps.url.show', ['id' => $this->connectedApp->id])
|
|
->assertForbidden();
|
|
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('admin');
|
|
|
|
Livewire::actingAs($admin)
|
|
->test('pages::apps.url.show', ['id' => $this->connectedApp->id])
|
|
->assertOk();
|
|
});
|
|
|
|
it('allows updating name and logo', function (): void {
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('admin');
|
|
|
|
$this->actingAs($admin);
|
|
|
|
$logo = Illuminate\Http\UploadedFile::fake()->image('logo.png');
|
|
|
|
Livewire::test('pages::apps.url.show', ['id' => $this->connectedApp->id])
|
|
->call('openEditGeneralModal')
|
|
->assertSet('editName', 'Test URL App')
|
|
->set('editName', 'Updated URL App Name')
|
|
->set('editLogo', $logo)
|
|
->call('saveGeneralInfo')
|
|
->assertHasNoErrors();
|
|
|
|
$this->connectedApp->refresh();
|
|
expect($this->connectedApp->name)->toBe('Updated URL App Name')
|
|
->and($this->connectedApp->logo)->not->toBeNull();
|
|
});
|
|
|
|
it('allows updating access URL in place', function (): void {
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('admin');
|
|
|
|
$this->actingAs($admin);
|
|
|
|
Livewire::test('pages::apps.url.show', ['id' => $this->connectedApp->id])
|
|
->call('startEditAccessUrl')
|
|
->assertSet('editAccessUrl', 'https://test-url-app.example.com')
|
|
->set('editAccessUrl', 'https://updated-url-app.example.com')
|
|
->call('saveAccessUrl')
|
|
->assertHasNoErrors();
|
|
|
|
$this->connectedApp->refresh();
|
|
expect(data_get($this->connectedApp->settings, 'access_url'))->toBe('https://updated-url-app.example.com');
|
|
});
|
|
|
|
it('allows updating connection status via changeStatus', function (): void {
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole('admin');
|
|
|
|
$this->actingAs($admin);
|
|
|
|
expect($this->connectedApp->status->name)->toBe('connected');
|
|
|
|
Livewire::test('pages::apps.url.show', ['id' => $this->connectedApp->id])
|
|
->call('changeStatus', 'disconnected')
|
|
->assertHasNoErrors();
|
|
|
|
$this->connectedApp->refresh();
|
|
expect($this->connectedApp->status->name)->toBe('disconnected');
|
|
});
|