tests/Scheduler.Tests.ps1
|
$moduleRoot = Split-Path -Parent $PSScriptRoot Import-Module (Join-Path $moduleRoot 'Octa.psd1') -Force . (Join-Path $moduleRoot 'private\ElevationCheck.ps1') $isElevated = Test-OctaElevation Describe 'Invoke-OctaScheduler' { It 'lists without throwing' { { Invoke-OctaScheduler } | Should Not Throw } It 'reports NotFound when removing a scheduled run that does not exist' { $result = Invoke-OctaScheduler -Remove 'ThisScheduledRunDoesNotExist12345' $result.Status | Should Be 'NotFound' } It 'creates, lists, and fully removes a real scheduled task for every frequency (Daily/Weekly/Monthly - validates the Monthly CIM trigger genuinely registers)' { if (-not $isElevated) { return } foreach ($frequency in @('Daily', 'Weekly', 'Monthly')) { $created = Invoke-OctaScheduler -Create -Category 'quick-clean' -Frequency $frequency $created.Status | Should Be 'Success' $created.TaskName | Should Not BeNullOrEmpty $listed = Invoke-OctaScheduler ($listed | Where-Object { $_.TaskName -eq $created.TaskName }) | Should Not Be $null $removed = Invoke-OctaScheduler -Remove $created.TaskName $removed.Status | Should Be 'Success' (Get-ScheduledTask -TaskPath '\Octa\' -TaskName $created.TaskName -ErrorAction SilentlyContinue) | Should Be $null } } } |