2019-05-12 22:37:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-27 12:09:44 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe DiscourseChat::Provider::MatrixProvider do
|
|
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
|
|
|
|
describe '.trigger_notifications' do
|
|
|
|
before do
|
|
|
|
SiteSetting.chat_integration_matrix_enabled = true
|
|
|
|
SiteSetting.chat_integration_matrix_access_token = 'abcd'
|
|
|
|
end
|
|
|
|
|
2017-08-01 15:53:39 -04:00
|
|
|
let(:chan1) { DiscourseChat::Channel.create!(provider: 'matrix', data: { name: "Awesome Channel", room_id: '!blah:matrix.org' }) }
|
2017-07-27 12:09:44 -04:00
|
|
|
|
|
|
|
it 'sends the message' do
|
|
|
|
stub1 = stub_request(:put, %r{https://matrix.org/_matrix/client/r0/rooms/!blah:matrix.org/send/m.room.message/*}).to_return(status: 200)
|
2020-06-15 11:45:25 -04:00
|
|
|
described_class.trigger_notification(post, chan1, nil)
|
2017-07-27 12:09:44 -04:00
|
|
|
expect(stub1).to have_been_requested.once
|
|
|
|
end
|
|
|
|
|
2017-08-01 15:53:39 -04:00
|
|
|
it 'handles errors correctly' do
|
|
|
|
stub1 = stub_request(:put, %r{https://matrix.org/_matrix/client/r0/rooms/!blah:matrix.org/send/m.room.message/*}).to_return(status: 400, body: '{"errmsg":"M_UNKNOWN"}')
|
2017-07-27 12:09:44 -04:00
|
|
|
expect(stub1).to have_been_requested.times(0)
|
2020-06-15 11:45:25 -04:00
|
|
|
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
2017-07-27 12:09:44 -04:00
|
|
|
expect(stub1).to have_been_requested.once
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|