85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
|
|
use App\Filament\Resources\PolicyResource;
|
|
use App\Models\AuditLog;
|
|
use App\Models\Policy;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\Graph\GraphClientInterface;
|
|
use App\Services\Graph\GraphResponse;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('bulk sync updates selected policies from graph', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
$policies = Policy::factory()
|
|
->count(3)
|
|
->create([
|
|
'tenant_id' => $tenant->id,
|
|
'policy_type' => 'deviceConfiguration',
|
|
'platform' => 'windows10AndLater',
|
|
'last_synced_at' => null,
|
|
]);
|
|
|
|
app()->bind(GraphClientInterface::class, fn () => new class implements GraphClientInterface
|
|
{
|
|
public function listPolicies(string $policyType, array $options = []): GraphResponse
|
|
{
|
|
return new GraphResponse(true, []);
|
|
}
|
|
|
|
public function getPolicy(string $policyType, string $policyId, array $options = []): GraphResponse
|
|
{
|
|
return new GraphResponse(true, [
|
|
'payload' => [
|
|
'id' => $policyId,
|
|
'displayName' => "Synced {$policyId}",
|
|
'platform' => $options['platform'] ?? null,
|
|
'example' => 'value',
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function getOrganization(array $options = []): GraphResponse
|
|
{
|
|
return new GraphResponse(true, []);
|
|
}
|
|
|
|
public function applyPolicy(string $policyType, string $policyId, array $payload, array $options = []): GraphResponse
|
|
{
|
|
return new GraphResponse(true, []);
|
|
}
|
|
|
|
public function getServicePrincipalPermissions(array $options = []): GraphResponse
|
|
{
|
|
return new GraphResponse(true, []);
|
|
}
|
|
|
|
public function request(string $method, string $path, array $options = []): GraphResponse
|
|
{
|
|
return new GraphResponse(true, []);
|
|
}
|
|
});
|
|
|
|
Livewire::actingAs($user)
|
|
->test(PolicyResource\Pages\ListPolicies::class)
|
|
->callTableBulkAction('bulk_sync', $policies)
|
|
->assertHasNoTableBulkActionErrors();
|
|
|
|
$policies->each(function (Policy $policy) {
|
|
$policy->refresh();
|
|
|
|
expect($policy->last_synced_at)->not->toBeNull();
|
|
expect($policy->display_name)->toBe("Synced {$policy->external_id}");
|
|
expect($policy->metadata)->toMatchArray([
|
|
'example' => 'value',
|
|
]);
|
|
});
|
|
|
|
expect(AuditLog::where('action', 'bulk.policy.sync.completed')->exists())->toBeTrue();
|
|
});
|