Commit 6a25b9c9 authored by Justin Ho's avatar Justin Ho

Add integrations#test to check if integration is working

- Add specs for other controller actions
- Add JS required to init form and buttons
- Add changelog
parent 9aeea3d4
import IntegrationSettingsForm from '~/integrations/integration_settings_form';
import PrometheusMetrics from '~/prometheus_metrics/prometheus_metrics';
import initAlertsSettings from '~/alerts_service_settings';
document.addEventListener('DOMContentLoaded', () => {
const prometheusSettingsWrapper = document.querySelector('.js-prometheus-metrics-monitoring');
const integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form');
console.log(integrationSettingsForm);
integrationSettingsForm.init();
if (prometheusSettingsWrapper) {
const prometheusMetrics = new PrometheusMetrics('.js-prometheus-metrics-monitoring');
prometheusMetrics.loadActiveMetrics();
}
initAlertsSettings(document.querySelector('.js-alerts-service-settings'));
});
......@@ -9,7 +9,9 @@ class Admin::IntegrationsController < Admin::ApplicationController
end
def update
if @service.update(service_params[:service])
@service.attributes = service_params[:service]
if @service.save(context: :manual_change)
redirect_to edit_admin_application_settings_integration_path(@service), notice: success_message
else
render :edit
......@@ -17,12 +19,22 @@ class Admin::IntegrationsController < Admin::ApplicationController
end
def test
if @service.can_test?
render json: service_test_response, status: :ok
else
render json: {}, status: :not_found
end
end
private
def project
# TODO: Change to something more meaningful
Project.first
end
def set_integration
@service ||= Project.first.find_or_initialize_service(params[:id])
@service ||= project.find_or_initialize_service(params[:id])
end
def success_message
......@@ -32,4 +44,21 @@ class Admin::IntegrationsController < Admin::ApplicationController
_('%{service_title} settings saved, but not activated.') % { service_title: @service.title }
end
end
def service_test_response
if @service.update(service_params[:service])
data = @service.test_data(project, current_user)
outcome = @service.test(data)
if outcome[:success]
{}
else
{ error: true, message: _('Test failed.'), service_response: outcome[:result].to_s, test_failed: true }
end
else
{ error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
end
rescue Gitlab::HTTP::BlockedUrlError => e
{ error: true, message: _('Test failed.'), service_response: e.message, test_failed: true }
end
end
......@@ -3,8 +3,11 @@
%p= @service.description
= form_for :service, url: admin_application_settings_integration_path, method: :put, html: { class: 'fieldset-form' } do |form|
= form_for @service, as: :service, url: admin_application_settings_integration_path, method: :put, html: { class: 'gl-show-field-errors fieldset-form integration-settings-form js-integration-settings-form', data: { 'can-test' => @service.can_test?, 'test-url' => test_admin_application_settings_integration_path(@service) } } do |form|
= render 'shared/service_settings', form: form, service: @service
.footer-block.row-content-block
= form.submit 'Save', class: 'btn btn-success'
- if @service.editable?
.footer-block.row-content-block
= service_save_button(@service)
&nbsp;
= link_to _('Cancel'), admin_application_settings_integration_path, class: 'btn btn-cancel'
---
title: Add CRUD for Instance-Level Integrations
merge_request: 26454
author:
type: added
......@@ -121,7 +121,11 @@ namespace :admin do
get '/', to: redirect('admin/application_settings/general'), as: nil
resources :services, only: [:index, :edit, :update]
resources :integrations, only: [:edit, :update, :test]
resources :integrations, only: [:edit, :update, :test] do
member do
put :test
end
end
get :usage_data
put :reset_registration_token
......
# frozen_string_literal: true
require 'spec_helper'
describe Admin::IntegrationsController do
let(:admin) { create(:admin) }
let!(:project) { create(:project) }
before do
sign_in(admin)
end
describe '#edit' do
Service.available_services_names.each do |integration_name|
context "#{integration_name}" do
it 'successfully displays the template' do
get :edit, params: { id: integration_name }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
end
end
end
end
describe '#update' do
let(:integration) { create(:jira_service, project: project) }
before do
put :update, params: { id: integration.class.to_param, service: { url: url } }
end
context 'valid params' do
let(:url) { 'https://jira.gitlab-example.com' }
it 'updates the integration' do
expect(response).to have_gitlab_http_status(:found)
expect(integration.reload.url).to eq(url)
end
end
context 'invalid params' do
let(:url) { 'https://jira.localhost' }
it 'does not update the integration' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
expect(integration.reload.url).not_to eq(url)
end
end
end
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