|
| 1 | +# Pester tests for Invoke-ExecAssignApp assignment mode defaults. |
| 2 | + |
| 3 | +BeforeAll { |
| 4 | + $RepoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSCommandPath)) |
| 5 | + $FunctionPath = Get-ChildItem -Path (Join-Path $RepoRoot 'Modules') -Recurse -Filter 'Invoke-ExecAssignApp.ps1' -File | |
| 6 | + Select-Object -First 1 -ExpandProperty FullName |
| 7 | + |
| 8 | + ([PSObject].Assembly.GetType('System.Management.Automation.TypeAccelerators')).GetMethod('Add').Invoke( |
| 9 | + $null, @('HttpStatusCode', [System.Net.HttpStatusCode])) |
| 10 | + |
| 11 | + class HttpResponseContext { |
| 12 | + [int]$StatusCode |
| 13 | + [object]$Body |
| 14 | + } |
| 15 | + |
| 16 | + function Set-CIPPAssignedApplication { param($ApplicationId, $TenantFilter, $Intent, $APIName, $Headers, $GroupName, $AssignmentMode) } |
| 17 | + |
| 18 | + . $FunctionPath |
| 19 | +} |
| 20 | + |
| 21 | +Describe 'Invoke-ExecAssignApp assignment mode' { |
| 22 | + BeforeEach { |
| 23 | + $script:assignmentMode = $null |
| 24 | + Mock -CommandName Set-CIPPAssignedApplication -MockWith { |
| 25 | + $script:assignmentMode = $AssignmentMode |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + It 'defaults omitted assignment mode to append' { |
| 30 | + $request = [pscustomobject]@{ |
| 31 | + Params = @{ CIPPEndpoint = 'ExecAssignApp' } |
| 32 | + Headers = @{} |
| 33 | + Query = [pscustomobject]@{} |
| 34 | + Body = [pscustomobject]@{ |
| 35 | + tenantFilter = 'contoso.onmicrosoft.com' |
| 36 | + ID = 'app-1' |
| 37 | + AppType = 'Win32Lob' |
| 38 | + AssignTo = 'AllDevices' |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + $response = Invoke-ExecAssignApp -Request $request -TriggerMetadata $null |
| 43 | + |
| 44 | + $response.StatusCode | Should -Be ([System.Net.HttpStatusCode]::OK) |
| 45 | + $script:assignmentMode | Should -Be 'append' |
| 46 | + } |
| 47 | + |
| 48 | + It 'preserves explicit replace mode' { |
| 49 | + $request = [pscustomobject]@{ |
| 50 | + Params = @{ CIPPEndpoint = 'ExecAssignApp' } |
| 51 | + Headers = @{} |
| 52 | + Query = [pscustomobject]@{} |
| 53 | + Body = [pscustomobject]@{ |
| 54 | + tenantFilter = 'contoso.onmicrosoft.com' |
| 55 | + ID = 'app-1' |
| 56 | + AppType = 'Win32Lob' |
| 57 | + AssignTo = 'AllDevices' |
| 58 | + assignmentMode = 'replace' |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + $null = Invoke-ExecAssignApp -Request $request -TriggerMetadata $null |
| 63 | + |
| 64 | + $script:assignmentMode | Should -Be 'replace' |
| 65 | + } |
| 66 | +} |
0 commit comments