TenantAtlas/tests/Unit/Providers/ProviderGatewayTest.php
ahmido a0ed9e24c5 feat: unify provider connection actions and notifications (#73)
## Summary
- introduce the Provider Connection Filament resource (list/create/edit) with DB-only controls, grouped action dropdowns, and badge-driven status/health rendering
- wire up the provider foundation stack (migrations, models, policies, providers, operations, badges, and audits) plus the required spec docs/checklists
- standardize Inventory Sync notifications so the job no longer writes its own DB rows; terminal notifications now flow exclusively through OperationRunCompleted while the start surface still shows the queued toast

## Testing
- ./vendor/bin/sail php ./vendor/bin/pint --dirty
- ./vendor/bin/sail artisan test tests/Unit/Badges/ProviderConnectionBadgesTest.php
- ./vendor/bin/sail artisan test tests/Feature/ProviderConnections tests/Feature/Filament/ProviderConnectionsDbOnlyTest.php
- ./vendor/bin/sail artisan test tests/Feature/Inventory/RunInventorySyncJobTest.php tests/Feature/Inventory/InventorySyncStartSurfaceTest.php

Co-authored-by: Ahmed Darrazi <ahmeddarrazi@MacBookPro.fritz.box>
Reviewed-on: #73
2026-01-25 01:01:37 +00:00

97 lines
3.4 KiB
PHP

<?php
use App\Models\ProviderConnection;
use App\Models\ProviderCredential;
use App\Services\Graph\GraphClientInterface;
use App\Services\Graph\GraphResponse;
use App\Services\Providers\CredentialManager;
use App\Services\Providers\ProviderGateway;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
it('builds per-request graph context from a provider connection + credentials', function (): void {
$connection = ProviderConnection::factory()->create([
'entra_tenant_id' => 'entra-tenant-id',
]);
ProviderCredential::factory()->create([
'provider_connection_id' => $connection->getKey(),
'payload' => [
'client_id' => 'client-id',
'client_secret' => 'client-secret',
],
]);
$graph = new class implements GraphClientInterface
{
public array $calls = [];
public function listPolicies(string $policyType, array $options = []): GraphResponse
{
$this->calls[] = ['fn' => 'listPolicies', 'policyType' => $policyType, 'options' => $options];
return new GraphResponse(true);
}
public function getPolicy(string $policyType, string $policyId, array $options = []): GraphResponse
{
$this->calls[] = ['fn' => 'getPolicy', 'policyType' => $policyType, 'policyId' => $policyId, 'options' => $options];
return new GraphResponse(true);
}
public function getOrganization(array $options = []): GraphResponse
{
$this->calls[] = ['fn' => 'getOrganization', 'options' => $options];
return new GraphResponse(true);
}
public function applyPolicy(string $policyType, string $policyId, array $payload, array $options = []): GraphResponse
{
$this->calls[] = ['fn' => 'applyPolicy', 'policyType' => $policyType, 'policyId' => $policyId, 'payload' => $payload, 'options' => $options];
return new GraphResponse(true);
}
public function getServicePrincipalPermissions(array $options = []): GraphResponse
{
$this->calls[] = ['fn' => 'getServicePrincipalPermissions', 'options' => $options];
return new GraphResponse(true);
}
public function request(string $method, string $path, array $options = []): GraphResponse
{
$this->calls[] = ['fn' => 'request', 'method' => $method, 'path' => $path, 'options' => $options];
return new GraphResponse(true);
}
};
$gateway = new ProviderGateway(
graph: $graph,
credentials: app(CredentialManager::class),
);
$gateway->getOrganization($connection);
$gateway->request($connection, 'GET', 'organization', ['query' => ['a' => 'b']]);
expect($graph->calls)->toHaveCount(2);
$first = $graph->calls[0]['options'];
$second = $graph->calls[1]['options'];
expect($first['tenant'])->toBe('entra-tenant-id');
expect($first['client_id'])->toBe('client-id');
expect($first['client_secret'])->toBe('client-secret');
expect($first['client_request_id'])->toBeString()->not->toBeEmpty();
expect($second['tenant'])->toBe('entra-tenant-id');
expect($second['client_id'])->toBe('client-id');
expect($second['client_secret'])->toBe('client-secret');
expect($second['client_request_id'])->toBeString()->not->toBeEmpty();
expect($second['query'])->toBe(['a' => 'b']);
});