## Summary <!-- Kurz: Was ändert sich und warum? --> ## Spec-Driven Development (SDD) - [ ] Es gibt eine Spec unter `specs/<NNN>-<feature>/` - [ ] Enthaltene Dateien: `plan.md`, `tasks.md`, `spec.md` - [ ] Spec beschreibt Verhalten/Acceptance Criteria (nicht nur Implementation) - [ ] Wenn sich Anforderungen während der Umsetzung geändert haben: Spec/Plan/Tasks wurden aktualisiert ## Implementation - [ ] Implementierung entspricht der Spec - [ ] Edge cases / Fehlerfälle berücksichtigt - [ ] Keine unbeabsichtigten Änderungen außerhalb des Scopes ## Tests - [ ] Tests ergänzt/aktualisiert (Pest/PHPUnit) - [ ] Relevante Tests lokal ausgeführt (`./vendor/bin/sail artisan test` oder `php artisan test`) ## Migration / Config / Ops (falls relevant) - [ ] Migration(en) enthalten und getestet - [ ] Rollback bedacht (rückwärts kompatibel, sichere Migration) - [ ] Neue Env Vars dokumentiert (`.env.example` / Doku) - [ ] Queue/cron/storage Auswirkungen geprüft ## UI (Filament/Livewire) (falls relevant) - [ ] UI-Flows geprüft - [ ] Screenshots/Notizen hinzugefügt ## Notes <!-- Links, Screenshots, Follow-ups, offene Punkte --> Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local> Reviewed-on: #4
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Services\Graph\AssignmentFilterResolver;
|
|
use App\Services\Graph\GraphResponse;
|
|
use App\Services\Graph\MicrosoftGraphClient;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
Cache::flush();
|
|
$this->graphClient = Mockery::mock(MicrosoftGraphClient::class);
|
|
$this->resolver = new AssignmentFilterResolver($this->graphClient);
|
|
});
|
|
|
|
test('resolves assignment filters by id', function () {
|
|
$filters = [
|
|
['id' => 'filter-1', 'displayName' => 'Targeted Devices'],
|
|
['id' => 'filter-2', 'displayName' => 'Excluded Devices'],
|
|
];
|
|
|
|
$response = new GraphResponse(
|
|
success: true,
|
|
data: ['value' => $filters]
|
|
);
|
|
|
|
$this->graphClient
|
|
->shouldReceive('request')
|
|
->once()
|
|
->with('GET', '/deviceManagement/assignmentFilters', [
|
|
'query' => [
|
|
'$select' => 'id,displayName',
|
|
],
|
|
])
|
|
->andReturn($response);
|
|
|
|
$result = $this->resolver->resolve(['filter-1']);
|
|
|
|
expect($result)->toHaveCount(1)
|
|
->and($result[0]['id'])->toBe('filter-1')
|
|
->and($result[0]['displayName'])->toBe('Targeted Devices');
|
|
});
|
|
|
|
test('uses cache for repeated lookups', function () {
|
|
$filters = [
|
|
['id' => 'filter-1', 'displayName' => 'Targeted Devices'],
|
|
];
|
|
|
|
$response = new GraphResponse(
|
|
success: true,
|
|
data: ['value' => $filters]
|
|
);
|
|
|
|
$this->graphClient
|
|
->shouldReceive('request')
|
|
->once()
|
|
->andReturn($response);
|
|
|
|
$result1 = $this->resolver->resolve(['filter-1']);
|
|
$result2 = $this->resolver->resolve(['filter-1']);
|
|
|
|
expect($result1)->toBe($result2);
|
|
});
|