Functions/Get-TeamObject.Tests.ps1
describe "BitTitan.Runbooks.MicrosoftTeams/Get-TeamObject" -Tag "module", "unit" { # Import the function to test . "$($PSScriptRoot)\Get-TeamObject.ps1" # Declare and mock our own external functions $defaultTeam = @{ DisplayName = "Team Name" Description = "team description" GroupId = [Guid]::Empty.Guid } function Get-Team {} mock Get-Team { return $defaultTeam } it "retrieves the team given the display name" { # Call the function $output = Get-TeamObject -DisplayName "Team Name" -ErrorAction SilentlyContinue -ErrorVariable errorVariable # Verify the mocks Assert-MockCalled Get-Team -Times 1 -Exactly -Scope it # Verify the output $errorVariable | Should BeNullOrEmpty $output | Should Be $defaultTeam } it "retrieves the team given the group ID" { # Call the function $output = Get-TeamObject -GroupId ([Guid]::Empty.Guid) -ErrorAction SilentlyContinue -ErrorVariable errorVariable # Verify the mocks Assert-MockCalled Get-Team -Times 1 -Exactly -Scope it # Verify the output $errorVariable | Should BeNullOrEmpty $output | Should Be $defaultTeam } it "outputs an error when the display name does not match any teams" { # Call the function $output = Get-TeamObject -DisplayName "Team Name 2" -ErrorAction SilentlyContinue -ErrorVariable errorVariable # Verify the mocks Assert-MockCalled Get-Team -Times 1 -Exactly -Scope it # Verify the output $errorVariable | Should Not BeNullOrEmpty $output | Should Be $null } it "outputs an error when the group ID does not match any teams" { # Call the function $output = Get-TeamObject -GroupId (New-Guid) -ErrorAction SilentlyContinue -ErrorVariable errorVariable # Verify the mocks Assert-MockCalled Get-Team -Times 1 -Exactly -Scope it # Verify the output $errorVariable | Should Not BeNullOrEmpty $output | Should Be $null } it "outputs an error when the display name and the group ID are both not provided" { # Call the function $output = Get-TeamObject -ErrorAction SilentlyContinue -ErrorVariable errorVariable # Verify the mocks Assert-MockCalled Get-Team -Times 0 -Exactly -Scope it # Verify the output $errorVariable | Should Not BeNullOrEmpty $output | Should Be $null } # Modify the mock of Get-Team mock Get-Team { return @($defaultTeam, $defaultTeam) } it "outputs an error when more than one team matches the display name" { # Call the function $output = Get-TeamObject -DisplayName "Team Name" -ErrorAction SilentlyContinue -ErrorVariable errorVariable # Verify the mocks Assert-MockCalled Get-Team -Times 1 -Exactly -Scope it # Verify the output $errorVariable | Should Not BeNullOrEmpty $output | Should Be $null } } |