'tenant-sync-collision', 'name' => 'Tenant Sync Collision', 'metadata' => [], 'is_current' => true, ]); $tenant->makeCurrent(); // Simulate an older bug: ESP row was synced under enrollmentRestriction. $wrong = Policy::create([ 'tenant_id' => $tenant->id, 'external_id' => 'esp-1', 'policy_type' => 'enrollmentRestriction', 'display_name' => 'ESP Misclassified', 'platform' => 'all', ]); $this->mock(GraphClientInterface::class, function (MockInterface $mock) { $espPayload = [ 'id' => 'esp-1', 'displayName' => 'Enrollment Status Page', '@odata.type' => '#microsoft.graph.windows10EnrollmentCompletionPageConfiguration', 'deviceEnrollmentConfigurationType' => 'windows10EnrollmentCompletionPageConfiguration', ]; $mock->shouldReceive('listPolicies') ->andReturnUsing(function (string $policyType) use ($espPayload) { if ($policyType === 'enrollmentRestriction') { // Shared endpoint can return ESP items if unfiltered. return new GraphResponse(true, [$espPayload]); } if ($policyType === 'windowsEnrollmentStatusPage') { return new GraphResponse(true, [$espPayload]); } return new GraphResponse(true, []); }); }); $service = app(PolicySyncService::class); $service->syncPolicies($tenant, [ [ 'type' => 'enrollmentRestriction', 'platform' => 'all', 'filter' => null, ], [ 'type' => 'windowsEnrollmentStatusPage', 'platform' => 'all', 'filter' => null, ], ]); $wrong->refresh(); expect($wrong->policy_type)->toBe('windowsEnrollmentStatusPage'); });