diff options
Diffstat (limited to 'spec/scripts/api')
-rw-r--r-- | spec/scripts/api/create_merge_request_discussion_spec.rb | 40 | ||||
-rw-r--r-- | spec/scripts/api/get_package_and_test_job_spec.rb | 47 |
2 files changed, 87 insertions, 0 deletions
diff --git a/spec/scripts/api/create_merge_request_discussion_spec.rb b/spec/scripts/api/create_merge_request_discussion_spec.rb new file mode 100644 index 00000000000..3867f6532a9 --- /dev/null +++ b/spec/scripts/api/create_merge_request_discussion_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../scripts/api/create_merge_request_discussion' + +RSpec.describe CreateMergeRequestDiscussion, feature_category: :tooling do + describe '#execute' do + let(:project_id) { 12345 } + let(:iid) { 1 } + let(:content) { 'test123' } + + let(:options) do + { + api_token: 'token', + endpoint: 'https://example.gitlab.com', + project: project_id, + merge_request: { + 'iid' => iid + } + } + end + + subject { described_class.new(options).execute(content) } + + it 'requests commit_merge_requests from the gitlab client' do + expected_result = true + client = double('Gitlab::Client') # rubocop:disable RSpec/VerifiedDoubles + + expect(Gitlab).to receive(:client) + .with(endpoint: options[:endpoint], private_token: options[:api_token]) + .and_return(client) + + expect(client).to receive(:create_merge_request_discussion).with( + project_id, iid, body: content + ).and_return(expected_result) + + expect(subject).to eq(expected_result) + end + end +end diff --git a/spec/scripts/api/get_package_and_test_job_spec.rb b/spec/scripts/api/get_package_and_test_job_spec.rb new file mode 100644 index 00000000000..60bb26cbcaf --- /dev/null +++ b/spec/scripts/api/get_package_and_test_job_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require_relative '../../../scripts/api/get_package_and_test_job' + +RSpec.describe GetPackageAndTestJob, feature_category: :tooling do + describe '#execute' do + let(:project) { 12345 } + let(:pipeline_id) { 1 } + + let(:options) do + { + api_token: 'token', + endpoint: 'https://example.gitlab.com', + project: project, + pipeline_id: pipeline_id + } + end + + subject { described_class.new(options).execute } + + it 'requests commit_merge_requests from the gitlab client' do + client_result = [ + { 'name' => 'foo' }, + { 'name' => 'e2e:package-and-test-ee' }, + { 'name' => 'bar' } + ] + client = double('Gitlab::Client') # rubocop:disable RSpec/VerifiedDoubles + client_response = double('Gitlab::ClientResponse') # rubocop:disable RSpec/VerifiedDoubles + + expect(Gitlab).to receive(:client) + .with(endpoint: options[:endpoint], private_token: options[:api_token]) + .and_return(client) + + expect(client).to receive(:pipeline_bridges).with( + project, pipeline_id, scope: 'failed', per_page: 100 + ).and_return(client_response) + + expect(client_response).to receive(:auto_paginate) + .and_yield(client_result[0]) + .and_yield(client_result[1]) + .and_yield(client_result[2]) + + expect(subject).to eq(client_result[1]) + end + end +end |