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

Duplicated fields with same name conflict New-JiraIssues #520

Merged
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
58 changes: 58 additions & 0 deletions Tests/Functions/New-JiraIssue.Unit.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,64 @@ Describe "New-JiraIssue" -Tag 'Unit' {
}
}

Context "New-JiraIssue handles duplicate fields" {
# Intentionally output multiple objects of different IDs but with the same name
Mock Get-JiraField {
$Field | % {
$name = $_
if ($name -eq 'Reporter') {
'Reporter', 'Reporter_mismatched' | % {
$fieldname = $_
$object = [PSCustomObject] @{
'Id' = "$fieldname"
}
$object.PSObject.TypeNames.Insert(0, 'JiraPS.Field')
$object
}
}
else {
$object = [PSCustomObject] @{
'Id' = "$name"
}
$object.PSObject.TypeNames.Insert(0, 'JiraPS.Field')
$object
}
}
}

It "finds the right field which has a matching name and id" {
Mock Get-JiraIssueCreateMetadata {
@(
@{Name = 'Project'; ID = 'Project'; Required = $true}
@{Name = 'IssueType'; ID = 'IssueType'; Required = $true}
@{Name = 'Priority'; ID = 'Priority'; Required = $true}
@{Name = 'Summary'; ID = 'Summary'; Required = $true}
@{Name = 'Description'; ID = 'Description'; Required = $true}
@{Name = 'Reporter'; ID = 'Reporter'; Required = $true}
@{Name = 'Reporter'; ID = 'Reporter_mismatch'; Required = $false}
)
}

{ New-JiraIssue @newParams } | Should Not Throw
}

It "throws when a field name return multiple fields without a field has matching name and id" {
Mock Get-JiraIssueCreateMetadata {
@(
@{Name = 'Project'; ID = 'Project'; Required = $true}
@{Name = 'IssueType'; ID = 'IssueType'; Required = $true}
@{Name = 'Priority'; ID = 'Priority'; Required = $true}
@{Name = 'Summary'; ID = 'Summary'; Required = $true}
@{Name = 'Description'; ID = 'Description'; Required = $true}
@{Name = 'Reporter'; ID = 'Reporter_mismatch1'; Required = $true}
@{Name = 'Reporter'; ID = 'Reporter_mismatch2'; Required = $false}
)
}

{ New-JiraIssue @newParams } | Should Throw
}
}

Context "Input testing" {
It "Checks to make sure all required fields are provided" {
# We'll create a custom field that's required, then see what happens when we don't provide it
Expand Down
Loading