ps/Modules/Alkami.PowerShell.Configuration/Public/Test-AlkamiHotfixManifest10.tests.ps1
2023-05-30 22:51:22 -07:00

173 lines
6.4 KiB
PowerShell

. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
Describe "Test-AlkamiHotfixManifest10" {
Mock -CommandName Get-ValidHotfixServerTiers -ModuleName $moduleForMock -MockWith {
return @("VALID", "TIER", "LIST")
}
# Default to mocking all strings returning as null/whitespace
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $true
}
Context "Test valid manifest" {
# This context is for valid manifests, therefore, any invocation of
# Test-StringIsNullOrWhiteSpace will return $false
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $false
}
$result = Test-AlkamiHotfixManifest10 @{
fixedInOrbVersion = '2000.0.0'
serverTier = 'TIER'
}
It "Tested successfully" {
$result.success | Should -BeTrue
}
It "Produced no error messages" {
$result.results.Count | Should -Be 0
}
}
Context "Test manifest with INVALID version" {
Mock -CommandName Get-ValidHotfixServerTiers -ModuleName $moduleForMock -MockWith {
return @("VALID", "TIER", "LIST")
}
# Both members have values, but one is INVALID
# Therefore both calls to
# Test-StringIsNullOrWhiteSpace will return $false
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $false
}
$invalidVersionResult = Test-AlkamiHotfixManifest10 @{
fixedInOrbVersion = 'REPLACEME'
serverTier = 'TIER'
}
It "Returns success false" {
$invalidVersionResult.success | Should -BeFalse
}
It "Actually produced warnings" {
$invalidVersionResult.results | Should -Not -BeNullOrEmpty
}
It "Produced at least one warning statements" {
$invalidVersionResult.results.Count | Should -BeGreaterOrEqual 1
}
It "Has messages about target version" {
$invalidVersionResult.results | Should -Match "target version is not a valid"
}
}
Context "Test manifest with MISSING version" {
Mock -CommandName Get-ValidHotfixServerTiers -ModuleName $moduleForMock -MockWith {
return @("VALID", "TIER", "LIST")
}
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $true
} -ParameterFilter { $Value -ne 'TIER' }
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $false
} -ParameterFilter { $Value -eq 'TIER' }
$invalidVersionResult = Test-AlkamiHotfixManifest10 @{
fixedInOrbVersion = ''
serverTier = 'TIER'
}
It "Returns success false" {
$invalidVersionResult.success | Should -BeFalse
}
It "Actually produced warnings" {
$invalidVersionResult.results | Should -Not -BeNullOrEmpty
}
It "Produced at least one warning statements" {
$invalidVersionResult.results.Count | Should -BeGreaterOrEqual 1
}
It "Has messages about target version" {
$invalidVersionResult.results | Should -Match "target version is missing"
}
}
Context "Test manifest with INVALID serverTier" {
Mock -CommandName Get-ValidHotfixServerTiers -ModuleName $moduleForMock -MockWith {
return @("VALID", "TIER", "LIST")
}
# Both members have values, but one is INVALID
# Therefore both calls to
# Test-StringIsNullOrWhiteSpace will return $false
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $false
}
$invalidServerTierResult = Test-AlkamiHotfixManifest10 @{
fixedInOrbVersion = '2000.0.0'
serverTier = 'REPLACESERVERTIER'
}
It "Returns success false" {
$invalidServerTierResult.success | Should -BeFalse
}
It "Actually produced warnings" {
$invalidServerTierResult.results | Should -Not -BeNullOrEmpty
}
It "Produced at least one warning statements" {
$invalidServerTierResult.results.Count | Should -BeGreaterOrEqual 1
}
It "Has messages about serverTier" {
$invalidServerTierResult.results | Should -Match "serverTier is not a valid"
}
}
Context "Test manifest with MISSING serverTier" {
Mock -CommandName Get-ValidHotfixServerTiers -ModuleName $moduleForMock -MockWith {
return @("VALID", "TIER", "LIST")
}
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $true
} -ParameterFilter { $Value -ne '2000.0.0' }
Mock -CommandName Test-StringIsNullOrWhiteSpace -ModuleName $moduleForMock -MockWith {
return $false
} -ParameterFilter { $Value -eq '2000.0.0' }
$invalidServerTierResult = Test-AlkamiHotfixManifest10 @{
fixedInOrbVersion = '2000.0.0'
serverTier = ''
}
# TODO: Will need to be revisited after 2022.4 release in the future (see also Get-PackageMetadataV2)
# Original 1.0 manifests did not have serverTier
# Null-or-Whitespace will mean Install-to-All-tiers until 2022.4 when hotfixes have serverTier node
It "Returns success TRUE until 2022.4 release" {
$invalidServerTierResult.success | Should -BeTrue -Because "Hotfix manifest v1.0 did not originally have serverTier nodes, so early hotfixes returned empty-string for serverTier"
}
It "Actually produced warnings" {
$invalidServerTierResult.results | Should -Not -BeNullOrEmpty
}
It "Produced at least one warning statements" {
$invalidServerTierResult.results.Count | Should -BeGreaterOrEqual 1
}
It "Has messages about serverTier" {
$invalidServerTierResult.results | Should -Match "serverTier is missing"
}
}
}