debian-mirror-gitlab/spec/services/integrations/test/project_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

199 lines
7 KiB
Ruby
Raw Permalink Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Integrations::Test::ProjectService, feature_category: :integrations do
2021-03-11 19:13:27 +05:30
include AfterNextHelpers
2020-06-23 00:09:42 +05:30
describe '#execute' do
2021-03-11 19:13:27 +05:30
let_it_be(:project) { create(:project) }
2021-09-30 23:02:18 +05:30
let(:integration) { create(:integrations_slack, project: project) }
2022-03-02 08:16:31 +05:30
let(:user) { project.first_owner }
2020-06-23 00:09:42 +05:30
let(:event) { nil }
let(:sample_data) { { data: 'sample' } }
let(:success_result) { { success: true, result: {} } }
subject { described_class.new(integration, user, event).execute }
context 'without event specified' do
it 'tests the integration with default data' do
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
2021-09-30 23:02:18 +05:30
context 'with Integrations::PipelinesEmail' do
let(:integration) { create(:pipelines_email_integration, project: project) }
2020-06-23 00:09:42 +05:30
it_behaves_like 'tests for integration with pipeline data'
end
end
context 'with event specified' do
context 'event not supported by integration' do
2021-09-30 23:02:18 +05:30
let(:integration) { create(:jira_integration, project: project) }
2020-06-23 00:09:42 +05:30
let(:event) { 'push' }
it 'returns error message' do
expect(subject).to include({ status: :error, message: 'Testing not available for this event' })
end
end
context 'push' do
let(:event) { 'push' }
it 'executes integration' do
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'tag_push' do
let(:event) { 'tag_push' }
it 'executes integration' do
allow(Gitlab::DataBuilder::Push).to receive(:build_sample).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'note' do
let(:event) { 'note' }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has notes.' })
end
it 'executes integration' do
2021-03-11 19:13:27 +05:30
create(:note, project: project)
2020-06-23 00:09:42 +05:30
allow(Gitlab::DataBuilder::Note).to receive(:build).and_return(sample_data)
2021-03-11 19:13:27 +05:30
allow_next(NotesFinder).to receive(:execute).and_return(Note.all)
2020-06-23 00:09:42 +05:30
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
2021-03-11 19:13:27 +05:30
shared_examples_for 'a test of an integration that operates on issues' do
2020-06-23 00:09:42 +05:30
let(:issue) { build(:issue) }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has issues.' })
end
it 'executes integration' do
allow(project).to receive(:issues).and_return([issue])
allow(issue).to receive(:to_hook_data).and_return(sample_data)
2021-03-11 19:13:27 +05:30
allow_next(IssuesFinder).to receive(:execute).and_return([issue])
2020-06-23 00:09:42 +05:30
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
2021-03-11 19:13:27 +05:30
context 'issue' do
let(:event) { 'issue' }
2020-06-23 00:09:42 +05:30
2021-03-11 19:13:27 +05:30
it_behaves_like 'a test of an integration that operates on issues'
end
2020-06-23 00:09:42 +05:30
2021-03-11 19:13:27 +05:30
context 'confidential_issue' do
let(:event) { 'confidential_issue' }
2020-06-23 00:09:42 +05:30
2021-03-11 19:13:27 +05:30
it_behaves_like 'a test of an integration that operates on issues'
2020-06-23 00:09:42 +05:30
end
context 'merge_request' do
let(:event) { 'merge_request' }
2021-03-11 19:13:27 +05:30
let(:merge_request) { build(:merge_request) }
2020-06-23 00:09:42 +05:30
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has merge requests.' })
end
it 'executes integration' do
2021-03-11 19:13:27 +05:30
allow(merge_request).to receive(:to_hook_data).and_return(sample_data)
allow_next(MergeRequestsFinder).to receive(:execute).and_return([merge_request])
2020-06-23 00:09:42 +05:30
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
2021-03-11 19:13:27 +05:30
expect(subject).to include(success_result)
2020-06-23 00:09:42 +05:30
end
end
context 'deployment' do
2021-03-11 19:13:27 +05:30
let_it_be(:project) { create(:project, :test_repo) }
2021-09-30 23:02:18 +05:30
2021-03-11 19:13:27 +05:30
let(:deployment) { build(:deployment) }
2020-06-23 00:09:42 +05:30
let(:event) { 'deployment' }
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has deployments.' })
end
it 'executes integration' do
allow(Gitlab::DataBuilder::Deployment).to receive(:build).and_return(sample_data)
2021-03-11 19:13:27 +05:30
allow_next(DeploymentsFinder).to receive(:execute).and_return([deployment])
2020-06-23 00:09:42 +05:30
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'pipeline' do
let(:event) { 'pipeline' }
2021-03-11 19:13:27 +05:30
let(:pipeline) { build(:ci_pipeline) }
2020-06-23 00:09:42 +05:30
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the project has CI pipelines.' })
end
it 'executes integration' do
allow(Gitlab::DataBuilder::Pipeline).to receive(:build).and_return(sample_data)
2021-03-11 19:13:27 +05:30
allow_next(Ci::PipelinesFinder).to receive(:execute).and_return([pipeline])
2020-06-23 00:09:42 +05:30
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
context 'wiki_page' do
2021-03-11 19:13:27 +05:30
let_it_be(:project) { create(:project, :wiki_repo) }
2021-09-30 23:02:18 +05:30
2020-06-23 00:09:42 +05:30
let(:event) { 'wiki_page' }
it 'returns error message if wiki disabled' do
allow(project).to receive(:wiki_enabled?).and_return(false)
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the wiki is enabled and has pages.' })
end
it 'returns error message if not enough data' do
expect(integration).not_to receive(:test)
expect(subject).to include({ status: :error, message: 'Ensure the wiki is enabled and has pages.' })
end
it 'executes integration' do
create(:wiki_page, wiki: project.wiki)
allow(Gitlab::DataBuilder::WikiPage).to receive(:build).and_return(sample_data)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
end
end
end