Fix discord avatar URL
This commit is contained in:
parent
04c711e438
commit
f1df1f5234
|
@ -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)
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue