Tests/InvokeZEP.Tests.ps1
|
$modulePath = Join-Path $PSScriptRoot '..\InvokeZEP.psd1' Import-Module $modulePath -Force $config = Get-ZEPConfiguration if (-not $config -or [string]::IsNullOrWhiteSpace($config.BaseUri)) { throw 'Get-ZEPConfiguration returned an invalid configuration object.' } $commands = @('Get-ZEPConfiguration', 'Set-ZEPConfiguration', 'Invoke-ZEPRest', 'Get-ZEPOffer', 'Get-ZEPOffers', 'Get-ZEPOfferItems') foreach ($commandName in $commands) { if (-not (Get-Command -Name $commandName -ErrorAction SilentlyContinue)) { throw "Command '$commandName' was not exported from the module." } } $cacheChanged = & (Get-Command -Name Test-ZEPOffersCacheNeedsRefresh -ErrorAction Stop) -CacheObject ([pscustomobject]@{ total = 10; items = @() }) -CurrentTotal 12 if ($cacheChanged -ne $true) { throw 'The cache refresh detection did not detect a changed total count.' } $cachePartial = & (Get-Command -Name Test-ZEPOffersCacheNeedsRefresh -ErrorAction Stop) -CacheObject ([pscustomobject]@{ total = 10; items = @(@{ id = 1 }, @{ id = 2 }) }) -CurrentTotal 10 if ($cachePartial -ne $true) { throw 'The cache refresh detection did not detect a partial cache.' } $cacheComplete = & (Get-Command -Name Test-ZEPOffersCacheNeedsRefresh -ErrorAction Stop) -CacheObject ([pscustomobject]@{ total = 10; items = @(@{ id = 1 }, @{ id = 2 }, @{ id = 3 }, @{ id = 4 }, @{ id = 5 }, @{ id = 6 }, @{ id = 7 }, @{ id = 8 }, @{ id = 9 }, @{ id = 10 }) }) -CurrentTotal 10 if ($cacheComplete -ne $false) { throw 'The cache refresh detection incorrectly flagged a complete cache as stale.' } Write-Host 'InvokeZEP module import and export validation passed.' -ForegroundColor Green Get-ZepOffers | FT id,name,title |