Tests/Private/Test-StorageAccountAccess.Tests.ps1

BeforeAll {
    . "$PSScriptRoot/../../Private/Get-Timestamp.ps1"
    . "$PSScriptRoot/../../Private/Test-StorageAccountAccess.ps1"
}

Describe 'Test-StorageAccountAccess' {
    BeforeEach {
        Mock Write-Host {}
    }

    Context 'When storage account is accessible' {
        BeforeEach {
            Mock -CommandName 'az' -MockWith {
                $global:LASTEXITCODE = 0
                'mystorageaccount'
            }
        }

        It 'Does not throw' {
            { Test-StorageAccountAccess -AccountName 'mystorageaccount' } | Should -Not -Throw
        }

        It 'Writes success confirmation' {
            Test-StorageAccountAccess -AccountName 'mystorageaccount'
            Should -Invoke Write-Host -ParameterFilter { $Object -like "*✓*mystorageaccount*" }
        }
    }

    Context 'When storage account is not accessible' {
        BeforeEach {
            Mock -CommandName 'az' -MockWith {
                $global:LASTEXITCODE = 1
                'ResourceNotFound'
            }
        }

        It 'Throws with account name in message' {
            { Test-StorageAccountAccess -AccountName 'badaccount' } | Should -Throw "*badaccount*"
        }
    }

    Context 'Parameter validation' {
        It 'AccountName parameter is mandatory' {
            $param = (Get-Command Test-StorageAccountAccess).Parameters['AccountName']
            $param.Attributes | Where-Object { $_ -is [System.Management.Automation.ParameterAttribute] } | ForEach-Object {
                $_.Mandatory | Should -BeTrue
            }
        }
    }
}