Commit 261679ed authored by Michael Kozono's avatar Michael Kozono

Merge branch '335384-rename-integration-can_test-method' into 'master'

Rename Integration#can_test? to #testable?

See merge request gitlab-org/gitlab!65691
parents a7aafeee 9710349c
......@@ -46,7 +46,7 @@ class Projects::ServicesController < Projects::ApplicationController
end
def test
if integration.can_test?
if integration.testable?
render json: service_test_response, status: :ok
else
render json: {}, status: :not_found
......
......@@ -84,7 +84,7 @@ module IntegrationsHelper
integration_level: integration_level(integration),
editable: integration.editable?.to_s,
cancel_path: scoped_integrations_path,
can_test: integration.can_test?.to_s,
can_test: integration.testable?.to_s,
test_path: scoped_test_integration_path(integration),
reset_path: scoped_reset_integration_path(integration, group: group)
}
......
......@@ -447,7 +447,7 @@ class Integration < ApplicationRecord
# Disable test for instance-level and group-level integrations.
# https://gitlab.com/gitlab-org/gitlab/-/issues/213138
def can_test?
def testable?
project_level?
end
......
......@@ -20,7 +20,7 @@ module Integrations
%w()
end
def can_test?
def testable?
false
end
......
......@@ -58,7 +58,7 @@ module Integrations
]
end
def can_test?
def testable?
false
end
......
......@@ -27,7 +27,7 @@ module Integrations
'ewm'
end
def can_test?
def testable?
false
end
......
......@@ -537,7 +537,7 @@ module Integrations
def update_deployment_type?
(api_url_changed? || url_changed? || username_changed? || password_changed?) &&
can_test?
testable?
end
def update_deployment_type
......
......@@ -6,7 +6,7 @@ module Integrations
prop_accessor :token
def can_test?
def testable?
false
end
......
......@@ -83,7 +83,7 @@ module Integrations
end
end
def can_test?
def testable?
false
end
end
......
......@@ -18,7 +18,7 @@ module Integrations
Gitlab::Json.parse(File.read(Rails.root + 'spec/fixtures/metrics.json'))
end
def can_test?
def testable?
false
end
end
......
......@@ -57,7 +57,7 @@ module Integrations
PipelineNotificationWorker.new.perform(pipeline_id, recipients: all_recipients)
end
def can_test?
def testable?
project&.ci_pipelines&.any?
end
......
......@@ -68,7 +68,7 @@ module Integrations
%w(pipeline)
end
def can_test?
def testable?
project&.ci_pipelines&.any?
end
......
......@@ -22,7 +22,7 @@ module Integrations
update(active: !!slack_integration)
end
def can_test?
def testable?
false
end
......
......@@ -285,17 +285,17 @@ RSpec.describe Integrations::Github do
end
end
describe '#can_test?' do
describe '#testable?' do
it 'is false if there are no pipelines' do
project.ci_pipelines.delete_all
expect(subject.can_test?).to eq false
expect(subject).not_to be_testable
end
it 'is true if the project has a pipeline' do
pipeline
expect(subject.can_test?).to eq true
expect(subject).to be_testable
end
end
......
......@@ -6,9 +6,10 @@ RSpec.describe Projects::ServicesController do
include JiraServiceHelper
include AfterNextHelpers
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:service) { create(:jira_integration, project: project) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:service) { create(:jira_integration, project: project) }
let(:service_params) { { username: 'username', password: 'password', url: 'http://example.com' } }
before do
......@@ -17,9 +18,9 @@ RSpec.describe Projects::ServicesController do
end
describe '#test' do
context 'when can_test? returns false' do
context 'when the integration is not testable' do
it 'renders 404' do
allow_any_instance_of(Integration).to receive(:can_test?).and_return(false)
allow_any_instance_of(Integration).to receive(:testable?).and_return(false)
put :test, params: project_params
......@@ -41,10 +42,10 @@ RSpec.describe Projects::ServicesController do
context 'success' do
context 'with empty project' do
let(:project) { create(:project) }
let_it_be(:project) { create(:project) }
context 'with chat notification service' do
let(:service) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') }
let_it_be(:service) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') }
it 'returns success' do
allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true)
......@@ -131,8 +132,7 @@ RSpec.describe Projects::ServicesController do
context 'with the Slack integration' do
let_it_be(:integration) { build(:integrations_slack) }
let(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
let_it_be(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
it 'returns an error response when the URL is blocked' do
put :test, params: project_params(service: { webhook: 'http://127.0.0.1' })
......@@ -259,7 +259,8 @@ RSpec.describe Projects::ServicesController do
end
context 'Prometheus integration' do
let!(:service) { create(:prometheus_integration, project: project) }
let_it_be(:service) { create(:prometheus_integration, project: project) }
let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } }
context 'feature flag :settings_operations_prometheus_service is enabled' do
......
......@@ -139,19 +139,17 @@ RSpec.describe Integration do
end
end
describe '#can_test?' do
subject { integration.can_test? }
describe '#testable?' do
context 'when integration is project-level' do
let(:integration) { build(:service, project: project) }
subject { build(:service, project: project) }
it { is_expected.to be true }
it { is_expected.to be_testable }
end
context 'when integration is not project-level' do
let(:integration) { build(:service, project: nil) }
subject { build(:service, project: nil) }
it { is_expected.to be false }
it { is_expected.not_to be_testable }
end
end
......
......@@ -15,24 +15,6 @@ RSpec.describe Integrations::BaseChatNotification do
it { is_expected.to validate_inclusion_of(:labels_to_be_notified_behavior).in_array(%w[match_any match_all]).allow_blank }
end
describe '#can_test?' do
context 'with empty repository' do
it 'returns true' do
subject.project = create(:project, :empty_repo)
expect(subject.can_test?).to be true
end
end
context 'with repository' do
it 'returns true' do
subject.project = create(:project, :repository)
expect(subject.can_test?).to be true
end
end
end
describe '#execute' do
subject(:chat_integration) { described_class.new }
......
......@@ -341,7 +341,7 @@ RSpec.describe Integrations::Jira do
context 'when not allowed to test an instance or group' do
it 'does not update deployment type' do
allow(integration).to receive(:can_test?).and_return(false)
allow(integration).to receive(:testable?).and_return(false)
integration.update!(url: 'http://first.url')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment