-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated documentation on Add-JiraFilterPermission
* added tests (WIP) * added external help * added -Id parameterSet * changed documentation on other functions (WIP)
- Loading branch information
Showing
5 changed files
with
237 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
Describe 'Add-JiraFilterPermission' { | ||
BeforeAll { | ||
Remove-Module JiraPS -ErrorAction SilentlyContinue | ||
Import-Module "$PSScriptRoot/../JiraPS" -Force -ErrorAction Stop | ||
} | ||
|
||
InModuleScope JiraPS { | ||
|
||
. "$PSScriptRoot/Shared.ps1" | ||
|
||
#region Definitions | ||
$jiraServer = "https://jira.example.com" | ||
|
||
$responseFilter = @" | ||
{ | ||
"self": "$jiraServer/rest/api/latest/filter/12844", | ||
"id": "12844", | ||
"name": "{0}", | ||
"jql": "{1}", | ||
"favourite": false | ||
} | ||
"@ | ||
#endregion Definitions | ||
|
||
#region Mocks | ||
Mock Get-JiraConfigServer -ModuleName JiraPS { | ||
$jiraServer | ||
} | ||
|
||
Mock ConvertTo-JiraFilterPermission -ModuleName JiraPS { | ||
$i = (ConvertFrom-Json $responseFilter) | ||
$i.PSObject.TypeNames.Insert(0, 'JiraPS.FilterPermission') | ||
$i | ||
} | ||
|
||
Mock Get-JiraFilter -ModuleName JiraPS { | ||
ConvertTo-JiraFilter | ||
} | ||
|
||
Mock Invoke-JiraMethod -ModuleName JiraPS -ParameterFilter {$Method -eq 'Post' -and $URI -like "$jiraServer/rest/api/*/filter"} { | ||
ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri', 'Body' | ||
ConvertFrom-Json $responseFilter | ||
} | ||
|
||
Mock Invoke-JiraMethod -ModuleName JiraPS { | ||
ShowMockInfo 'Invoke-JiraMethod' 'Method', 'Uri' | ||
throw "Unidentified call to Invoke-JiraMethod" | ||
} | ||
#endregion Mocks | ||
|
||
Context "Sanity checking" { | ||
$command = Get-Command -Name Add-JiraFilterPermission | ||
|
||
defParam $command 'Filter' | ||
defParam $command 'Type' | ||
defParam $command 'Value' | ||
defParam $command 'Credential' | ||
} | ||
|
||
Context "Behavior testing" { | ||
It "Invokes the Jira API to create a filter" { | ||
{ | ||
$newData = @{ | ||
Name = "myName" | ||
Description = "myDescription" | ||
JQL = "myJQL" | ||
Favorite = $true | ||
} | ||
New-JiraFilter @newData | ||
} | Should Not Throw | ||
|
||
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It -ParameterFilter { | ||
$Method -eq 'Post' -and | ||
$URI -like '*/rest/api/*/filter' -and | ||
$Body -match "`"name`":\s*`"myName`"" -and | ||
$Body -match "`"description`":\s*`"myDescription`"" -and | ||
$Body -match "`"jql`":\s*`"myJQL`"" -and | ||
$Body -match "`"favourite`":\s*true" | ||
} | ||
} | ||
} | ||
|
||
Context "Input testing" { | ||
It "-Name and -JQL" { | ||
{ | ||
$parameter = @{ | ||
Name = "newName" | ||
JQL = "newJQL" | ||
} | ||
New-JiraFilter @parameter | ||
} | Should Not Throw | ||
|
||
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It | ||
} | ||
It "-Name and -Description and -JQL" { | ||
{ | ||
$parameter = @{ | ||
Name = "newName" | ||
Description = "newDescription" | ||
JQL = "newJQL" | ||
} | ||
New-JiraFilter @parameter | ||
} | Should Not Throw | ||
|
||
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It | ||
} | ||
It "-Name and -Description and -JQL and -Favorite" { | ||
{ | ||
$parameter = @{ | ||
Name = "newName" | ||
Description = "newDescription" | ||
JQL = "newJQL" | ||
Favorite = $true | ||
} | ||
New-JiraFilter @parameter | ||
} | Should Not Throw | ||
|
||
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName JiraPS -Exactly -Times 1 -Scope It | ||
} | ||
It "maps the properties of an object to the parameters" { | ||
{ Get-JiraFilter "12345" | New-JiraFilter } | Should Not Throw | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.