tests/unit/Public/Get-KlippyNetworkInfo.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-KlippyNetworkInfo" -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]@{ SystemInfo = [PSCustomObject]@{ Network = [PSCustomObject]@{ eth0 = [PSCustomObject]@{ MacAddress = "AA:BB:CC:DD:EE:FF" IpAddresses = @("192.168.1.10") LinkSpeed = "1000" } } } } } } It "Should return network info for a named printer" { $result = Get-KlippyNetworkInfo -PrinterName "TestPrinter" $result | Should -Not -BeNullOrEmpty $result.PSTypeName | Should -Be "KlippyCLI.NetworkInfo" $result.PrinterId | Should -Be $script:testPrinter.Id $result.PrinterName | Should -Be $script:testPrinter.PrinterName $result.Interfaces.eth0.MacAddress | Should -Be "AA:BB:CC:DD:EE:FF" } It "Should accept printer input from the pipeline" { $result = $script:testPrinter | Get-KlippyNetworkInfo $result | Should -Not -BeNullOrEmpty $result.PrinterName | Should -Be "TestPrinter" } It "Should call machine/system_info via JSON-RPC" { $null = Get-KlippyNetworkInfo -PrinterName "TestPrinter" Assert-MockCalled -CommandName Invoke-KlippyJsonRpc -ModuleName KlippyCLI -Times 1 -Exactly -ParameterFilter { $Method -eq "machine/system_info" } } } |