Tests/Presets.Tests.ps1

BeforeAll {
    $script:ModulePath = Join-Path -Path (Split-Path -Parent (Split-Path -Parent $PSCommandPath)) -ChildPath 'TechCare/TechCare.psd1'
    if (-not (Test-Path -LiteralPath $script:ModulePath)) {
        $script:ModulePath = Join-Path -Path (Split-Path -Parent $PSCommandPath) -ChildPath '../TechCare.psd1'
    }
    Import-Module -Name $script:ModulePath -Force
}

AfterAll {
    Remove-Module -Name TechCare -Force -ErrorAction SilentlyContinue
}

Describe 'Presets de mantenimiento' {

    It 'Basic contiene exactamente Diagnose, Cleanup y Report' {
        $m = @(Get-TechCareProfile -MaintenanceProfile Basic)
        $m | Should -Be @('Diagnose', 'Cleanup', 'Report')
    }

    It 'Standard anade Repair, Update y Security' {
        $m = @(Get-TechCareProfile -MaintenanceProfile Standard)
        $m | Should -Contain 'Repair'
        $m | Should -Contain 'Update'
        $m | Should -Contain 'Security'
        $m.Count | Should -Be 6
    }

    It 'Full contiene los siete modulos' {
        @(Get-TechCareProfile -MaintenanceProfile Full).Count | Should -Be 7
    }

    It 'devuelve siempre el orden canonico de ejecucion' {
        # Diagnosticar antes de reparar y el informe al final no es un detalle
        # estetico: un informe generado antes de limpiar no veria el espacio.
        $orden = @('Diagnose', 'Repair', 'Update', 'Cleanup', 'Performance', 'Security', 'Report')
        foreach ($preset in @('Basic', 'Standard', 'Full')) {
            $m = @(Get-TechCareProfile -MaintenanceProfile $preset)
            $indices = @($m | ForEach-Object { $orden.IndexOf($_) })
            $ordenados = @($indices | Sort-Object)
            ($indices -join ',') | Should -Be ($ordenados -join ',') -Because "el preset $preset debe venir ordenado"
        }
    }

    It 'Report es siempre el ultimo modulo de cada preset' {
        foreach ($preset in @('Basic', 'Standard', 'Full')) {
            @(Get-TechCareProfile -MaintenanceProfile $preset)[-1] | Should -Be 'Report'
        }
    }

    It 'rechaza un preset que no existe' {
        { Get-TechCareProfile -MaintenanceProfile 'Turbo' } | Should -Throw
    }

    It 'acepta el preset en posicion 0 sin nombrar el parametro' {
        @(Get-TechCareProfile 'Basic').Count | Should -Be 3
    }

    It 'acepta los alias -Preset y -Profile' {
        @(Get-TechCareProfile -Preset Basic) | Should -Be @(Get-TechCareProfile -Profile Basic)
    }
}