Tests/Public/Support/Helper/Get-MatchingPatternForCallRestriction.Tests.ps1

# Module: TeamsFunctions
# Function: Test
# Author: David Eberhardt
# Updated: 26-AUG-2022

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



InModuleScope TeamsFunctions {
  BeforeAll {
    # None
  }

  Describe -Tags ('Unit', 'Acceptance') "Function 'Get-MatchingPatternForCallRestriction*'" {
    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
      }

    }
  }
}