mirror of
https://github.com/discourse/discourse-chat-integration.git
synced 2025-02-28 23:09:17 +00:00
31 lines
1.0 KiB
Ruby
31 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe DiscourseChat::Provider::GoogleProvider do
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
describe '.trigger_notifications' do
|
|
before do
|
|
SiteSetting.chat_integration_google_enabled = true
|
|
end
|
|
|
|
let(:chan1) { DiscourseChat::Channel.create!(provider: 'google', data: { name: 'discourse', webhook_url: 'https://chat.googleapis.com/v1/abcdefg' }) }
|
|
|
|
it 'sends a webhook request' do
|
|
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(body: "1")
|
|
described_class.trigger_notification(post, chan1, nil)
|
|
expect(stub1).to have_been_requested.once
|
|
end
|
|
|
|
it 'handles errors correctly' do
|
|
stub1 = stub_request(:post, chan1.data['webhook_url']).to_return(status: 400, body: "{}")
|
|
expect(stub1).to have_been_requested.times(0)
|
|
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChat::ProviderError)
|
|
expect(stub1).to have_been_requested.once
|
|
end
|
|
|
|
end
|
|
|
|
end
|