Tests/Unit/Private/Get-TeamAndChannel.Tests.ps1

# Module: Orbit.Teams
# Function: Test
# Author: David Eberhardt
# Updated: 24-JUL-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-AzureADConnection -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

    }

    #Old Context blocks
    Context 'Team not found' {
      BeforeEach {
        Mock Get-Team { throw }
      }

      It 'should return neither a Team Object nor a Channel Object' {
        $Identity = 'Trunk Company\General'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw
        $Team.GroupId | Should -BeNullOrEmpty
        $Channel.Id | Should -BeNullOrEmpty

        $Identity = 'Trunk Company\19:6knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw
        $Team.GroupId | Should -BeNullOrEmpty
        $Channel.Id | Should -BeNullOrEmpty

        $Identity = '6c105977-d636-419a-b5f3-4885375e432a\General'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw
        $Team.GroupId | Should -BeNullOrEmpty
        $Channel.Id | Should -BeNullOrEmpty

        $Identity = '6c105977-d636-419a-b5f3-4885375e432a\19:6knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw
        $Team.GroupId | Should -BeNullOrEmpty
        $Channel.Id | Should -BeNullOrEmpty
      }
    }

    Context 'Team found but Channel not found' {
      BeforeEach {
        # Using Testing-MockedObjects.ps1: $TeamGood
        Mock Get-Team { return $TeamGood }
        Mock Get-TeamChannel { return }
      }

      It 'should return a Team Object but not a Channel Object' {
        $Identity = 'Night Watch\Bribes'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw

        $Identity = 'Night Watch\19:7knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw

        $Identity = '6c105977-d636-419a-b5f3-4885375e432a\Bribes'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw

        $Identity = '6c105977-d636-419a-b5f3-4885375e432a\19:7knN4Rzr3_NUiCsVwEtrHvYWbp_MzqbPp9fEyqujZVc1@thread.tacv2'
        { $Team, $Channel = Get-TeamAndChannel -String $Identity @Params } | Should -Throw
      }
    }

    Context 'Team and Channel found' {
      BeforeEach {
        # Using Testing-MockedObjects.ps1: $TeamGood and $ChannelGood
        Mock Get-Team { return $TeamGood }
        Mock Get-TeamChannel { return $TeamChannelGood }
      }

      It 'should find a Team by Name and a Channel by Name and return a Team Object and a Channel object' {
        $Identity = 'Night Watch\Night Watch - Duty Roster'
        { $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params } | Should -Not -Throw
        $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params
        $Team.GroupId | Should -Be $TeamGood.GroupId
        $Channel.Id | Should -Be $ChannelGood.Id
      }

      It 'should find a Team by Name and a Channel by Id and return a Team Object and a Channel object' {
        $Identity = 'Night Watch\19:5e61bcffc0e54c5d915b17f6a0796a42@thread.tacv2'
        { $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params } | Should -Not -Throw
        $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params
        $Team.GroupId | Should -Be $TeamGood.GroupId
        $Channel.Id | Should -Be $ChannelGood.Id
      }

      It 'should find a Team by Id and a Channel by Name and return a Team Object and a Channel object' {
        $Identity = '6c105977-d636-419a-b5f3-4885375e432a\Night Watch - Duty Roster'
        { $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params } | Should -Not -Throw
        $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params
        $Team.GroupId | Should -Be $TeamGood.GroupId
        $Channel.Id | Should -Be $ChannelGood.Id
      }

      It 'should find a Team by Id and a Channel by Id and return a Team Object and a Channel object' {
        $Identity = '6c105977-d636-419a-b5f3-4885375e432a\19:5e61bcffc0e54c5d915b17f6a0796a42@thread.tacv2'
        { $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params } | Should -Not -Throw
        $Team, $Channel = Get-TeamAndChannel -String "$Identity" @Params
        $Team.GroupId | Should -Be $TeamGood.GroupId
        $Channel.Id | Should -Be $ChannelGood.Id
      }
    }
  }
}