Skip to content

Commit

Permalink
Added functionality to ensure the room name is automatically URL enco…
Browse files Browse the repository at this point in the history
…ded if not already per issue #4
  • Loading branch information
markwragg committed Mar 17, 2024
1 parent 3d22ea5 commit df1c00c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 5 additions & 2 deletions HipChatPS/Public/Send-HipChat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
[Parameter(Mandatory = $True)]
[string]$apitoken,

#The id or URL encoded name of the HipChat room you want to send the message to.
#The id or name of the HipChat room you want to send the message to. If not URL encoded, will be URL encoded for you.
[Parameter(Mandatory = $True, ParameterSetName = 'Room')]
[string]$room,

#The id or URL encoded name of the HipChat room you want to send the message to.
#The id or name of the HipChat room you want to send the message to. If not URL encoded, will be URL encoded for you.
[Parameter(Mandatory = $True, ParameterSetName = 'User')]
[string]$user,

Expand All @@ -58,6 +58,9 @@
"notify" = [string]$notify
}

$roomDecoded = [System.Web.HttpUtility]::UrlDecode($room)
$room = [System.Web.HttpUtility]::UrlEncode($roomDecoded)

$uri = "$uri/v2/room/$room/notification?auth_token=$apitoken"
$Body = ConvertTo-Json $messageObj
$Post = [System.Text.Encoding]::UTF8.GetBytes($Body)
Expand Down
24 changes: 23 additions & 1 deletion Tests/Send-HipChat.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ Describe 'Send-HipChat' {

{send-hipchat @params} | Should Throw
}

It "should handle a URL encoded room" {

$params = @{
message = "Pester test message"
room = "Test%20Room"
apitoken = "c6cS2qXSv1zRyUUXpPsu3bebVF43wx8bvPQK5vg6"
}

Send-HipChat @params | Should Be $true
}

It "should handle a non-url encoded room name that needs encoding" {

$params = @{
message = "Pester test message"
room = "Test Room"
apitoken = "c6cS2qXSv1zRyUUXpPsu3bebVF43wx8bvPQK5vg6"
}

Send-HipChat @params | Should Be $true
}
}

Describe "Send-HipChat timeouts" {
Expand All @@ -48,7 +70,7 @@ Describe "Send-HipChat timeouts" {
}

send-hipchat @params | Should be $false

Assert-MockCalled Invoke-WebRequest -Exactly 4 -Scope It
}
}

0 comments on commit df1c00c

Please sign in to comment.