Tests/Unit/Public/Discovery/Get-SCAStandingAccess.Tests.ps1

Import-Module (Join-Path $PSScriptRoot '../../../../psSCA.psd1') -Force

Describe 'Get-SCAStandingAccess' {
    InModuleScope psSCA {
        It 'posts a filters body with the provider merged in, marked idempotent' {
            Mock Invoke-SCARequest { }

            Get-SCAStandingAccess -Provider AWS | Out-Null

            Should -Invoke Invoke-SCARequest -ParameterFilter {
                $Service -eq 'CDS' -and $Method -eq 'POST' -and $Path -eq '/detections/cloud-service-entitlements/list' -and
                $Body['filters']['cloudProvider'] -eq 'AWS' -and $Idempotent -eq $true
            }
        }

        It 'merges -Filter into the request body without dropping it' {
            Mock Invoke-SCARequest { }

            Get-SCAStandingAccess -Filter @{ identityType = 'User' } | Out-Null

            Should -Invoke Invoke-SCARequest -ParameterFilter {
                $Body['filters']['identityType'] -eq 'User'
            }
        }
    }
}