104 lines
3.2 KiB
PHP
104 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Filament\Resources\BackupSetResource;
|
|
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('backup creation captures snapshots and audit log', function () {
|
|
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' => ['policyId' => $policyId, 'type' => $policyType]]);
|
|
}
|
|
|
|
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, []);
|
|
}
|
|
});
|
|
|
|
$tenant = Tenant::create([
|
|
'tenant_id' => env('INTUNE_TENANT_ID', 'local-tenant'),
|
|
'name' => 'Tenant One',
|
|
'metadata' => [],
|
|
]);
|
|
|
|
$tenant->makeCurrent();
|
|
|
|
$policyA = Policy::create([
|
|
'tenant_id' => $tenant->id,
|
|
'external_id' => 'policy-1',
|
|
'policy_type' => 'deviceConfiguration',
|
|
'display_name' => 'Policy A',
|
|
'platform' => 'windows',
|
|
]);
|
|
|
|
$policyB = Policy::create([
|
|
'tenant_id' => $tenant->id,
|
|
'external_id' => 'policy-2',
|
|
'policy_type' => 'deviceCompliancePolicy',
|
|
'display_name' => 'Policy B',
|
|
'platform' => 'windows',
|
|
]);
|
|
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$backupSet = BackupSetResource::createBackupSet([
|
|
'name' => 'Test backup',
|
|
]);
|
|
|
|
Livewire::test(\App\Filament\Resources\BackupSetResource\RelationManagers\BackupItemsRelationManager::class, [
|
|
'ownerRecord' => $backupSet,
|
|
'pageClass' => \App\Filament\Resources\BackupSetResource\Pages\ViewBackupSet::class,
|
|
])->callTableAction('addPolicies', data: [
|
|
'policy_ids' => [$policyA->id, $policyB->id],
|
|
]);
|
|
|
|
$backupSet->refresh();
|
|
|
|
expect($backupSet->item_count)->toBe(2);
|
|
expect($backupSet->items)->toHaveCount(2);
|
|
expect($backupSet->items->first()->payload['policyId'])->toBe('policy-1');
|
|
|
|
$this->assertDatabaseHas('audit_logs', [
|
|
'action' => 'backup.created',
|
|
'resource_type' => 'backup_set',
|
|
'resource_id' => (string) $backupSet->id,
|
|
]);
|
|
|
|
$this->assertDatabaseHas('audit_logs', [
|
|
'action' => 'backup.items_added',
|
|
'resource_type' => 'backup_set',
|
|
'resource_id' => (string) $backupSet->id,
|
|
]);
|
|
});
|