tests/Octa.Tests.ps1
|
$moduleRoot = Split-Path -Parent $PSScriptRoot Import-Module (Join-Path $moduleRoot 'Octa.psd1') -Force Describe 'Octa module' { It 'imports without error and exports the expected commands' { $commands = Get-Command -Module Octa | Select-Object -ExpandProperty Name ($commands -contains 'Get-OctaCategory') | Should Be $true ($commands -contains 'Invoke-OctaCategory') | Should Be $true } } Describe 'Get-OctaCategory -SkipRiskScan (010 performance fix)' { # Found via real user complaint: Invoke-Octa took ~20s just to build its menu, because it # called plain Get-OctaCategory (all 20 categories, no -Id) to get DisplayName/Description # for the group pickers - which also live-scans every category's GetActionsFunction just to # compute HighestRiskLevel, a value the interactive menu never displays at all. Measured # directly: ~20s without -SkipRiskScan, ~28ms with it (both real numbers, not estimated). It 'completes fast (catches a regression back to the old always-scan behavior)' { $sw = [System.Diagnostics.Stopwatch]::StartNew() $categories = @(Get-OctaCategory -SkipRiskScan) $sw.Stop() $sw.Elapsed.TotalSeconds | Should BeLessThan 2 $categories.Count | Should BeGreaterThan 0 } It 'reports HighestRiskLevel as Unknown instead of scanning for a real value' { $categories = @(Get-OctaCategory -SkipRiskScan) foreach ($c in $categories) { $c.HighestRiskLevel | Should Be 'Unknown' } } It 'still computes a real HighestRiskLevel when -SkipRiskScan is not passed (default behavior unchanged)' { $category = Get-OctaCategory -Id 'telemetry' $category.HighestRiskLevel | Should Not Be 'Unknown' } } Describe 'Show-OctaMenu' { It 'fails fast with a clear error instead of looping forever when no console is attached' { InModuleScope Octa { $items = @([pscustomobject]@{ Key = 'x'; Label = 'Exit'; Description = '' }) { Show-OctaMenu -Items $items -Header 'Test' } | Should Throw 'real console' } } } |