Commit af2320c7 authored by Imre Farkas's avatar Imre Farkas

Merge branch '330300-ajk-model-specs-12' into 'master'

Rename references to services in Jira integration model specs

See merge request gitlab-org/gitlab!65020
parents 2d589a39 246116e0
...@@ -100,9 +100,9 @@ RSpec.describe Integrations::Jira do ...@@ -100,9 +100,9 @@ RSpec.describe Integrations::Jira do
end end
describe '#fields' do describe '#fields' do
let(:service) { create(:jira_integration) } let(:integration) { create(:jira_integration) }
subject(:fields) { service.fields } subject(:fields) { integration.fields }
it 'returns custom fields' do it 'returns custom fields' do
expect(fields.pluck(:name)).to eq(%w[url api_url username password]) expect(fields.pluck(:name)).to eq(%w[url api_url username password])
...@@ -146,39 +146,35 @@ RSpec.describe Integrations::Jira do ...@@ -146,39 +146,35 @@ RSpec.describe Integrations::Jira do
} }
end end
subject { described_class.create!(params) } subject(:integration) { described_class.create!(params) }
it 'does not store data into properties' do it 'does not store data into properties' do
expect(subject.properties).to be_nil expect(integration.properties).to be_nil
end end
it 'stores data in data_fields correctly' do it 'stores data in data_fields correctly' do
service = subject expect(integration.jira_tracker_data.url).to eq(url)
expect(integration.jira_tracker_data.api_url).to eq(api_url)
expect(service.jira_tracker_data.url).to eq(url) expect(integration.jira_tracker_data.username).to eq(username)
expect(service.jira_tracker_data.api_url).to eq(api_url) expect(integration.jira_tracker_data.password).to eq(password)
expect(service.jira_tracker_data.username).to eq(username) expect(integration.jira_tracker_data.jira_issue_transition_id).to eq(transition_id)
expect(service.jira_tracker_data.password).to eq(password) expect(integration.jira_tracker_data.deployment_cloud?).to be_truthy
expect(service.jira_tracker_data.jira_issue_transition_id).to eq(transition_id)
expect(service.jira_tracker_data.deployment_cloud?).to be_truthy
end end
context 'when loading serverInfo' do context 'when loading serverInfo' do
let(:jira_integration) { subject } context 'with a Cloud instance' do
context 'from a Cloud instance' do
let(:server_info_results) { { 'deploymentType' => 'Cloud' } } let(:server_info_results) { { 'deploymentType' => 'Cloud' } }
it 'is detected' do it 'is detected' do
expect(jira_integration.jira_tracker_data.deployment_cloud?).to be_truthy expect(integration.jira_tracker_data).to be_deployment_cloud
end end
end end
context 'from a Server instance' do context 'with a Server instance' do
let(:server_info_results) { { 'deploymentType' => 'Server' } } let(:server_info_results) { { 'deploymentType' => 'Server' } }
it 'is detected' do it 'is detected' do
expect(jira_integration.jira_tracker_data.deployment_server?).to be_truthy expect(integration.jira_tracker_data).to be_deployment_server
end end
end end
...@@ -189,7 +185,7 @@ RSpec.describe Integrations::Jira do ...@@ -189,7 +185,7 @@ RSpec.describe Integrations::Jira do
let(:api_url) { 'http://example-api.atlassian.net' } let(:api_url) { 'http://example-api.atlassian.net' }
it 'deployment_type is set to cloud' do it 'deployment_type is set to cloud' do
expect(jira_integration.jira_tracker_data.deployment_cloud?).to be_truthy expect(integration.jira_tracker_data).to be_deployment_cloud
end end
end end
...@@ -197,7 +193,7 @@ RSpec.describe Integrations::Jira do ...@@ -197,7 +193,7 @@ RSpec.describe Integrations::Jira do
let(:api_url) { 'http://my-jira-api.someserver.com' } let(:api_url) { 'http://my-jira-api.someserver.com' }
it 'deployment_type is set to server' do it 'deployment_type is set to server' do
expect(jira_integration.jira_tracker_data.deployment_server?).to be_truthy expect(integration.jira_tracker_data).to be_deployment_server
end end
end end
end end
...@@ -210,7 +206,7 @@ RSpec.describe Integrations::Jira do ...@@ -210,7 +206,7 @@ RSpec.describe Integrations::Jira do
it 'deployment_type is set to cloud' do it 'deployment_type is set to cloud' do
expect(Gitlab::AppLogger).to receive(:warn).with(message: "Jira API returned no ServerInfo, setting deployment_type from URL", server_info: server_info_results, url: api_url) expect(Gitlab::AppLogger).to receive(:warn).with(message: "Jira API returned no ServerInfo, setting deployment_type from URL", server_info: server_info_results, url: api_url)
expect(jira_integration.jira_tracker_data.deployment_cloud?).to be_truthy expect(integration.jira_tracker_data).to be_deployment_cloud
end end
end end
...@@ -219,7 +215,7 @@ RSpec.describe Integrations::Jira do ...@@ -219,7 +215,7 @@ RSpec.describe Integrations::Jira do
it 'deployment_type is set to server' do it 'deployment_type is set to server' do
expect(Gitlab::AppLogger).to receive(:warn).with(message: "Jira API returned no ServerInfo, setting deployment_type from URL", server_info: server_info_results, url: api_url) expect(Gitlab::AppLogger).to receive(:warn).with(message: "Jira API returned no ServerInfo, setting deployment_type from URL", server_info: server_info_results, url: api_url)
expect(jira_integration.jira_tracker_data.deployment_server?).to be_truthy expect(integration.jira_tracker_data).to be_deployment_server
end end
end end
end end
...@@ -253,11 +249,11 @@ RSpec.describe Integrations::Jira do ...@@ -253,11 +249,11 @@ RSpec.describe Integrations::Jira do
context 'reading data' do context 'reading data' do
it 'reads data correctly' do it 'reads data correctly' do
expect(service.url).to eq(url) expect(integration.url).to eq(url)
expect(service.api_url).to eq(api_url) expect(integration.api_url).to eq(api_url)
expect(service.username).to eq(username) expect(integration.username).to eq(username)
expect(service.password).to eq(password) expect(integration.password).to eq(password)
expect(service.jira_issue_transition_id).to eq(transition_id) expect(integration.jira_issue_transition_id).to eq(transition_id)
end end
end end
...@@ -267,15 +263,11 @@ RSpec.describe Integrations::Jira do ...@@ -267,15 +263,11 @@ RSpec.describe Integrations::Jira do
let_it_be(:new_url) { 'http://jira-new.example.com' } let_it_be(:new_url) { 'http://jira-new.example.com' }
before do before do
service.update!(username: new_username, url: new_url) integration.update!(username: new_username, url: new_url)
end
it 'leaves properties field emtpy' do
# expect(service.reload.properties).to be_empty
end end
it 'stores updated data in jira_tracker_data table' do it 'stores updated data in jira_tracker_data table' do
data = service.jira_tracker_data.reload data = integration.jira_tracker_data.reload
expect(data.url).to eq(new_url) expect(data.url).to eq(new_url)
expect(data.api_url).to eq(api_url) expect(data.api_url).to eq(api_url)
...@@ -288,15 +280,15 @@ RSpec.describe Integrations::Jira do ...@@ -288,15 +280,15 @@ RSpec.describe Integrations::Jira do
context 'when updating the url, api_url, username, or password' do context 'when updating the url, api_url, username, or password' do
context 'when updating the integration' do context 'when updating the integration' do
it 'updates deployment type' do it 'updates deployment type' do
service.update!(url: 'http://first.url') integration.update!(url: 'http://first.url')
service.jira_tracker_data.update!(deployment_type: 'server') integration.jira_tracker_data.update!(deployment_type: 'server')
expect(service.jira_tracker_data.deployment_server?).to be_truthy expect(integration.jira_tracker_data.deployment_server?).to be_truthy
service.update!(api_url: 'http://another.url') integration.update!(api_url: 'http://another.url')
service.jira_tracker_data.reload integration.jira_tracker_data.reload
expect(service.jira_tracker_data.deployment_cloud?).to be_truthy expect(integration.jira_tracker_data.deployment_cloud?).to be_truthy
expect(WebMock).to have_requested(:get, /serverInfo/).twice expect(WebMock).to have_requested(:get, /serverInfo/).twice
end end
end end
...@@ -305,34 +297,34 @@ RSpec.describe Integrations::Jira do ...@@ -305,34 +297,34 @@ RSpec.describe Integrations::Jira do
let(:server_info_results) { {} } let(:server_info_results) { {} }
it 'updates deployment type' do it 'updates deployment type' do
service.update!(url: nil, api_url: nil, active: false) integration.update!(url: nil, api_url: nil, active: false)
service.jira_tracker_data.reload integration.jira_tracker_data.reload
expect(service.jira_tracker_data.deployment_unknown?).to be_truthy expect(integration.jira_tracker_data.deployment_unknown?).to be_truthy
end end
end end
it 'calls serverInfo for url' do it 'calls serverInfo for url' do
service.update!(url: 'http://first.url') integration.update!(url: 'http://first.url')
expect(WebMock).to have_requested(:get, /serverInfo/) expect(WebMock).to have_requested(:get, /serverInfo/)
end end
it 'calls serverInfo for api_url' do it 'calls serverInfo for api_url' do
service.update!(api_url: 'http://another.url') integration.update!(api_url: 'http://another.url')
expect(WebMock).to have_requested(:get, /serverInfo/) expect(WebMock).to have_requested(:get, /serverInfo/)
end end
it 'calls serverInfo for username' do it 'calls serverInfo for username' do
service.update!(username: 'test-user') integration.update!(username: 'test-user')
expect(WebMock).to have_requested(:get, /serverInfo/) expect(WebMock).to have_requested(:get, /serverInfo/)
end end
it 'calls serverInfo for password' do it 'calls serverInfo for password' do
service.update!(password: 'test-password') integration.update!(password: 'test-password')
expect(WebMock).to have_requested(:get, /serverInfo/) expect(WebMock).to have_requested(:get, /serverInfo/)
end end
...@@ -340,7 +332,8 @@ RSpec.describe Integrations::Jira do ...@@ -340,7 +332,8 @@ RSpec.describe Integrations::Jira do
context 'when not updating the url, api_url, username, or password' do context 'when not updating the url, api_url, username, or password' do
it 'does not update deployment type' do it 'does not update deployment type' do
expect {service.update!(jira_issue_transition_id: 'jira_issue_transition_id')}.to raise_error(ActiveRecord::RecordInvalid) expect { integration.update!(jira_issue_transition_id: 'jira_issue_transition_id') }
.to raise_error(ActiveRecord::RecordInvalid)
expect(WebMock).not_to have_requested(:get, /serverInfo/) expect(WebMock).not_to have_requested(:get, /serverInfo/)
end end
...@@ -348,9 +341,9 @@ RSpec.describe Integrations::Jira do ...@@ -348,9 +341,9 @@ RSpec.describe Integrations::Jira do
context 'when not allowed to test an instance or group' do context 'when not allowed to test an instance or group' do
it 'does not update deployment type' do it 'does not update deployment type' do
allow(service).to receive(:can_test?).and_return(false) allow(integration).to receive(:can_test?).and_return(false)
service.update!(url: 'http://first.url') integration.update!(url: 'http://first.url')
expect(WebMock).not_to have_requested(:get, /serverInfo/) expect(WebMock).not_to have_requested(:get, /serverInfo/)
end end
...@@ -368,68 +361,68 @@ RSpec.describe Integrations::Jira do ...@@ -368,68 +361,68 @@ RSpec.describe Integrations::Jira do
end end
it 'resets password if url changed' do it 'resets password if url changed' do
service integration
service.url = 'http://jira_edited.example.com' integration.url = 'http://jira_edited.example.com'
service.save! integration.save!
expect(service.reload.url).to eq('http://jira_edited.example.com') expect(integration.reload.url).to eq('http://jira_edited.example.com')
expect(service.password).to be_nil expect(integration.password).to be_nil
end end
it 'does not reset password if url "changed" to the same url as before' do it 'does not reset password if url "changed" to the same url as before' do
service.url = 'http://jira.example.com' integration.url = 'http://jira.example.com'
service.save! integration.save!
expect(service.reload.url).to eq('http://jira.example.com') expect(integration.reload.url).to eq('http://jira.example.com')
expect(service.password).not_to be_nil expect(integration.password).not_to be_nil
end end
it 'resets password if url not changed but api url added' do it 'resets password if url not changed but api url added' do
service.api_url = 'http://jira_edited.example.com/rest/api/2' integration.api_url = 'http://jira_edited.example.com/rest/api/2'
service.save! integration.save!
expect(service.reload.api_url).to eq('http://jira_edited.example.com/rest/api/2') expect(integration.reload.api_url).to eq('http://jira_edited.example.com/rest/api/2')
expect(service.password).to be_nil expect(integration.password).to be_nil
end end
it 'does not reset password if new url is set together with password, even if it\'s the same password' do it 'does not reset password if new url is set together with password, even if it\'s the same password' do
service.url = 'http://jira_edited.example.com' integration.url = 'http://jira_edited.example.com'
service.password = password integration.password = password
service.save! integration.save!
expect(service.password).to eq(password) expect(integration.password).to eq(password)
expect(service.url).to eq('http://jira_edited.example.com') expect(integration.url).to eq('http://jira_edited.example.com')
end end
it 'resets password if url changed, even if setter called multiple times' do it 'resets password if url changed, even if setter called multiple times' do
service.url = 'http://jira1.example.com/rest/api/2' integration.url = 'http://jira1.example.com/rest/api/2'
service.url = 'http://jira1.example.com/rest/api/2' integration.url = 'http://jira1.example.com/rest/api/2'
service.save! integration.save!
expect(service.password).to be_nil expect(integration.password).to be_nil
end end
it 'does not reset password if username changed' do it 'does not reset password if username changed' do
service.username = 'some_name' integration.username = 'some_name'
service.save! integration.save!
expect(service.reload.password).to eq(password) expect(integration.reload.password).to eq(password)
end end
it 'does not reset password if password changed' do it 'does not reset password if password changed' do
service.url = 'http://jira_edited.example.com' integration.url = 'http://jira_edited.example.com'
service.password = 'new_password' integration.password = 'new_password'
service.save! integration.save!
expect(service.reload.password).to eq('new_password') expect(integration.reload.password).to eq('new_password')
end end
it 'does not reset password if the password is touched and same as before' do it 'does not reset password if the password is touched and same as before' do
service.url = 'http://jira_edited.example.com' integration.url = 'http://jira_edited.example.com'
service.password = password integration.password = password
service.save! integration.save!
expect(service.reload.password).to eq(password) expect(integration.reload.password).to eq(password)
end end
end end
...@@ -443,23 +436,23 @@ RSpec.describe Integrations::Jira do ...@@ -443,23 +436,23 @@ RSpec.describe Integrations::Jira do
end end
it 'resets password if api url changed' do it 'resets password if api url changed' do
service.api_url = 'http://jira_edited.example.com/rest/api/2' integration.api_url = 'http://jira_edited.example.com/rest/api/2'
service.save! integration.save!
expect(service.password).to be_nil expect(integration.password).to be_nil
end end
it 'does not reset password if url changed' do it 'does not reset password if url changed' do
service.url = 'http://jira_edited.example.com' integration.url = 'http://jira_edited.example.com'
service.save! integration.save!
expect(service.password).to eq(password) expect(integration.password).to eq(password)
end end
it 'resets password if api url set to empty' do it 'resets password if api url set to empty' do
service.update!(api_url: '') integration.update!(api_url: '')
expect(service.reload.password).to be_nil expect(integration.reload.password).to be_nil
end end
end end
end end
...@@ -472,11 +465,11 @@ RSpec.describe Integrations::Jira do ...@@ -472,11 +465,11 @@ RSpec.describe Integrations::Jira do
end end
it 'saves password if new url is set together with password' do it 'saves password if new url is set together with password' do
service.url = 'http://jira_edited.example.com/rest/api/2' integration.url = 'http://jira_edited.example.com/rest/api/2'
service.password = 'password' integration.password = 'password'
service.save! integration.save!
expect(service.reload.password).to eq('password') expect(integration.reload.password).to eq('password')
expect(service.reload.url).to eq('http://jira_edited.example.com/rest/api/2') expect(integration.reload.url).to eq('http://jira_edited.example.com/rest/api/2')
end end
end end
end end
...@@ -486,7 +479,7 @@ RSpec.describe Integrations::Jira do ...@@ -486,7 +479,7 @@ RSpec.describe Integrations::Jira do
# this will be removed as part of https://gitlab.com/gitlab-org/gitlab/issues/29404 # this will be removed as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
context 'when data are stored in properties' do context 'when data are stored in properties' do
let(:properties) { data_params } let(:properties) { data_params }
let!(:service) do let!(:integration) do
create(:jira_integration, :without_properties_callback, properties: properties.merge(additional: 'something')) create(:jira_integration, :without_properties_callback, properties: properties.merge(additional: 'something'))
end end
...@@ -494,7 +487,7 @@ RSpec.describe Integrations::Jira do ...@@ -494,7 +487,7 @@ RSpec.describe Integrations::Jira do
end end
context 'when data are stored in separated fields' do context 'when data are stored in separated fields' do
let(:service) do let(:integration) do
create(:jira_integration, data_params.merge(properties: {})) create(:jira_integration, data_params.merge(properties: {}))
end end
...@@ -503,7 +496,7 @@ RSpec.describe Integrations::Jira do ...@@ -503,7 +496,7 @@ RSpec.describe Integrations::Jira do
context 'when data are stored in both properties and separated fields' do context 'when data are stored in both properties and separated fields' do
let(:properties) { data_params } let(:properties) { data_params }
let(:service) do let(:integration) do
create(:jira_integration, :without_properties_callback, active: false, properties: properties).tap do |integration| create(:jira_integration, :without_properties_callback, active: false, properties: properties).tap do |integration|
create(:jira_tracker_data, data_params.merge(integration: integration)) create(:jira_tracker_data, data_params.merge(integration: integration))
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