Files
CABM-IT/tests/Feature/OrganizationIdentityCardTest.php
T
mrKamooandClaude Sonnet 5 3c87ced1e4 Ajoute fiche d'identité informatique, catalogue prestataires et schémas draw.io
- Fiche d'identité par organisation (technicien référent, FAI, IP publiques,
  prestataires liés) accessible depuis un nouveau menu.
- Nouveau module Prestataires dédié (catalogue léger réutilisable entre
  communes, avec journal de suivi des échanges) plutôt que de détourner les
  organisations de type "Fournisseur".
- Nouveau menu Infrastructure par organisation avec schémas réseau/fonctionnel
  édités via draw.io embarqué (URL configurable, cf. réglages admin).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-21 15:55:23 +02:00

158 lines
5.6 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Organization;
use App\Models\Provider;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class OrganizationIdentityCardTest extends TestCase
{
use RefreshDatabase;
public function test_identity_card_page_renders_for_an_authenticated_user(): void
{
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
$user = User::factory()->create();
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
$response = $this->actingAs($user)->get(route('organizations.identity-card', $org));
$response->assertOk();
$response->assertSee("Fiche d'identité informatique");
}
public function test_can_save_identity_fields_and_link_a_provider(): void
{
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
$user = User::factory()->create();
$technician = User::factory()->create();
$technician->assignRole('Technicien');
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
$provider = Provider::create(['name' => 'Orange Pro']);
$this->actingAs($user);
Livewire::test('organizations.identity-card', ['organization' => $org])
->set('technicianUserId', $technician->id)
->set('ispName', 'Orange Pro')
->set('publicIpsText', "203.0.113.10\n203.0.113.11")
->call('save')
->assertHasNoErrors();
$org->refresh();
$this->assertSame($technician->id, $org->technician_user_id);
$this->assertSame('Orange Pro', $org->isp_name);
$this->assertSame(['203.0.113.10', '203.0.113.11'], $org->public_ips);
Livewire::test('organizations.identity-card', ['organization' => $org])
->set('newProviderId', $provider->id)
->set('newProviderLabel', 'Téléphonie')
->call('addProvider')
->assertHasNoErrors();
$this->assertCount(1, $org->providers()->get());
$pivotId = $org->providers()->first()->pivot->id;
Livewire::test('organizations.identity-card', ['organization' => $org])
->call('removeProvider', $pivotId);
$this->assertCount(0, $org->providers()->get());
}
public function test_clearing_the_technician_select_nulls_it_out(): void
{
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
$user = User::factory()->create();
$technician = User::factory()->create();
$technician->assignRole('Technicien');
$org = Organization::create([
'name' => 'Test Commune',
'slug' => 'test-commune',
'org_type' => 'client',
'technician_user_id' => $technician->id,
]);
$this->actingAs($user);
Livewire::test('organizations.identity-card', ['organization' => $org])
->assertSet('technicianUserId', $technician->id)
->set('technicianUserId', '')
->call('save')
->assertHasNoErrors();
$this->assertNull($org->refresh()->technician_user_id);
}
public function test_duplicate_provider_link_with_same_label_is_rejected(): void
{
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
$user = User::factory()->create();
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
$provider = Provider::create(['name' => 'Orange Pro']);
$this->actingAs($user);
$org->providers()->attach($provider->id, ['label' => 'Téléphonie']);
Livewire::test('organizations.identity-card', ['organization' => $org])
->set('newProviderId', $provider->id)
->set('newProviderLabel', 'Téléphonie')
->call('addProvider')
->assertHasErrors('newProviderId');
$this->assertCount(1, $org->providers()->get());
}
public function test_duplicate_provider_link_without_a_label_is_rejected(): void
{
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
$user = User::factory()->create();
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
$provider = Provider::create(['name' => 'Orange Pro']);
$this->actingAs($user);
$org->providers()->attach($provider->id, ['label' => null]);
Livewire::test('organizations.identity-card', ['organization' => $org])
->set('newProviderId', $provider->id)
->set('newProviderLabel', '')
->call('addProvider')
->assertHasErrors('newProviderId');
$this->assertCount(1, $org->providers()->get());
}
public function test_removing_a_provider_link_is_scoped_to_its_own_organization(): void
{
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
$user = User::factory()->create();
$orgA = Organization::create(['name' => 'Commune A', 'slug' => 'commune-a', 'org_type' => 'client']);
$orgB = Organization::create(['name' => 'Commune B', 'slug' => 'commune-b', 'org_type' => 'client']);
$provider = Provider::create(['name' => 'Orange Pro']);
$orgA->providers()->attach($provider->id, ['label' => null]);
$pivotIdA = $orgA->providers()->first()->pivot->id;
$this->actingAs($user);
Livewire::test('organizations.identity-card', ['organization' => $orgB])
->call('removeProvider', $pivotIdA);
$this->assertCount(1, $orgA->providers()->get());
}
}