diff --git a/JiraPS/Public/Get-JiraUser.ps1 b/JiraPS/Public/Get-JiraUser.ps1 index 51537075..bb88c2ea 100644 --- a/JiraPS/Public/Get-JiraUser.ps1 +++ b/JiraPS/Public/Get-JiraUser.ps1 @@ -13,6 +13,16 @@ function Get-JiraUser { [Switch] $IncludeInactive, + [Parameter( ParameterSetName = 'ByUserName' )] + [ValidateRange(1, 1000)] + [UInt32] + $MaxResults = 50, + + [Parameter( ParameterSetName = 'ByUserName' )] + [ValidateNotNullOrEmpty()] + [UInt64] + $Skip = 0, + [Parameter()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] @@ -30,6 +40,12 @@ function Get-JiraUser { if ($IncludeInactive) { $searchResourceUri += "&includeInactive=true" } + if ($MaxResults) { + $searchResourceUri += "&maxResults=$MaxResults" + } + if ($Skip) { + $searchResourceUri += "&startAt=$Skip" + } } process { diff --git a/Tests/Get-JiraUser.Tests.ps1 b/Tests/Get-JiraUser.Tests.ps1 index 2128e992..203ea66a 100644 --- a/Tests/Get-JiraUser.Tests.ps1 +++ b/Tests/Get-JiraUser.Tests.ps1 @@ -68,7 +68,11 @@ Describe "Get-JiraUser" { } # Searching for a user. - Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user/search?username=$testUsername"} { + Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user/search?*username=$testUsername*"} { + ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri' + ConvertFrom-Json -InputObject $restResult + } + Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Get' -and $URI -like "$jiraServer/rest/api/*/user/search?*username=%25*"} { ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri' ConvertFrom-Json -InputObject $restResult } @@ -128,6 +132,30 @@ Describe "Get-JiraUser" { Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 2 -Scope It -ParameterFilter {$URI -like "$jiraServer/rest/api/*/user?username=$testUsername&expand=groups"} } + It "Allow it search for multiple users" { + Get-JiraUser -UserName "%" + + Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter { + $URI -like "$jiraServer/rest/api/*/user/search?*username=%25*" + } + } + + It "Allows to change the max number of users to be returned" { + Get-JiraUser -UserName "%" -MaxResults 100 + + Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter { + $URI -like "$jiraServer/rest/api/*/user/search?*maxResults=100*" + } + } + + It "Can skip a certain amount of results" { + Get-JiraUser -UserName "%" -Skip 10 + + Assert-MockCalled -CommandName Invoke-JiraMethod -Exactly 1 -Scope It -ParameterFilter { + $URI -like "$jiraServer/rest/api/*/user/search?*startAt=10*" + } + } + It "Provides information about the user's group membership in Jira" { $getResult = Get-JiraUser -UserName $testUsername diff --git a/docs/en-US/commands/Get-JiraUser.md b/docs/en-US/commands/Get-JiraUser.md index 7c04aa99..76d9d06c 100644 --- a/docs/en-US/commands/Get-JiraUser.md +++ b/docs/en-US/commands/Get-JiraUser.md @@ -24,7 +24,7 @@ Get-JiraUser [-Credential ] [] ### ByUserName ```powershell -Get-JiraUser [-UserName] [-IncludeInactive] [-Credential ] [] +Get-JiraUser [-UserName] [-IncludeInactive] [[-MaxResults] ] [[-Skip] ] [-Credential ] [] ``` ### ByInputObject @@ -113,6 +113,42 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -MaxResults + +Maximum number of user to be returned. + +> The API does not allow for any value higher than 1000. + +```yaml +Type: UInt32 +Parameter Sets: ByUserName +Aliases: + +Required: False +Position: Named +Default value: 50 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Skip + +Controls how many objects will be skipped before starting output. + +Defaults to 0. + +```yaml +Type: UInt64 +Parameter Sets: ByUserName +Aliases: + +Required: False +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Credential Credentials to use to connect to JIRA.