Commit 55d3ff1a authored by Nikola Milojevic's avatar Nikola Milojevic

Merge branch '330300-cleanup' into 'master'

Clean up temporary code

See merge request gitlab-org/gitlab!65769
parents b3658f2c b3fd1372
......@@ -41,6 +41,5 @@ class Projects::MattermostsController < Projects::ApplicationController
def integration
@integration ||= @project.find_or_initialize_integration('mattermost_slash_commands')
@service = @integration # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
end
end
......@@ -16,6 +16,5 @@ class Projects::ServiceHookLogsController < Projects::HookLogsController
def integration
@integration ||= @project.find_or_initialize_integration(params[:service_id])
@service = @integration # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
end
end
......@@ -112,7 +112,7 @@ class Projects::ServicesController < Projects::ApplicationController
return if !integration.is_a?(::Integrations::Prometheus) || !Feature.enabled?(:settings_operations_prometheus_service, project)
operations_link_start = "<a href=\"#{project_settings_operations_path(project)}\">"
message = s_('PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page has been deprecated.') % { operations_link_start: operations_link_start, operations_link_end: "</a>" }
message = s_('PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page have been deprecated.') % { operations_link_start: operations_link_start, operations_link_end: "</a>" }
flash.now[:alert] = message.html_safe
end
end
......@@ -15,4 +15,4 @@
and try again.
%hr
.clearfix
= link_to 'Go back', edit_project_service_path(@project, @service), class: 'gl-button btn btn-lg float-right'
= link_to 'Go back', edit_project_service_path(@project, @integration), class: 'gl-button btn btn-lg float-right'
......@@ -2,7 +2,7 @@
This service will be installed on the Mattermost instance at
%strong= link_to Gitlab.config.mattermost.host, Gitlab.config.mattermost.host
%hr
= form_for(:mattermost, method: :post, url: project_mattermost_path(@project), html: { class: 'js-requires-input'} ) do |f|
= form_for(:mattermost, method: :post, url: project_mattermost_path(@project), html: { class: 'js-requires-input' }) do |f|
%h4 Team
%p
= @teams.one? ? 'The team' : 'Select the team'
......@@ -42,5 +42,5 @@
%hr
.clearfix
.float-right
= link_to 'Cancel', edit_project_service_path(@project, @service), class: 'gl-button btn btn-lg'
= link_to 'Cancel', edit_project_service_path(@project, @integration), class: 'gl-button btn btn-lg'
= f.submit 'Install', class: 'gl-button btn btn-success btn-lg'
......@@ -26414,7 +26414,7 @@ msgstr ""
msgid "PrometheusService|Waiting for your first deployment to an environment to find common metrics"
msgstr ""
msgid "PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page has been deprecated."
msgid "PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page have been deprecated."
msgstr ""
msgid "PrometheusService|You have a cluster with the Prometheus integration enabled."
......
......@@ -8,9 +8,10 @@ RSpec.describe Projects::ServicesController do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:service) { create(:jira_integration, project: project) }
let_it_be(:jira_integration) { create(:jira_integration, project: project) }
let(:service_params) { { username: 'username', password: 'password', url: 'http://example.com' } }
let(:integration) { jira_integration }
let(:integration_params) { { username: 'username', password: 'password', url: 'http://example.com' } }
before do
sign_in(user)
......@@ -29,10 +30,10 @@ RSpec.describe Projects::ServicesController do
end
context 'when validations fail' do
let(:service_params) { { active: 'true', url: '' } }
let(:integration_params) { { active: 'true', url: '' } }
it 'returns error messages in JSON response' do
put :test, params: project_params(service: service_params)
put :test, params: project_params(service: integration_params)
expect(json_response['message']).to eq 'Validations failed.'
expect(json_response['service_response']).to include "Url can't be blank"
......@@ -40,12 +41,14 @@ RSpec.describe Projects::ServicesController do
end
end
context 'success' do
context 'when successful' do
context 'with empty project' do
let_it_be(:project) { create(:project) }
context 'with chat notification service' do
let_it_be(:service) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') }
context 'with chat notification integration' do
let_it_be(:teams_integration) { project.create_microsoft_teams_integration(webhook: 'http://webhook.com') }
let(:integration) { teams_integration }
it 'returns success' do
allow_next(::MicrosoftTeams::Notifier).to receive(:ping).and_return(true)
......@@ -61,7 +64,7 @@ RSpec.describe Projects::ServicesController do
expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original
put :test, params: project_params(service: service_params)
put :test, params: project_params(service: integration_params)
expect(response).to be_successful
end
......@@ -72,13 +75,13 @@ RSpec.describe Projects::ServicesController do
expect(Gitlab::HTTP).to receive(:get).with('/rest/api/2/serverInfo', any_args).and_call_original
put :test, params: project_params(service: service_params)
put :test, params: project_params(service: integration_params)
expect(response).to be_successful
end
context 'when service is configured for the first time' do
let(:service_params) do
let(:integration_params) do
{
'active' => '1',
'push_events' => '1',
......@@ -109,17 +112,17 @@ RSpec.describe Projects::ServicesController do
def do_put
put :test, params: project_params(id: 'buildkite',
service: service_params)
service: integration_params)
end
end
end
context 'failure' do
context 'when unsuccessful' do
it 'returns an error response when the integration test fails' do
stub_request(:get, 'http://example.com/rest/api/2/serverInfo')
.to_return(status: 404)
put :test, params: project_params(service: service_params)
put :test, params: project_params(service: integration_params)
expect(response).to be_successful
expect(json_response).to eq(
......@@ -132,7 +135,6 @@ RSpec.describe Projects::ServicesController do
context 'with the Slack integration' do
let_it_be(:integration) { build(:integrations_slack) }
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' })
......@@ -165,17 +167,17 @@ RSpec.describe Projects::ServicesController do
describe 'PUT #update' do
describe 'as HTML' do
let(:service_params) { { active: true } }
let(:params) { project_params(service: service_params) }
let(:integration_params) { { active: true } }
let(:params) { project_params(service: integration_params) }
let(:message) { 'Jira settings saved and active.' }
let(:redirect_url) { edit_project_service_path(project, service) }
let(:redirect_url) { edit_project_service_path(project, integration) }
before do
put :update, params: params
end
shared_examples 'service update' do
shared_examples 'integration update' do
it 'redirects to the correct url with a flash message' do
expect(response).to redirect_to(redirect_url)
expect(flash[:notice]).to eq(message)
......@@ -183,49 +185,49 @@ RSpec.describe Projects::ServicesController do
end
context 'when param `active` is set to true' do
let(:params) { project_params(service: service_params, redirect_to: redirect) }
let(:params) { project_params(service: integration_params, redirect_to: redirect) }
context 'when redirect_to param is present' do
let(:redirect) { '/redirect_here' }
let(:redirect_url) { redirect }
it_behaves_like 'service update'
it_behaves_like 'integration update'
end
context 'when redirect_to is an external domain' do
let(:redirect) { 'http://examle.com' }
it_behaves_like 'service update'
it_behaves_like 'integration update'
end
context 'when redirect_to param is an empty string' do
let(:redirect) { '' }
it_behaves_like 'service update'
it_behaves_like 'integration update'
end
end
context 'when param `active` is set to false' do
let(:service_params) { { active: false } }
let(:integration_params) { { active: false } }
let(:message) { 'Jira settings saved, but not active.' }
it_behaves_like 'service update'
it_behaves_like 'integration update'
end
context 'when param `inherit_from_id` is set to empty string' do
let(:service_params) { { inherit_from_id: '' } }
let(:integration_params) { { inherit_from_id: '' } }
it 'sets inherit_from_id to nil' do
expect(service.reload.inherit_from_id).to eq(nil)
expect(integration.reload.inherit_from_id).to eq(nil)
end
end
context 'when param `inherit_from_id` is set to some value' do
let(:instance_service) { create(:jira_integration, :instance) }
let(:service_params) { { inherit_from_id: instance_service.id } }
let(:integration_params) { { inherit_from_id: instance_service.id } }
it 'sets inherit_from_id to value' do
expect(service.reload.inherit_from_id).to eq(instance_service.id)
expect(integration.reload.inherit_from_id).to eq(instance_service.id)
end
end
end
......@@ -233,11 +235,11 @@ RSpec.describe Projects::ServicesController do
describe 'as JSON' do
before do
stub_jira_integration_test
put :update, params: project_params(service: service_params, format: :json)
put :update, params: project_params(service: integration_params, format: :json)
end
context 'when update succeeds' do
let(:service_params) { { url: 'http://example.com' } }
let(:integration_params) { { url: 'http://example.com' } }
it 'returns JSON response with no errors' do
expect(response).to be_successful
......@@ -246,60 +248,67 @@ RSpec.describe Projects::ServicesController do
end
context 'when update fails' do
let(:service_params) { { url: '' } }
let(:integration_params) { { url: '' } }
it 'returns JSON response with errors' do
expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response).to include(
'active' => true,
'errors' => { 'url' => ['must be a valid URL', %{can't be blank}] }
'errors' => { 'url' => ['must be a valid URL', %(can't be blank)] }
)
end
end
end
context 'Prometheus integration' do
let_it_be(:service) { create(:prometheus_integration, project: project) }
context 'with Prometheus integration' do
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } }
let(:integration) { prometheus_integration }
let(:integration_params) { { manual_configuration: '1', api_url: 'http://example.com' } }
context 'feature flag :settings_operations_prometheus_service is enabled' do
context 'when feature flag :settings_operations_prometheus_service is enabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: true)
end
it 'redirects user back to edit page with alert' do
put :update, params: project_params.merge(service: service_params)
put :update, params: project_params.merge(service: integration_params)
expect(response).to redirect_to(edit_project_service_path(project, service))
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated."
expect(response).to redirect_to(edit_project_service_path(project, integration))
expected_alert = [
"You can now manage your Prometheus settings on the",
%(<a href="#{project_settings_operations_path(project)}">Operations</a> page.),
"Fields on this page have been deprecated."
].join(' ')
expect(controller).to set_flash.now[:alert].to(expected_alert)
end
it 'does not modify integration' do
expect { put :update, params: project_params.merge(service: service_params) }.not_to change { project.prometheus_integration.reload.attributes }
expect { put :update, params: project_params.merge(service: integration_params) }
.not_to change { project.prometheus_integration.reload.attributes }
end
end
context 'feature flag :settings_operations_prometheus_service is disabled' do
context 'when feature flag :settings_operations_prometheus_service is disabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: false)
end
it 'modifies integration' do
expect { put :update, params: project_params.merge(service: service_params) }.to change { project.prometheus_integration.reload.attributes }
expect { put :update, params: project_params.merge(service: integration_params) }
.to change { project.prometheus_integration.reload.attributes }
end
end
end
end
describe 'GET #edit' do
context 'Jira service' do
let(:service_param) { 'jira' }
context 'with Jira service' do
let(:integration_param) { 'jira' }
before do
get :edit, params: project_params(id: service_param)
get :edit, params: project_params(id: integration_param)
end
context 'with approved services' do
......@@ -309,25 +318,30 @@ RSpec.describe Projects::ServicesController do
end
end
context 'Prometheus service' do
let(:service_param) { 'prometheus' }
context 'with Prometheus service' do
let(:integration_param) { 'prometheus' }
context 'feature flag :settings_operations_prometheus_service is enabled' do
context 'when feature flag :settings_operations_prometheus_service is enabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: true)
get :edit, params: project_params(id: service_param)
get :edit, params: project_params(id: integration_param)
end
it 'renders deprecation warning notice' do
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated."
expected_alert = [
"You can now manage your Prometheus settings on the",
%(<a href="#{project_settings_operations_path(project)}">Operations</a> page.),
"Fields on this page have been deprecated."
].join(' ')
expect(controller).to set_flash.now[:alert].to(expected_alert)
end
end
context 'feature flag :settings_operations_prometheus_service is disabled' do
context 'when feature flag :settings_operations_prometheus_service is disabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: false)
get :edit, params: project_params(id: service_param)
get :edit, params: project_params(id: integration_param)
end
it 'does not render deprecation warning notice' do
......@@ -343,7 +357,7 @@ RSpec.describe Projects::ServicesController do
opts.reverse_merge(
namespace_id: project.namespace,
project_id: project,
id: service.to_param
id: integration.to_param
)
end
end
......@@ -17,6 +17,6 @@ RSpec.describe 'User activates Prometheus' do
click_button('Save changes')
expect(page).not_to have_content('Prometheus settings saved and active.')
expect(page).to have_content('Fields on this page has been deprecated.')
expect(page).to have_content('Fields on this page have been deprecated.')
end
end
......@@ -217,8 +217,6 @@ RSpec.describe Banzai::Filter::References::ExternalIssueReferenceFilter do
context "ewm project" do
let_it_be(:integration) { create(:ewm_integration, project: project) }
let(:service) { integration } # TODO: remove when https://gitlab.com/gitlab-org/gitlab/-/issues/330300 is complete
before do
project.update!(issues_enabled: false)
end
......
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