Tests/Unit/Private/ConvertTo-SCARequestBody.Tests.ps1
|
Import-Module (Join-Path $PSScriptRoot '../../../psSCA.psd1') -Force Describe 'ConvertTo-SCARequestBody' { InModuleScope psSCA { It 'serializes a hashtable to compact JSON' { $json = ConvertTo-SCARequestBody -InputObject @{ name = 'test' } $json | Should -Be '{"name":"test"}' } It 'drops null-valued keys from a hashtable' { $json = ConvertTo-SCARequestBody -InputObject @{ name = 'test'; description = $null } $json | Should -Not -Match 'description' ($json | ConvertFrom-Json).name | Should -Be 'test' } It 'drops null-valued properties from a PSCustomObject' { $object = [pscustomobject]@{ name = 'test'; description = $null } $json = ConvertTo-SCARequestBody -InputObject $object $json | Should -Not -Match 'description' } It 'serializes nested structures up to the requested depth' { $body = @{ metadata = @{ timeFrame = @{ startDate = '2026-01-01'; endDate = '2026-02-01' } } } $json = ConvertTo-SCARequestBody -InputObject $body $parsed = $json | ConvertFrom-Json $parsed.metadata.timeFrame.startDate | Should -Be '2026-01-01' } It 'serializes a non-object input (e.g. an array) via the plain ConvertTo-Json fallback' { $json = ConvertTo-SCARequestBody -InputObject @('a', 'b') $json | Should -Be '["a","b"]' } } } |