debian-mirror-gitlab/spec/features/projects/services/user_activates_jira_spec.rb

104 lines
3.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2018-03-17 18:26:18 +05:30
describe 'User activates Jira', :js do
2017-09-10 17:25:29 +05:30
let(:user) { create(:user) }
let(:project) { create(:project) }
let(:url) { 'http://jira.example.com' }
let(:test_url) { 'http://jira.example.com/rest/api/2/serverInfo' }
2020-03-13 15:44:24 +05:30
def fill_form(disabled: false)
2020-04-22 19:07:51 +05:30
find('input[name="service[active]"] + button').click if disabled
2017-09-10 17:25:29 +05:30
fill_in 'service_url', with: url
fill_in 'service_username', with: 'username'
fill_in 'service_password', with: 'password'
fill_in 'service_jira_issue_transition_id', with: '25'
end
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
visit project_settings_integrations_path(project)
end
describe 'user sets and activates Jira Service' do
context 'when Jira connection test succeeds' do
2018-03-27 19:54:05 +05:30
before do
2017-09-10 17:25:29 +05:30
server_info = { key: 'value' }.to_json
WebMock.stub_request(:get, test_url).with(basic_auth: %w(username password)).to_return(body: server_info)
2019-09-30 21:07:59 +05:30
click_link('Jira')
2017-09-10 17:25:29 +05:30
fill_form
click_button('Test settings and save changes')
wait_for_requests
2018-03-27 19:54:05 +05:30
end
2017-09-10 17:25:29 +05:30
2019-09-30 21:07:59 +05:30
it 'activates the Jira service' do
expect(page).to have_content('Jira activated.')
2017-09-10 17:25:29 +05:30
expect(current_path).to eq(project_settings_integrations_path(project))
end
2018-03-27 19:54:05 +05:30
2019-09-30 21:07:59 +05:30
it 'shows the Jira link in the menu' do
2018-03-27 19:54:05 +05:30
page.within('.nav-sidebar') do
2019-09-30 21:07:59 +05:30
expect(page).to have_link('Jira', href: url)
2018-03-27 19:54:05 +05:30
end
end
2017-09-10 17:25:29 +05:30
end
context 'when Jira connection test fails' do
it 'shows errors when some required fields are not filled in' do
2019-09-30 21:07:59 +05:30
click_link('Jira')
2017-09-10 17:25:29 +05:30
fill_in 'service_password', with: 'password'
click_button('Test settings and save changes')
page.within('.service-settings') do
expect(page).to have_content('This field is required.')
end
end
2019-09-30 21:07:59 +05:30
it 'activates the Jira service' do
2017-09-10 17:25:29 +05:30
WebMock.stub_request(:get, test_url).with(basic_auth: %w(username password))
.to_raise(JIRA::HTTPError.new(double(message: 'message')))
2019-09-30 21:07:59 +05:30
click_link('Jira')
2017-09-10 17:25:29 +05:30
fill_form
click_button('Test settings and save changes')
wait_for_requests
expect(find('.flash-container-page')).to have_content 'Test failed. message'
expect(find('.flash-container-page')).to have_content 'Save anyway'
2018-03-17 18:26:18 +05:30
find('.flash-alert .flash-action').click
2017-09-10 17:25:29 +05:30
wait_for_requests
2019-09-30 21:07:59 +05:30
expect(page).to have_content('Jira activated.')
2017-09-10 17:25:29 +05:30
expect(current_path).to eq(project_settings_integrations_path(project))
end
end
end
2020-03-13 15:44:24 +05:30
describe 'user disables the Jira Service' do
2018-03-27 19:54:05 +05:30
before do
2019-09-30 21:07:59 +05:30
click_link('Jira')
2020-03-13 15:44:24 +05:30
fill_form(disabled: true)
2018-03-27 19:54:05 +05:30
click_button('Save changes')
end
2017-09-10 17:25:29 +05:30
2019-09-30 21:07:59 +05:30
it 'saves but does not activate the Jira service' do
expect(page).to have_content('Jira settings saved, but not activated.')
2018-03-27 19:54:05 +05:30
expect(current_path).to eq(project_settings_integrations_path(project))
end
2019-09-30 21:07:59 +05:30
it 'does not show the Jira link in the menu' do
2018-03-27 19:54:05 +05:30
page.within('.nav-sidebar') do
2019-09-30 21:07:59 +05:30
expect(page).not_to have_link('Jira', href: url)
2017-09-10 17:25:29 +05:30
end
end
end
end