Skip to content

Commit

Permalink
Merge pull request #23 from LiamLeane/dev
Browse files Browse the repository at this point in the history
Switching to ConvertFrom-Json2
  • Loading branch information
replicaJunction committed Apr 13, 2016
2 parents 9c6187a + 32b6cf9 commit 3047be1
Show file tree
Hide file tree
Showing 37 changed files with 368 additions and 368 deletions.
2 changes: 1 addition & 1 deletion PSJira/Functions/Add-JiraIssueComment.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ InModuleScope PSJira {

# This data was created from a GUI REST client, then sanitized. A lot of extra data was also removed to save space.
# Many Bothans died to bring us this information.
ConvertFrom-Json $restResponse
ConvertFrom-Json2 $restResponse
}

# Generic catch-all. This will throw an exception if we forgot to mock something.
Expand Down
Binary file added PSJira/Functions/ConvertFrom-Json2.Tests.ps1
Binary file not shown.
Binary file added PSJira/Functions/ConvertFrom-Json2.ps1
Binary file not shown.
4 changes: 2 additions & 2 deletions PSJira/Functions/Get-JiraField.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ InModuleScope PSJira {
}

Mock Invoke-JiraMethod -ModuleName PSJira -ParameterFilter {$Method -eq 'Get' -and $Uri -eq "$jiraServer/rest/api/latest/field"} {
ConvertFrom-Json $restResult
ConvertFrom-Json2 $restResult
}

It "Gets all fields in Jira if called with no parameters" {
$allResults = Get-JiraField
$allResults | Should Not BeNullOrEmpty
@($allResults).Count | Should Be @((ConvertFrom-Json -InputObject $restResult)).Count
@($allResults).Count | Should Be @((ConvertFrom-Json2 -InputObject $restResult)).Count
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It
}

Expand Down
178 changes: 89 additions & 89 deletions PSJira/Functions/Get-JiraFilter.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"

InModuleScope PSJira {

$ShowMockData = $false
$ShowDebugText = $false

Describe 'Get-JiraFilter' {
if ($ShowDebugText)
{
Mock 'Write-Debug' {
Write-Host " [DEBUG] $Message" -ForegroundColor Yellow
}
}

Mock Get-JiraConfigServer {
'https://jira.example.com'
}

# If we don't override this in a context or test, we don't want it to
# actually try to query a JIRA instance
Mock Invoke-JiraMethod -ModuleName PSJira {
if ($ShowMockData)
{
Write-Host " Mocked Invoke-WebRequest" -ForegroundColor Cyan
Write-Host " [Uri] $Uri" -ForegroundColor Cyan
Write-Host " [Method] $Method" -ForegroundColor Cyan
}
}

Context "Sanity checking" {
$command = Get-Command -Name Get-JiraFilter

function defParam($name)
{
It "Has a -$name parameter" {
$command.Parameters.Item($name) | Should Not BeNullOrEmpty
}
}

defParam 'Id'
defParam 'InputObject'
defParam 'Credential'
}

Context "Behavior testing" {
It "Queries JIRA for a filter with a given ID" {
{ Get-JiraFilter -Id 12345 } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*/rest/api/*/filter/12345'}
}

It "Uses ConvertTo-JiraFilter to output a Filter object if JIRA returns data" {
Mock Invoke-JiraMethod -ModuleName PSJira { $true }
Mock ConvertTo-JiraFilter -ModuleName PSJira {}
{ Get-JiraFilter -Id 12345 } | Should Not Throw
Assert-MockCalled -CommandName ConvertTo-JiraFilter -ModuleName PSJira
}
}

Context "Input testing" {
$sampleFilter = ConvertTo-JiraFilter (ConvertFrom-Json @'
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
InModuleScope PSJira {
$ShowMockData = $false
$ShowDebugText = $false
Describe 'Get-JiraFilter' {
if ($ShowDebugText)
{
Mock 'Write-Debug' {
Write-Host " [DEBUG] $Message" -ForegroundColor Yellow
}
}
Mock Get-JiraConfigServer {
'https://jira.example.com'
}
# If we don't override this in a context or test, we don't want it to
# actually try to query a JIRA instance
Mock Invoke-JiraMethod -ModuleName PSJira {
if ($ShowMockData)
{
Write-Host " Mocked Invoke-WebRequest" -ForegroundColor Cyan
Write-Host " [Uri] $Uri" -ForegroundColor Cyan
Write-Host " [Method] $Method" -ForegroundColor Cyan
}
}
Context "Sanity checking" {
$command = Get-Command -Name Get-JiraFilter
function defParam($name)
{
It "Has a -$name parameter" {
$command.Parameters.Item($name) | Should Not BeNullOrEmpty
}
}
defParam 'Id'
defParam 'InputObject'
defParam 'Credential'
}
Context "Behavior testing" {
It "Queries JIRA for a filter with a given ID" {
{ Get-JiraFilter -Id 12345 } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*/rest/api/*/filter/12345'}
}
It "Uses ConvertTo-JiraFilter to output a Filter object if JIRA returns data" {
Mock Invoke-JiraMethod -ModuleName PSJira { $true }
Mock ConvertTo-JiraFilter -ModuleName PSJira {}
{ Get-JiraFilter -Id 12345 } | Should Not Throw
Assert-MockCalled -CommandName ConvertTo-JiraFilter -ModuleName PSJira
}
}
Context "Input testing" {
$sampleFilter = ConvertTo-JiraFilter (ConvertFrom-Json2 @'
{
"self": "https://jira.atlassian.com/rest/api/latest/filter/12844",
"id": "12844",
Expand Down Expand Up @@ -102,29 +102,29 @@ InModuleScope PSJira {
"start-index": 0,
"end-index": 0
}
}
'@)

It "Accepts a filter ID for the -Filter parameter" {
{ Get-JiraFilter -Id 12345 } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It
}

It "Accepts multiple filter IDs to the -Filter parameter" {
{ Get-JiraFilter -Id '12345','67890' } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*/rest/api/*/filter/12345'}
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*/rest/api/*/filter/67890'}
}

It "Accepts a PSJira.Filter object to the InputObject parameter" {
{ Get-JiraFilter -InputObject $sampleFilter } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*rest/api/*/filter/12844'}
}

It "Accepts a PSJira.Filter object via pipeline" {
{ $sampleFilter | Get-JiraFilter } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*rest/api/*/filter/12844'}
}
}
}
}
}
'@)
It "Accepts a filter ID for the -Filter parameter" {
{ Get-JiraFilter -Id 12345 } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It
}
It "Accepts multiple filter IDs to the -Filter parameter" {
{ Get-JiraFilter -Id '12345','67890' } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*/rest/api/*/filter/12345'}
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*/rest/api/*/filter/67890'}
}
It "Accepts a PSJira.Filter object to the InputObject parameter" {
{ Get-JiraFilter -InputObject $sampleFilter } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*rest/api/*/filter/12844'}
}
It "Accepts a PSJira.Filter object via pipeline" {
{ $sampleFilter | Get-JiraFilter } | Should Not Throw
Assert-MockCalled -CommandName Invoke-JiraMethod -ModuleName PSJira -Exactly -Times 1 -Scope It -ParameterFilter {$Method -eq 'Get' -and $URI -like '*rest/api/*/filter/12844'}
}
}
}
}
4 changes: 2 additions & 2 deletions PSJira/Functions/Get-JiraGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ InModuleScope PSJira {
Write-Host " [Method] $Method" -ForegroundColor Cyan
Write-Host " [URI] $URI" -ForegroundColor Cyan
}
ConvertFrom-Json -InputObject $restResult
ConvertFrom-Json2 -InputObject $restResult
}

# Generic catch-all. This will throw an exception if we forgot to mock something.
Expand Down Expand Up @@ -72,7 +72,7 @@ InModuleScope PSJira {

It "Returns all available properties about the returned group object" {
$getResult = Get-JiraGroup -GroupName $testGroupName
$restObj = ConvertFrom-Json -InputObject $restResult
$restObj = ConvertFrom-Json2 -InputObject $restResult

$getResult.RestUrl | Should Be $restObj.self
$getResult.Name | Should Be $restObj.name
Expand Down
70 changes: 35 additions & 35 deletions PSJira/Functions/Get-JiraGroupMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ InModuleScope PSJira {
Mock Invoke-JiraMethod {}

Mock Invoke-JiraMethod -ModuleName PSJira -ParameterFilter { $Method -eq 'Get' -and $URI -like '*/rest/api/*/group?groupname=testgroup*' } {
ConvertFrom-Json @'
{
"Name": "testgroup",
"RestUrl": "https://jira.example.com/rest/api/2/group?groupname=testgroup",
"Size": 2
}
ConvertFrom-Json2 @'
{
"Name": "testgroup",
"RestUrl": "https://jira.example.com/rest/api/2/group?groupname=testgroup",
"Size": 2
}
'@
}

Expand Down Expand Up @@ -101,35 +101,35 @@ InModuleScope PSJira {
Write-Host " [Uri] $Uri" -ForegroundColor Cyan
Write-Host " [Method] $Method" -ForegroundColor Cyan
}
ConvertFrom-Json -InputObject @'
{
"name": "testgroup",
"self": "https://jira.example.com/rest/api/2/group?groupname=testgroup",
"users": {
"size": 2,
"items": [
{
"self": "https://jira.example.com/rest/api/2/user?username=testuser1",
"key": "testuser1",
"name": "testuser1",
"emailAddress": "testuser1@example.com",
"displayName": "Test User 1",
"active": true
},
{
"self": "https://jira.example.com/rest/api/2/user?username=testuser2",
"key": "testuser2",
"name": "testuser2",
"emailAddress": "testuser2@example.com",
"displayName": "Test User 2",
"active": true
}
],
"max-results": 50,
"start-index": 0,
"end-index": 0
},
"expand": "users"
ConvertFrom-Json2 -InputObject @'
{
"name": "testgroup",
"self": "https://jira.example.com/rest/api/2/group?groupname=testgroup",
"users": {
"size": 2,
"items": [
{
"self": "https://jira.example.com/rest/api/2/user?username=testuser1",
"key": "testuser1",
"name": "testuser1",
"emailAddress": "testuser1@example.com",
"displayName": "Test User 1",
"active": true
},
{
"self": "https://jira.example.com/rest/api/2/user?username=testuser2",
"key": "testuser2",
"name": "testuser2",
"emailAddress": "testuser2@example.com",
"displayName": "Test User 2",
"active": true
}
],
"max-results": 50,
"start-index": 0,
"end-index": 0
},
"expand": "users"
}
'@
}
Expand Down
2 changes: 1 addition & 1 deletion PSJira/Functions/Get-JiraIssue.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ InModuleScope PSJira {
# Write-Host " [Body] $Body" -ForegroundColor Cyan
}

ConvertFrom-Json @'
ConvertFrom-Json2 @'
{
"expand": "schema,names",
"startAt": 0,
Expand Down
2 changes: 1 addition & 1 deletion PSJira/Functions/Get-JiraIssueComment.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ InModuleScope PSJira {
Write-Host " [Method] $Method" -ForegroundColor Cyan
Write-Host " [URI] $URI" -ForegroundColor Cyan
}
ConvertFrom-Json -InputObject $restResult
ConvertFrom-Json2 -InputObject $restResult
}

# Generic catch-all. This will throw an exception if we forgot to mock something.
Expand Down

0 comments on commit 3047be1

Please sign in to comment.