summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/api/2_plan/closes_issue_via_pushing_a_commit_spec.rb
blob: 6935f9de4862ab31870589be9e594dd9f0189c91 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

require 'airborne'

module QA
  RSpec.describe 'Plan' do
    include Support::API

    describe 'Issue', product_group: :project_management do
      let(:issue) do
        Resource::Issue.fabricate_via_api!
      end

      let(:issue_id) { issue.api_response[:iid] }

      let(:api_client) { Runtime::API::Client.new(:gitlab) }

      before do
        # Initial commit should be pushed because
        # the very first commit to the project doesn't close the issue
        # https://gitlab.com/gitlab-org/gitlab-foss/issues/38965
        push_commit('Initial commit')
      end

      it 'closes via pushing a commit', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347947' do
        push_commit("Closes ##{issue_id}", false)

        Support::Retrier.retry_until(max_duration: 10, sleep_interval: 1) do
          issue_closed?
        end
      end

      private

      def push_commit(commit_message, new_branch = true)
        Resource::Repository::ProjectPush.fabricate! do |push|
          push.commit_message = commit_message
          push.new_branch = new_branch
          push.file_content = commit_message
          push.project = issue.project
        end
      end

      def issue_closed?
        response = get Runtime::API::Request.new(api_client, "/projects/#{issue.project.id}/issues/#{issue_id}").url
        parse_body(response)[:state] == 'closed'
      end
    end
  end
end