diff --git a/test/module/EntraBeta/Integration/EntraBetaObjectSetting.Tests.ps1 b/test/module/EntraBeta/Integration/EntraBetaObjectSetting.Tests.ps1 new file mode 100644 index 0000000000..5aa7f1ce2e --- /dev/null +++ b/test/module/EntraBeta/Integration/EntraBetaObjectSetting.Tests.ps1 @@ -0,0 +1,50 @@ +Describe "The EntraBetaObjectSetting commands executing unmocked" { + + Context "When Changing group settings" { + BeforeAll { + $testReportPath = join-path $psscriptroot "\setenv.ps1" + Import-Module -Name $testReportPath + $appId = $env:TEST_APPID + $tenantId = $env:TEST_TENANTID + $cert = $env:CERTIFICATETHUMBPRINT + Connect-MgGraph -TenantId $tenantId -AppId $appId -CertificateThumbprint $cert + + $thisTestInstanceId = New-Guid | select -expandproperty guid + $testGroupName = 'SimpleTestAppRead' + $testGroupName + $global:testGroup = New-EntraBetaGroup -DisplayName $testGroupName -MailEnabled $false -SecurityEnabled $true -MailNickName $testGroupName -Description $testGroupName + } + + It "Should successfully block guest access" { + $template = Get-EntraBetaDirectorySettingTemplate | ? {$_.displayname -eq "group.unified.guest"} + $settingsCopy = $template.CreateDirectorySetting() + $settingsCopy["AllowToAddGuests"]=$False + + $groupID= (Get-EntraBetaGroup -ObjectId $testGroup.Id).ObjectId + $global:newObjectSetting = New-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $groupID -DirectorySetting $settingsCopy + + $ObjectSettings = Get-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $testGroup.Id + $ObjectSettings.values.value | Should -be 'False' + } + + It "Should successfully allow guest access" { + $template = Get-EntraBetaDirectorySettingTemplate | ? {$_.displayname -eq "group.unified.guest"} + $settingsCopy = $template.CreateDirectorySetting() + $settingsCopy["AllowToAddGuests"]=$True + + $groupID= (Get-EntraBetaGroup -ObjectId $testGroup.Id).ObjectId + Set-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $groupID -DirectorySetting $settingsCopy -Id $newObjectSetting.Id + + $ObjectSettings = Get-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $testGroup.Id + $ObjectSettings.values.value | Should -be 'True' + } + + AfterAll { + $groupId = (Get-EntraBetaGroup -ObjectId $testGroup.Id).ObjectId + Remove-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $groupId -Id $newObjectSetting.Id + $ObjectSettings = Get-EntraBetaObjectSetting -TargetType Groups -TargetObjectId $testGroup.Id + $ObjectSettings | Should -BeNullorEmpty + + Remove-EntraBetaGroup -ObjectId $groupId + } + } +} \ No newline at end of file diff --git a/test/module/EntraBeta/Integration/setenv.ps1 b/test/module/EntraBeta/Integration/setenv.ps1 new file mode 100644 index 0000000000..eaef940bd2 --- /dev/null +++ b/test/module/EntraBeta/Integration/setenv.ps1 @@ -0,0 +1,3 @@ +$env:TEST_APPID = "8886ad7b-1795-4542-9808-c85859d97f23" +$env:TEST_TENANTID = "d5aec55f-2d12-4442-8d2f-ccca95d4390e" +$env:CERTIFICATETHUMBPRINT = "305D4F33E153980E2451F6E068426FC2BCAF683E" \ No newline at end of file