File: api_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (41 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download
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
35
36
37
38
39
40
41
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Slack::API, feature_category: :integrations do
  describe '#post' do
    let(:slack_installation) { build(:slack_integration) }
    let(:api_method) { 'api_method_call' }
    let(:api_url) { "#{described_class::BASE_URL}/#{api_method}" }
    let(:payload) { { foo: 'bar' } }

    subject(:post) { described_class.new(slack_installation).post(api_method, payload) }

    before do
      stub_request(:post, api_url)
    end

    it 'posts to the Slack API correctly' do
      post

      expect(WebMock).to have_requested(:post, api_url).with(
        body: payload.to_json,
        headers: {
          'Authorization' => "Bearer #{slack_installation.bot_access_token}",
          'Content-Type' => 'application/json; charset=utf-8'
        })
    end

    it 'returns the response' do
      is_expected.to be_kind_of(HTTParty::Response)
    end

    context 'when the slack installation has no bot token' do
      let(:slack_installation) { build(:slack_integration, :legacy) }

      it 'raises an error' do
        expect { post }.to raise_error(ArgumentError)
      end
    end
  end
end