Tests/Unit/Public/Test-GraphGroup.Tests.ps1

# Module: Orbit.Groups
# Function: Test
# Author: David Eberhardt
# Updated: 03-JUN 2023

# 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.Groups' {
    BeforeAll {
      Mock Assert-GraphConnection -MockWith { $true } -ModuleName Orbit.Groups
      Mock Test-GraphConnection -MockWith { $true } -ModuleName Orbit.Groups
      Mock Get-MgGroup -MockWith { $MgGroupAll } -ParameterFilter { $All }

      # 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

    }

    Context 'Testing for not found' {
      It "should return <Expected> for '<Identity>'" -ForEach @(
        @{ Identity = 'RoundWorld Observers'; Expected = $false }
        @{ Identity = 'RoundWorldObservers@discworld.onmicrosoft.com'; Expected = $false }
        @{ Identity = 'RoundWorldObservers'; Expected = $false }
        @{ Identity = 'fe5c659f-b00e-41c9-98bb-265fa437eabe'; Expected = $false }
      ) {
        Mock Get-MgGroup -MockWith { $null } -ParameterFilter { $Filter -and $Filter -eq "Displayname eq '$Identity'" }
        Test-GraphGroup -Identity "$Identity" | Should -Be $Expected
      }
    }

    Context 'Testing for DisplayName' {
      It "should return <Expected> for '<Identity>'" -ForEach @(
        @{ Identity = 'Committee for Equal Heights'; Expected = $true }
      ) {
        Mock Get-MgGroup -MockWith { $MgGroupGood1 } -ParameterFilter { $Filter -and $Filter -eq "Displayname eq '$Identity'" }

        Test-GraphGroup -Identity "$Identity" | Should -Be $Expected
      }

      It "should return <Expected> for '<Identity>'" -ForEach @(
        @{ Identity = 'Ankh Morpork Watch - Night Watch'; Expected = $true }
      ) {
        Mock Get-MgGroup -MockWith { $MgGroupGood2 } -ParameterFilter { $Filter -and $Filter -eq "Displayname eq '$Identity'" }

        Test-GraphGroup -Identity "$Identity" | Should -Be $Expected
      }

    }

    Context 'Testing for Id' {
      It "should return <Expected> for '<Identity>'" -ForEach @(
        @{ Identity = 'baa40d88-cd83-4a24-8cd9-1846b28388fa'; Expected = $true }
      ) {
        Mock Get-MgGroup -MockWith { $null } -ParameterFilter { $Filter -and $Filter -eq "Displayname eq '$Identity'" }
        Mock Get-MgGroup -MockWith { $MgGroupGood1 } -ParameterFilter { $GroupId -and $GroupId -eq "$Identity" }

        Test-GraphGroup -Identity "$Identity" | Should -Be $Expected
      }

      It "should return <Expected> for '<Identity>'" -ForEach @(
        @{ Identity = 'c3a541b6-d0a8-4899-a171-2c25dbb12436'; Expected = $true }
      ) {
        Mock Get-MgGroup -MockWith { $null } -ParameterFilter { $Filter -and $Filter -eq "Displayname eq '$Identity'" }
        Mock Get-MgGroup -MockWith { $MgGroupGood2 } -ParameterFilter { $GroupId -and $GroupId -eq "$Identity" }

        Test-GraphGroup -Identity "$Identity" | Should -Be $Expected
      }
    }

    <# Succeeded before - don't know why now for a reason it does not...
    Context 'Testing for Mail' {
      It "should return <Expected> for '<Identity>'" -ForEach @(
        @{ Identity = 'equalheights@discworld.onmicrosoft.com'; Expected = $true }
        @{ Identity = 'nightwatch@discworld.onmicrosoft.com'; Expected = $true }
        #NOTE Testing for MailNickname is not built yet!
        # @{ Identity = 'noHeightDiscrimination'; Expected = $true }
        # @{ Identity = 'AMnightwatch'; Expected = $true }
        ) {
          Mock Get-MgGroup -MockWith { $null } -ParameterFilter { $Filter -and $Filter -eq "Displayname eq '$Identity'" }
          Mock Get-MgGroup -MockWith { $null } -ParameterFilter { $GroupId -and $GroupId -eq "$Identity" }
 
          Test-GraphGroup -Identity "$Identity" | Should -Be $Expected
        }
      }
      #>


  }
}