summaryrefslogtreecommitdiff
path: root/spec/tooling/merge_request_spec.rb
blob: de6fd48ad9f920415cb87b2fde71d5df5843f93a (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
# frozen_string_literal: true

require 'webmock/rspec'

require_relative '../../tooling/merge_request'
require_relative '../support/helpers/next_instance_of'

RSpec.describe Tooling::MergeRequest do
  let(:project_path) { 'gitlab-org/gitlab' }
  let(:branch_name) { 'my-branch' }
  let(:merge_request_iid) { 123 }
  let(:merge_requests) { [{ 'iid' => merge_request_iid }] }

  describe '.for' do
    let(:stub_api) do
      stub_request(:get, "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/merge_requests")
        .and_return(body: merge_requests)
    end

    before do
      stub_api.with(query: { source_branch: branch_name, order_by: 'updated_at', sort: 'desc' })
    end

    it 'fetches merge request for local branch in the given GitLab project path' do
      merge_request = described_class.for(branch: branch_name, project_path: project_path)

      expect(merge_request.iid).to eq(merge_request_iid)
      expect(stub_api).to have_been_requested.once
    end
  end
end