Powerdex.Tests.ps1

Remove-Module Powerdex -ErrorAction SilentlyContinue
Import-Module "$PSScriptRoot/Powerdex.psm1"

InModuleScope Powerdex {
    Describe "Powerdex Unit Tests" {
        Context "Read-DexEntry Test - Happy Path" {
            Mock "Invoke-RestMethod" {
                return @{name="bulbasaur"; color=@{name="green"}; shape=@{name="quadruped"}; flavor_text_entries=@(@{flavor_text="Bulbasaur can be seen napping in bright sunlight. There is a seed on its back. By soaking up the sun's rays, the seed grows progressively larger."; language=@{name="en"}})}
            }

            $result = Read-DexEntry -Id 1

            It "Invoke-RestMethod called" {
                Assert-MockCalled Invoke-RestMethod -Exactly 1 -Scope Context
            }

            It "Full Pokemon entry returned" {
                $result | Should -Be "Bulbasaur, the green quadruped pokemon. Bulbasaur can be seen napping in bright sunlight. There is a seed on its back. By soaking up the sun's rays, the seed grows progressively larger."
            }
        }

        Context "Read-DexEntry Test - Fail Path" {
            Mock "Invoke-RestMethod" {
                throw "Error" 
            }

            $result = Read-DexEntry -Id 1

            It "Invoke-RestMethod called" {
                Assert-MockCalled Invoke-RestMethod -Exactly 1 -Scope Context
            }

            It "Error Pokemon entry returned" {
                $result | Should -Be "Pokemon not found."
            }
        }
    }
}