FIX: don't send nil user.name for MS Teams (#131)

Because Teams rejects the request for having a JSON `null` where a string is expected.
This commit is contained in:
Leonardo Mosquera 2022-06-16 13:12:56 -03:00 committed by GitHub
parent 157f3e910d
commit fd6be34974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -32,7 +32,12 @@ module DiscourseChatIntegration::Provider::TeamsProvider
def self.get_message(post) def self.get_message(post)
display_name = "@#{post.user.username}" display_name = "@#{post.user.username}"
full_name = SiteSetting.enable_names ? post.user.name : "" full_name =
if SiteSetting.enable_names && post.user.name.present?
post.user.name
else
""
end
topic = post.topic topic = post.topic

View File

@ -25,6 +25,18 @@ RSpec.describe DiscourseChatIntegration::Provider::TeamsProvider do
expect(stub1).to have_been_requested.once expect(stub1).to have_been_requested.once
end end
describe 'with nil user.name' do
before do
post.user.update!(name: nil)
end
it 'handles nil username correctly' do
message = described_class.get_message(post)
name = message[:sections].first[:facts].first[:name]
expect(name).to eq("")
end
end
end end
end end