Fix discord avatar URL

This commit is contained in:
David Taylor 2017-07-31 14:47:27 +01:00
parent 04c711e438
commit f1df1f5234
2 changed files with 14 additions and 1 deletions

View File

@ -21,6 +21,11 @@ module DiscourseChat
return response
end
def self.ensure_protocol(url)
return url if not url.start_with?('//')
return 'http:' + url
end
def self.generate_discord_message(post)
display_name = "@#{post.user.username}"
@ -38,7 +43,7 @@ module DiscourseChat
author:{
name: display_name,
url: Discourse.base_url+"/u/"+post.user.username,
# icon_url: post.user.small_avatar_url
icon_url: ensure_protocol(post.user.small_avatar_url)
}
}]
}

View File

@ -16,6 +16,14 @@ RSpec.describe DiscourseChat::Provider::DiscordProvider do
expect(stub1).to have_been_requested.once
end
it 'includes the protocol in the avatar URL' do
stub1 = stub_request(:post, 'https://discordapp.com/api/webhooks/1234/abcd?wait=true')
.with(body: hash_including({embeds:[hash_including({author:hash_including({url:/^https?:\/\//})})]}))
.to_return(status: 200)
described_class.trigger_notification(post, chan1)
expect(stub1).to have_been_requested.once
end
it 'handles errors correctly' do
stub1 = stub_request(:post, "https://discordapp.com/api/webhooks/1234/abcd?wait=true").to_return(status: 400)
expect(stub1).to have_been_requested.times(0)