60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\Graph\DirectorySync;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class AdminSyncTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private Tenant $tenant;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
config(['signature.admin_allowed_cidrs' => []]);
|
|
$this->tenant = Tenant::create(['name' => 'CABM', 'entra_tenant_id' => '11111111-1111-1111-1111-111111111111']);
|
|
|
|
// Pas d'appel Graph en test : la synchro est simulée.
|
|
$this->app->instance(DirectorySync::class, new class extends DirectorySync {
|
|
public array $calls = [];
|
|
|
|
public function run(Tenant $tenant, bool $full = false): array
|
|
{
|
|
$this->calls[] = $full;
|
|
|
|
return ['users' => 3, 'removed' => 1, 'groups' => 2, 'memberships' => 5];
|
|
}
|
|
});
|
|
}
|
|
|
|
private function user(string $role): User
|
|
{
|
|
return User::create(['name' => $role, 'email' => "{$role}@x.fr", 'tenant_id' => $this->tenant->id, 'entra_oid' => '22222222-2222-2222-2222-222222222222', 'role' => $role]);
|
|
}
|
|
|
|
public function test_admin_lance_une_synchro_complete(): void
|
|
{
|
|
$this->actingAs($this->user('admin'))->from('/admin')->post('/admin/synchro', ['full' => '1'])
|
|
->assertRedirect('/admin')
|
|
->assertSessionHas('status', 'Synchronisation complète terminée : 3 agents mis à jour, 1 retirés, 2 groupes, 5 appartenances.');
|
|
|
|
$this->assertSame([true], app(DirectorySync::class)->calls);
|
|
}
|
|
|
|
public function test_editeur_ne_peut_pas_synchroniser(): void
|
|
{
|
|
$this->actingAs($this->user('editor'))->post('/admin/synchro')->assertForbidden();
|
|
}
|
|
|
|
public function test_bouton_visible_sur_le_tableau_de_bord(): void
|
|
{
|
|
$this->actingAs($this->user('admin'))->get('/admin')->assertOk()->assertSee('Synchroniser maintenant');
|
|
}
|
|
}
|