debian-mirror-gitlab/spec/controllers/groups/settings/integrations_controller_spec.rb

115 lines
3.1 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Groups::Settings::IntegrationsController do
2020-04-22 19:07:51 +05:30
let(:user) { create(:user) }
let(:group) { create(:group) }
before do
sign_in(user)
end
describe '#index' do
context 'when user is not owner' do
it 'renders not_found' do
get :index, params: { group_id: group }
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when user is owner' do
before do
group.add_owner(user)
end
context 'when group_level_integrations not enabled' do
it 'returns not_found' do
2020-05-24 23:13:21 +05:30
stub_feature_flags(group_level_integrations: false)
2020-04-22 19:07:51 +05:30
get :index, params: { group_id: group }
expect(response).to have_gitlab_http_status(:not_found)
end
end
it 'successfully displays the template' do
get :index, params: { group_id: group }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
end
end
describe '#edit' do
context 'when user is not owner' do
it 'renders not_found' do
2021-01-29 00:20:46 +05:30
get :edit, params: { group_id: group, id: Service.available_services_names(include_project_specific: false).sample }
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when user is owner' do
before do
group.add_owner(user)
end
context 'when group_level_integrations not enabled' do
it 'returns not_found' do
2020-05-24 23:13:21 +05:30
stub_feature_flags(group_level_integrations: false)
2020-04-22 19:07:51 +05:30
2021-01-29 00:20:46 +05:30
get :edit, params: { group_id: group, id: Service.available_services_names(include_project_specific: false).sample }
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
end
2021-01-29 00:20:46 +05:30
Service.available_services_names(include_project_specific: false).each do |integration_name|
2020-04-22 19:07:51 +05:30
context "#{integration_name}" do
it 'successfully displays the template' do
get :edit, params: { group_id: group, id: integration_name }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
end
end
end
end
end
describe '#update' do
2020-11-24 15:15:51 +05:30
include JiraServiceHelper
let(:integration) { create(:jira_service, project: nil, group_id: group.id) }
2020-04-22 19:07:51 +05:30
before do
group.add_owner(user)
2020-11-24 15:15:51 +05:30
stub_jira_service_test
2020-04-22 19:07:51 +05:30
put :update, params: { group_id: group, 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) { 'invalid' }
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