summaryrefslogtreecommitdiff
path: root/spec/initializers/hangouts_chat_http_override_spec.rb
blob: 42236c8c853c6d8886eedc8e4518738386356d66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'HangoutsChat::Sender Gitlab::HTTP override' do
  describe 'HangoutsChat::Sender::HTTP#post' do
    it 'calls Gitlab::HTTP.post with default protection settings' do
      webhook_url = 'https://example.gitlab.com'
      payload = { key: 'value' }
      http = HangoutsChat::Sender::HTTP.new(webhook_url)
      mock_response = double(response: 'the response')

      expect(Gitlab::HTTP).to receive(:post)
        .with(
          URI.parse(webhook_url),
          body: payload.to_json,
          headers: { 'Content-Type' => 'application/json' },
          parse: nil
        )
        .and_return(mock_response)

      expect(http.post(payload)).to eq(mock_response.response)
    end

    it_behaves_like 'a request using Gitlab::UrlBlocker' do
      let(:http_method) { :post }
      let(:url_blocked_error_class) { Gitlab::HTTP::BlockedUrlError }

      def make_request(uri)
        HangoutsChat::Sender::HTTP.new(uri).post({})
      end
    end
  end
end