- Introduced `StoreURLAppForm` and `StoreURLAppData` for form handling and data transformation. - Added `UrlAppService` to streamline URL app creation with settings like `accessUrl` and `isConnectedToMicrosoft`. - Enhanced user access controls with role-based permissions using `UserAccessTypeEnum`. - Updated UI for URL app creation with support for logos and dynamic role selection. - Implemented feature tests to validate URL app creation and access URL formatting.
108 lines
3.7 KiB
PHP
108 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\{ConnectedApp, ConnectionProtocol, ConnectionProvider, ConnectionStatus, User};
|
|
use App\Services\UserAppAccessService;
|
|
use Livewire\Livewire;
|
|
|
|
beforeEach(function (): void {
|
|
$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->provider = ConnectionProvider::query()->where('slug', 'azure-fd')->firstOrFail();
|
|
$this->status = ConnectionStatus::query()->where('name', 'connected')->firstOrFail();
|
|
});
|
|
|
|
it('successfully creates a connected app with URL protocol', function (): void {
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole(App\Models\Role::findOrCreate('Admin'));
|
|
|
|
$this->actingAs($admin);
|
|
|
|
Livewire::test('pages::connected-apps.create')
|
|
->set('form.name', 'Azure Portal')
|
|
->set('form.protocolId', $this->urlProtocol->id)
|
|
->set('form.providerId', $this->provider->id)
|
|
->set('form.statusId', $this->status->id)
|
|
->call('save');
|
|
|
|
$this->assertDatabaseHas('connected_apps', [
|
|
'name' => 'Azure Portal',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
]);
|
|
});
|
|
|
|
it('successfully edits a connected app with URL protocol', function (): void {
|
|
$admin = User::factory()->create();
|
|
$admin->assignRole(App\Models\Role::findOrCreate('Admin'));
|
|
|
|
$this->actingAs($admin);
|
|
|
|
$app = ConnectedApp::query()->create([
|
|
'name' => 'Azure Portal',
|
|
'slug' => 'azure-portal',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
'connection_provider_id' => $this->provider->id,
|
|
'connection_status_id' => $this->status->id,
|
|
]);
|
|
|
|
Livewire::test('pages::connected-apps.edit', ['id' => $app->id])
|
|
->set('form.name', 'Updated Azure Portal')
|
|
->call('save');
|
|
|
|
$app->refresh();
|
|
expect($app->name)->toBe('Updated Azure Portal');
|
|
});
|
|
|
|
it('maps URL protocol to ServiceAppDto in UserAppAccessService', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$app = ConnectedApp::query()->create([
|
|
'name' => 'Azure Portal',
|
|
'slug' => 'azure-portal',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
'connection_provider_id' => $this->provider->id,
|
|
'connection_status_id' => $this->status->id,
|
|
]);
|
|
|
|
$role = App\Models\Role::findOrCreate('Standard User');
|
|
$role->update(['priority' => 10]);
|
|
$role->apps()->attach($app->id, ['duration' => now()->addYear()->toDateTimeString()]);
|
|
|
|
$user->assignRole($role);
|
|
|
|
$service = app(UserAppAccessService::class);
|
|
$activeServices = $service->getActiveServices($user);
|
|
|
|
expect($activeServices->count())->toBe(1);
|
|
|
|
$dto = $activeServices->first();
|
|
expect($dto->protocolName)->toBe('url')
|
|
->and($dto->providerSlug)->toBe('azure-fd');
|
|
});
|
|
|
|
it('shows newly created connected apps with no roles in searchAppsForSelect dropdown', function (): void {
|
|
$admin = User::factory()->create();
|
|
$role = App\Models\Role::findOrCreate('Admin');
|
|
$role->update(['priority' => 1]);
|
|
$admin->assignRole($role);
|
|
|
|
$this->actingAs($admin);
|
|
|
|
$app = ConnectedApp::query()->create([
|
|
'name' => 'Brand New App',
|
|
'slug' => 'brand-new-app',
|
|
'connection_protocol_id' => $this->urlProtocol->id,
|
|
'connection_provider_id' => $this->provider->id,
|
|
'connection_status_id' => $this->status->id,
|
|
]);
|
|
|
|
$appRoleService = app(App\Services\AppRoleService::class);
|
|
$apps = $appRoleService->searchAppsForSelect('');
|
|
|
|
expect($apps->pluck('id')->toArray())->toContain($app->id);
|
|
});
|