tests/unit/Public/Get-KlippyMoonrakerInfo.Tests.ps1

#Requires -Modules Pester

BeforeAll {
    $modulePath = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
    Import-Module "$modulePath/KlippyCLI.psd1" -Force
}

Describe "Get-KlippyMoonrakerInfo" -Tag Unit {
    BeforeEach {
        $script:testPrinter = [PSCustomObject]@{
            Id          = "11111111-1111-1111-1111-111111111111"
            PrinterName = "TestPrinter"
            Uri         = "http://127.0.0.1"
            ApiKey      = $null
        }

        Mock -CommandName Resolve-KlippyPrinterTarget -ModuleName KlippyCLI -MockWith {
            return $script:testPrinter
        }

        Mock -CommandName Invoke-KlippyJsonRpc -ModuleName KlippyCLI -MockWith {
            return [PSCustomObject]@{
                KlippyConnected      = $true
                KlippyState          = "ready"
                MoonrakerVersion     = "0.9.0"
                ApiVersion           = 1
                ApiVersionText       = "v1"
                Components           = @("file_manager", "machine")
                FailedComponents     = @()
                RegisteredDirectories = @("gcodes")
                Warnings             = @()
            }
        }
    }

    It "Should return Moonraker info for a named printer" {
        $result = Get-KlippyMoonrakerInfo -PrinterName "TestPrinter"

        $result | Should -Not -BeNullOrEmpty
        $result.PSTypeName | Should -Be "KlippyCLI.MoonrakerInfo"
        $result.PrinterId | Should -Be $script:testPrinter.Id
        $result.PrinterName | Should -Be $script:testPrinter.PrinterName
        $result.MoonrakerVersion | Should -Be "0.9.0"
    }

    It "Should accept printer input from the pipeline" {
        $result = $script:testPrinter | Get-KlippyMoonrakerInfo

        $result | Should -Not -BeNullOrEmpty
        $result.PrinterName | Should -Be "TestPrinter"
    }

    It "Should call server/info via JSON-RPC" {
        $null = Get-KlippyMoonrakerInfo -PrinterName "TestPrinter"

        Assert-MockCalled -CommandName Invoke-KlippyJsonRpc -ModuleName KlippyCLI -Times 1 -Exactly -ParameterFilter {
            $Method -eq "server/info"
        }
    }
}