Tests/Unit/Public/VoiceConfig/Get-MatchingPatternForCallRestriction.Tests.ps1

# Module: Orbit.Teams
# Function: Test
# Author: David Eberhardt
# Updated: 26-AUG-2022

# Script Analyzer Exceptions
#[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Justification = 'Context Boundaries')]


# Unit Tests
Describe -Tags ('Unit', 'Acceptance') "Function '$(((Split-Path -Leaf $PsCommandPath) -replace '\.Tests\.', '.') -replace '\.ps1', '')'" {
  InModuleScope -ModuleName 'Orbit.Teams' {
    BeforeAll {
      # Mocking basic connection commands to avoid connectivity related errors
      Mock Assert-GraphConnection -MockWith { $true }
      Mock Test-GraphConnection -MockWith { $true }
      Mock Assert-MicrosoftTeamsConnection -MockWith { $true }
      Mock Test-MicrosoftTeamsConnection -MockWith { $true }

      # Splatting Parameters
      $Params = @{
        WarningAction     = 'SilentlyContinue'
        InformationAction = 'SilentlyContinue'
      }

      # Dot Sourcing Mock Objects
      . "$(Split-Path -Parent ((Split-Path -Parent $PsScriptRoot) -split 'Tests')[0])\Orbit\Tests\Testing-MockedObjects.ps1"
    }

    Context 'Input' {
      # Pipeline, Position, etc.

    }

    Context 'Execution' {
      # Code Logic

    }

    Context 'Output' {
      #Properties, Values, Types

      #NOTE: This tests both Input and Output Cmdlets as they feed directly into each other

      It 'Should return objects of the Type System.Object' {
      (Get-MatchingPatternForCallRestriction -Country DE) | Should -BeOfType [System.Object]
      }

      It "should pass Case '<Case>' for Country '<Country>'" -TestCases @(
        @{ Case   = 'Lookup Country with ISO3166-alpha2 notation';
          Country = 'DE';
        }
        @{ Case   = 'Lookup Country with ISO3166-alpha3 notation';
          Country = 'DEU';
        }
        @{ Case   = 'Throw if Country not found';
          Country = 'XXX';
        }
      ) {
        param($Country)

        if ( $Country -eq 'XXX' ) {
          { Get-MatchingPatternForCallRestriction -Country $Country -ErrorAction Stop } | Should -Throw
        }
        else {
          $ISO3166CountryParams = @{
            $(if ( $Country.length -EQ 2 ) { 'TwoLetterCode' } else { 'ThreeLetterCode' } ) = $Country
          }
          $ISOCountry = Get-ISO3166Country @ISO3166CountryParams

          $CallRestrictionObject = Get-MatchingPatternForCallRestriction -Country $Country

          $CallRestrictionObject.Country | Should -Be $ISOCountry.Name
          $CallRestrictionObject.DialCode | Should -Be $ISOCountry.DialCode
          $CallRestrictionObject.UnrestrictedPattern | Should -Be '.*'
          $CallRestrictionObject.InternationalPattern | Should -Match '^\+|'
          $CallRestrictionObject.NationalPattern | Should -Match "^\+$($ISOCountry.DialCode)|"

          # How to Test EmergencyOnly pattern?
          $CallRestrictionObject.EmergencyOnlyPattern | Should -BeOfType String
        }

      }
    }

  }
}