Tests/Unit/Public/System.Tests.ps1
|
BeforeAll { $moduleRoot = (Resolve-Path (Join-Path $PSScriptRoot '../../..')).Path Import-Module (Join-Path $moduleRoot 'psSIA.psd1') -Force } Describe 'Get-SIAModuleConfiguration and Set-SIAModuleConfiguration' { AfterEach { Set-SIAModuleConfiguration -RequestTimeout 30 -RetryCount 3 -RetryDelay 2 -AutoPagination $true -LogLevel Normal -Confirm:$false } It 'returns the current defaults' { $config = Get-SIAModuleConfiguration $config.RequestTimeout | Should -Be 30 $config.PSObject.TypeNames | Should -Contain 'psSIA.ModuleConfiguration' } It 'only changes the values that are supplied' { Set-SIAModuleConfiguration -RequestTimeout 60 -Confirm:$false $config = Get-SIAModuleConfiguration $config.RequestTimeout | Should -Be 60 $config.RetryCount | Should -Be 3 } It 'does not change anything under -WhatIf' { Set-SIAModuleConfiguration -RequestTimeout 99 -WhatIf (Get-SIAModuleConfiguration).RequestTimeout | Should -Be 30 } } Describe 'Get-SIASetting and Set-SIASetting' { It 'requests every setting when -FeatureName is omitted' { InModuleScope psSIA { Mock Invoke-SIARequest { param($Path) $Path | Should -Be '/api/settings'; @() } Get-SIASetting | Out-Null } } It 'requests a single feature by name' { InModuleScope psSIA { Mock Invoke-SIARequest { param($Path) $Path | Should -Be '/api/settings/SSHRecording'; [pscustomobject]@{} } Get-SIASetting -FeatureName 'SSHRecording' | Out-Null } } It 'uses PATCH by default' { InModuleScope psSIA { Mock Invoke-SIARequest { param($Method) $Method | Should -Be 'PATCH' } Set-SIASetting -FeatureName 'SSHRecording' -Body @{ enabled = $true } -Confirm:$false } } It 'uses PUT with -Replace' { InModuleScope psSIA { Mock Invoke-SIARequest { param($Method) $Method | Should -Be 'PUT' } Set-SIASetting -FeatureName 'SSHRecording' -Body @{ enabled = $true } -Replace -Confirm:$false } } It 'rejects -Replace without -FeatureName' { { Set-SIASetting -Body @{ enabled = $true } -Replace -Confirm:$false } | Should -Throw '*requires -FeatureName*' } } |