Skip to content

Commit 7781d80

Browse files
committed
Bug fix in Update-ServiceNowNumber. Added Pester Test.
1 parent 72227e0 commit 7781d80

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

ServiceNow/Public/Update-ServiceNowNumber.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ Function Update-ServiceNowNumber {
7070
# Process credential steps based on parameter set name
7171
Switch ($PSCmdlet.ParameterSetName) {
7272
'SpecifyConnectionFields' {
73+
$getServiceNowTableEntry.Add('ServiceNowCredential',$Credential)
74+
$getServiceNowTableEntry.Add('ServiceNowURL',$ServiceNowURL)
7375
$ServiceNowURL = 'https://' + $ServiceNowURL + '/api/now/v1'
74-
$updateServiceNowTableEntrySplat.Add('ServiceNowCredential',$ServiceNowCredential)
75-
$updateServiceNowTableEntrySplat.Add('ServiceNowURL',$ServiceNowURL)
7676
}
7777
'UseConnectionObject' {
78+
$getServiceNowTableEntry.Add('Connection',$Connection)
7879
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
7980
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
8081
$ServiceNowURL = 'https://' + $Connection.ServiceNowUri + '/api/now/v1'
81-
$updateServiceNowTableEntrySplat.Add('Connection',$Connection)
8282
}
8383
Default {
8484
If ((Test-ServiceNowAuthIsSet)) {
@@ -90,9 +90,10 @@ Function Update-ServiceNowNumber {
9090
}
9191
}
9292
}
93-
93+
Write-Verbose "ServiceNowURL: $ServiceNowURL"
9494
# Use the number and table to determine the sys_id
9595
$SysID = Get-ServiceNowTableEntry @getServiceNowTableEntry | Select-Object -Expand sys_id
96+
Write-Verbose "SysID: $SysID"
9697

9798
# Convert the values to Json and encode them to an UTF8 array to support special chars
9899
$Body = $Values | ConvertTo-Json

Tests/ServiceNow.Tests.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,41 @@ Describe "ServiceNow-Module" {
202202
$TestTicket.description | Should -Be 'Updated by Pester test Update-ServiceNowNumber works'
203203
}
204204

205+
It "Update-ServiceNowNumber with SpecifyConnectionFields works" {
206+
$ShortDescription = 'Testing Ticket Update with Pester'
207+
$newServiceNowIncidentSplat = @{
208+
Caller = $Defaults.TestUser
209+
ShortDescription = $ShortDescription
210+
Description = 'Long description'
211+
AssignmentGroup = $Defaults.TestUserGroup
212+
Comment = 'Comment'
213+
Category = $Defaults.TestCategory
214+
SubCategory = $Defaults.TestSubcategory
215+
ConfigurationItem = $Defaults.TestConfigurationItem
216+
}
217+
$TestTicket = New-ServiceNowIncident @newServiceNowIncidentSplat
218+
219+
$TestTicket.short_description | Should -Be $ShortDescription
220+
221+
$Values = @{
222+
'short_description' = 'Ticket Updated with Pester (Update-ServiceNowNumber)'
223+
'description' = 'Updated by Pester test Update-ServiceNowNumber with SpecifyConnectionFields works'
224+
}
225+
226+
$updateServiceNowNumberSplat = @{
227+
Number = $TestTicket.Number
228+
Table = 'incident'
229+
Values = $Values
230+
Credential = $Defaults.Creds
231+
ServiceNowURL = $Defaults.ServiceNowURL
232+
}
233+
Update-ServiceNowNumber @updateServiceNowNumberSplat
234+
235+
$TestTicket = Get-ServiceNowIncident -MatchExact @{sys_id=$TestTicket.sys_id}
236+
$TestTicket.short_description | Should -Be 'Ticket Updated with Pester (Update-ServiceNowNumber)'
237+
$TestTicket.description | Should -Be 'Updated by Pester test Update-ServiceNowNumber with SpecifyConnectionFields works'
238+
}
239+
205240
# Remove Functions
206241
It "Remove-ServiceNowTable works" {
207242
$TestTicket = Get-ServiceNowIncident -Limit 1

0 commit comments

Comments
 (0)