Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added -Id parameter to Remove-JiraFilter #288

Merged
merged 2 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions JiraPS/Public/Remove-JiraFilter.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
function Remove-JiraFilter {
[CmdletBinding( ConfirmImpact = "Medium", SupportsShouldProcess )]
[CmdletBinding( ConfirmImpact = "Medium", SupportsShouldProcess, DefaultParameterSetName = 'ByInputObject' )]
param(
[Parameter( Mandatory, ValueFromPipeline )]
[Parameter( Position = 0, Mandatory, ValueFromPipeline, ParameterSetName = 'ByInputObject' )]
[ValidateNotNullOrEmpty()]
[PSTypeName('JiraPS.Filter')]
$InputObject,

[Parameter( Position = 0, Mandatory, ValueFromPipeline, ParameterSetName = 'ById')]
[UInt32[]]
$Id,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand All @@ -20,6 +24,12 @@ function Remove-JiraFilter {
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] ParameterSetName: $($PsCmdlet.ParameterSetName)"
Write-DebugMessage "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

if ($PSCmdlet.ParameterSetName -eq 'ById') {
$InputObject = foreach ($_id in $Id) {
Get-JiraFilter -Id $_id
}
}

foreach ($filter in $InputObject) {
$parameter = @{
URI = $filter.RestURL
Expand Down
33 changes: 31 additions & 2 deletions Tests/Remove-JiraFilter.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,18 @@ Describe 'Remove-JiraFilter' {

Context "Behavior testing" {
Get-JiraFilter -Id 12844
It "Invokes the Jira API to delete a filter" {
It "deletes a filter based on one or more InputObjects" {
{ Get-JiraFilter -Id 12844 | Remove-JiraFilter } | Should Not Throw

Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Delete' -and $URI -like '*/rest/api/*/filter/12844'}
}

It "deletes a filter based on one ore more filter ids" {
{ Remove-JiraFilter -Id 12844 } | Should Not Throw

Assert-MockCalled -CommandName Get-JiraFilter -ModuleName JiraPS -Exactly -Times 1 -Scope It
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Delete' -and $URI -like '*/rest/api/*/filter/12844'}
}
}

Context "Input testing" {
Expand Down Expand Up @@ -128,8 +135,30 @@ Describe 'Remove-JiraFilter' {
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 2 -Scope It
}

It "Accepts an ID of a filter" {
{ Remove-JiraFilter -Id 12345 } | Should Not Throw

Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It
}

It "Accepts multiple IDs of filters" {
{ Remove-JiraFilter -Id 12345, 12345 } | Should Not Throw

Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 2 -Scope It
}

It "Accepts multiple IDs of filters over the pipeline" {
{ 12345, 12345 | Remove-JiraFilter } | Should Not Throw

Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 2 -Scope It
}

It "fails if a negative number is passed as ID" {
{ Remove-JiraFilter -Id -1 } | Should Throw
}

It "fails if something other than [JiraPS.Filter] is provided" {
{ "12345" | Remove-JiraFilter -ErrorAction Stop } | Should Throw
{ Get-Date | Remove-JiraFilter -ErrorAction Stop } | Should Throw
{ Remove-JiraFilter "12345" -ErrorAction Stop} | Should Throw
}
}
Expand Down
42 changes: 40 additions & 2 deletions docs/en-US/commands/Remove-JiraFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ Removes an existing filter.

## SYNTAX

### byInputObject (Default)

```powershell
Remove-JiraFilter [-InputObject] <Object> [-WhatIf] [-Confirm] [<CommonParameters>]
Remove-JiraFilter [-InputObject] <JiraPS.Filter> [-WhatIf] [-Confirm] [<CommonParameters>]
```

### byId (Default)

```powershell
Remove-JiraFilter [-Id] <UInt32[]> [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -59,6 +67,18 @@ Get-JiraFilter -Favorite | Remove-JiraFilter -Confirm

Asks for each favorite filter confirmation to delete it.

### Example 5

```powershell
$listOfFilters = 1,2,3,4
$listOfFilters | Remove-JiraFilter
```

Remove filters with id "1", "2", "3" and "4".

This input allows for the ID of the filters to be stored in an array and passed to
the command. (eg: `Get-Content` from a file with the ids)

## PARAMETERS

### -InputObject
Expand All @@ -69,7 +89,25 @@ Object can be retrieved with `Get-JiraFilter`

```yaml
Type: JiraPS.Filter
Parameter Sets: (All)
Parameter Sets: ByInputObject
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Id

Id of the filter to be deleted.

Accepts integers over the pipeline.

```yaml
Type: UInt32[]
Parameter Sets: ById
Aliases:

Required: True
Expand Down