Skip to content

Commit f4ea05b

Browse files
committed
Update Get-AADGroupByDisplayName Unit Test
* Goal reached for markekraus/PSMSGraph#8 * Added missing code coverage for ```Invoke-GrapRequest``` error handling * Now has 100% code coverage for ```Get-AADGroupByDisplayName```
1 parent c0ceb19 commit f4ea05b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Tests/Get-AADGroupByDisplayName.Unit.Tests.ps1

+16-1
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,18 @@ $VerifyUrl = @(
7070
'/groups'
7171
'?api-version=1.6'
7272
'&$filter=displayName+eq+%27Marketing%27'
73-
73+
) -Join ''
74+
$VerifyBadUrl = @(
75+
'https://graph.windows.net/'
76+
$AppParams.Tenant
77+
'/groups'
78+
'?api-version=1.6'
79+
'&$filter=displayName+eq+%27BadGroup%27'
7480
) -Join ''
7581

7682
$ValidUrls = @(
7783
$VerifyUrl
84+
$VerifyBadUrl
7885
)
7986
# https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations
8087
$Global:AADGroupJSON = @'
@@ -110,6 +117,9 @@ Describe $Command -Tags Unit {
110117
}
111118
return $MockResponse
112119
}
120+
Mock -CommandName Invoke-GraphRequest -ModuleName PSMSGraph -ParameterFilter {$Uri -eq $ValidUrls[1]} -MockWith {
121+
Throw 'invalid group'
122+
}
113123
It 'Does not have errors when passed required parameters' {
114124
$LocalParams = $Params.psobject.Copy()
115125
{ & $Command @LocalParams -ErrorAction Stop } | Should not throw
@@ -134,6 +144,11 @@ Describe $Command -Tags Unit {
134144
$Object = & $Command @LocalParams | Select-Object -First 1
135145
$Object._AccessToken.GUID | should be $Token.GUID
136146
}
147+
It 'Provides friendly errors' {
148+
$LocalParams = $Params.psobject.Copy()
149+
$LocalParams.DisplayName = 'BadGroup'
150+
{ & $Command @LocalParams -ErrorAction Stop } | Should not throw 'Unable to query Group'
151+
}
137152
}
138153

139154
Remove-Variable -Name 'AADGroupJSON' -Scope 'Global'

0 commit comments

Comments
 (0)