Skip to content

Commit

Permalink
Merge pull request #272 from lipkau/fix/ParameterForMaxResultsOfUsers
Browse files Browse the repository at this point in the history
Added parameter to influence max# of users to search
  • Loading branch information
lipkau authored May 30, 2018
2 parents 1357cea + dd1b6d7 commit 2a53f7c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
16 changes: 16 additions & 0 deletions JiraPS/Public/Get-JiraUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -30,6 +40,12 @@ function Get-JiraUser {
if ($IncludeInactive) {
$searchResourceUri += "&includeInactive=true"
}
if ($MaxResults) {
$searchResourceUri += "&maxResults=$MaxResults"
}
if ($Skip) {
$searchResourceUri += "&startAt=$Skip"
}
}

process {
Expand Down
30 changes: 29 additions & 1 deletion Tests/Get-JiraUser.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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

Expand Down
38 changes: 37 additions & 1 deletion docs/en-US/commands/Get-JiraUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Get-JiraUser [-Credential <PSCredential>] [<CommonParameters>]
### ByUserName

```powershell
Get-JiraUser [-UserName] <String[]> [-IncludeInactive] [-Credential <PSCredential>] [<CommonParameters>]
Get-JiraUser [-UserName] <String[]> [-IncludeInactive] [[-MaxResults] <UInt32>] [[-Skip] <UInt64>] [-Credential <PSCredential>] [<CommonParameters>]
```

### ByInputObject
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2a53f7c

Please sign in to comment.