diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-30 12:07:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-30 12:07:58 +0000 |
commit | 7c28a677895df5195ed6342921934734646c90c9 (patch) | |
tree | 651181e5b0b4534700249ac94e14d16eca823524 /spec | |
parent | d08bee6aaf36fb6cd922f130f5596484c64562c0 (diff) | |
download | gitlab-ce-7c28a677895df5195ed6342921934734646c90c9.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/profiles/personal_access_tokens_controller_spec.rb | 12 | ||||
-rw-r--r-- | spec/features/profiles/personal_access_tokens_spec.rb | 11 | ||||
-rw-r--r-- | spec/frontend/diffs/components/app_spec.js | 46 | ||||
-rw-r--r-- | spec/frontend/tracking_spec.js | 46 | ||||
-rw-r--r-- | spec/lib/gitlab/content_security_policy/config_loader_spec.rb | 30 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/client_metrics_spec.rb | 36 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/integrations/ewm_spec.rb | 10 | ||||
-rw-r--r-- | spec/models/integrations/jira_spec.rb | 189 | ||||
-rw-r--r-- | spec/models/integrations/microsoft_teams_spec.rb | 44 |
11 files changed, 298 insertions, 131 deletions
diff --git a/spec/controllers/profiles/personal_access_tokens_controller_spec.rb b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb index 1fdd1200028..3859af66292 100644 --- a/spec/controllers/profiles/personal_access_tokens_controller_spec.rb +++ b/spec/controllers/profiles/personal_access_tokens_controller_spec.rb @@ -64,5 +64,17 @@ RSpec.describe Profiles::PersonalAccessTokensController do it "retrieves newly created personal access token value" do expect(assigns(:new_personal_access_token)).to eql(token_value) end + + it "sets PAT name and scopes" do + name = 'My PAT' + scopes = 'api,read_user' + + get :index, params: { name: name, scopes: scopes } + + expect(assigns(:personal_access_token)).to have_attributes( + name: eq(name), + scopes: contain_exactly(:api, :read_user) + ) + end end end diff --git a/spec/features/profiles/personal_access_tokens_spec.rb b/spec/features/profiles/personal_access_tokens_spec.rb index 1166ebd944f..de511e99182 100644 --- a/spec/features/profiles/personal_access_tokens_spec.rb +++ b/spec/features/profiles/personal_access_tokens_spec.rb @@ -149,4 +149,15 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do expect(page).to have_pushed_frontend_feature_flags(personalAccessTokensScopedToProjects: true) end + + it "prefills token details" do + name = 'My PAT' + scopes = 'api,read_user' + + visit profile_personal_access_tokens_path({ name: name, scopes: scopes }) + + expect(page).to have_field("Token name", with: name) + expect(find("#personal_access_token_scopes_api")).to be_checked + expect(find("#personal_access_token_scopes_read_user")).to be_checked + end end diff --git a/spec/frontend/diffs/components/app_spec.js b/spec/frontend/diffs/components/app_spec.js index 8a1c5547581..b5eb3e1713c 100644 --- a/spec/frontend/diffs/components/app_spec.js +++ b/spec/frontend/diffs/components/app_spec.js @@ -6,14 +6,19 @@ import Vue, { nextTick } from 'vue'; import Vuex from 'vuex'; import { TEST_HOST } from 'spec/test_constants'; import App from '~/diffs/components/app.vue'; -import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue'; import CommitWidget from '~/diffs/components/commit_widget.vue'; import CompareVersions from '~/diffs/components/compare_versions.vue'; import DiffFile from '~/diffs/components/diff_file.vue'; -import HiddenFilesWarning from '~/diffs/components/hidden_files_warning.vue'; import NoChanges from '~/diffs/components/no_changes.vue'; import TreeList from '~/diffs/components/tree_list.vue'; +/* eslint-disable import/order */ +/* You know what: sometimes alphabetical isn't the best order */ +import CollapsedFilesWarning from '~/diffs/components/collapsed_files_warning.vue'; +import HiddenFilesWarning from '~/diffs/components/hidden_files_warning.vue'; +import MergeConflictWarning from '~/diffs/components/merge_conflict_warning.vue'; +/* eslint-enable import/order */ + import axios from '~/lib/utils/axios_utils'; import * as urlUtils from '~/lib/utils/url_utility'; import createDiffsStore from '../create_diffs_store'; @@ -541,6 +546,43 @@ describe('diffs/components/app', () => { expect(getCollapsedFilesWarning(wrapper).exists()).toBe(false); }); }); + + describe('merge conflicts', () => { + it('should render the merge conflicts banner if viewing the whole changeset and there are conflicts', () => { + createComponent({}, ({ state }) => { + Object.assign(state.diffs, { + latestDiff: true, + startVersion: null, + hasConflicts: true, + canMerge: false, + conflictResolutionPath: 'path', + }); + }); + + expect(wrapper.find(MergeConflictWarning).exists()).toBe(true); + }); + + it.each` + prop | value + ${'latestDiff'} | ${false} + ${'startVersion'} | ${'notnull'} + ${'hasConflicts'} | ${false} + `( + "should not render if any of the MR properties aren't correct - like $prop: $value", + ({ prop, value }) => { + createComponent({}, ({ state }) => { + Object.assign(state.diffs, { + latestDiff: true, + startVersion: null, + hasConflicts: true, + [prop]: value, + }); + }); + + expect(wrapper.find(MergeConflictWarning).exists()).toBe(false); + }, + ); + }); }); it('should display commit widget if store has a commit', () => { diff --git a/spec/frontend/tracking_spec.js b/spec/frontend/tracking_spec.js index d8dae2b2dc0..13498cfb823 100644 --- a/spec/frontend/tracking_spec.js +++ b/spec/frontend/tracking_spec.js @@ -197,6 +197,52 @@ describe('Tracking', () => { expectedError, ); }); + + it('does not add empty form whitelist rules', () => { + Tracking.enableFormTracking({ fields: { allow: ['input-class1'] } }); + + expect(snowplowSpy).toHaveBeenCalledWith( + 'enableFormTracking', + { fields: { whitelist: ['input-class1'] } }, + [], + ); + }); + + describe('when `document.readyState` does not equal `complete`', () => { + const originalReadyState = document.readyState; + const setReadyState = (value) => { + Object.defineProperty(document, 'readyState', { + value, + configurable: true, + }); + }; + const fireReadyStateChangeEvent = () => { + document.dispatchEvent(new Event('readystatechange')); + }; + + beforeEach(() => { + setReadyState('interactive'); + }); + + afterEach(() => { + setReadyState(originalReadyState); + }); + + it('does not call `window.snowplow` until `readystatechange` is fired and `document.readyState` equals `complete`', () => { + Tracking.enableFormTracking({ fields: { allow: ['input-class1'] } }); + + expect(snowplowSpy).not.toHaveBeenCalled(); + + fireReadyStateChangeEvent(); + + expect(snowplowSpy).not.toHaveBeenCalled(); + + setReadyState('complete'); + fireReadyStateChangeEvent(); + + expect(snowplowSpy).toHaveBeenCalled(); + }); + }); }); describe('.flushPendingEvents', () => { diff --git a/spec/lib/gitlab/content_security_policy/config_loader_spec.rb b/spec/lib/gitlab/content_security_policy/config_loader_spec.rb index d08057fb10a..8e63e771caa 100644 --- a/spec/lib/gitlab/content_security_policy/config_loader_spec.rb +++ b/spec/lib/gitlab/content_security_policy/config_loader_spec.rb @@ -61,6 +61,36 @@ RSpec.describe Gitlab::ContentSecurityPolicy::ConfigLoader do expect(directives['font_src']).to eq("'self' https://example.com") end end + + context 'when CUSTOMER_PORTAL_URL is set' do + before do + stub_env('CUSTOMER_PORTAL_URL', 'https://customers.example.com') + end + + context 'when in production' do + before do + allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production')) + end + + it 'does not add CUSTOMER_PORTAL_URL to CSP' do + directives = settings['directives'] + + expect(directives['frame_src']).to eq("'self' https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com") + end + end + + context 'when in development' do + before do + allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development')) + end + + it 'adds CUSTOMER_PORTAL_URL to CSP' do + directives = settings['directives'] + + expect(directives['frame_src']).to eq("'self' https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com https://customers.example.com") + end + end + end end describe '#load' do diff --git a/spec/lib/gitlab/sidekiq_middleware/client_metrics_spec.rb b/spec/lib/gitlab/sidekiq_middleware/client_metrics_spec.rb index 82ca84f0697..698758a13fd 100644 --- a/spec/lib/gitlab/sidekiq_middleware/client_metrics_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/client_metrics_spec.rb @@ -3,11 +3,12 @@ require 'spec_helper' RSpec.describe Gitlab::SidekiqMiddleware::ClientMetrics do + let(:enqueued_jobs_metric) { double('enqueued jobs metric', increment: true) } + shared_examples "a metrics middleware" do context "with mocked prometheus" do - let(:enqueued_jobs_metric) { double('enqueued jobs metric', increment: true) } - before do + labels[:scheduling] = 'immediate' allow(Gitlab::Metrics).to receive(:counter).with(described_class::ENQUEUED, anything).and_return(enqueued_jobs_metric) end @@ -32,4 +33,35 @@ RSpec.describe Gitlab::SidekiqMiddleware::ClientMetrics do end it_behaves_like 'metrics middleware with worker attribution' + + context 'when mounted' do + before do + stub_const('TestWorker', Class.new) + TestWorker.class_eval do + include Sidekiq::Worker + + def perform(*args) + end + end + + allow(Gitlab::Metrics).to receive(:counter).and_return(Gitlab::Metrics::NullMetric.instance) + allow(Gitlab::Metrics).to receive(:counter).with(described_class::ENQUEUED, anything).and_return(enqueued_jobs_metric) + end + + context 'when scheduling jobs for immediate execution' do + it 'increments enqueued jobs metric with scheduling label set to immediate' do + expect(enqueued_jobs_metric).to receive(:increment).with(a_hash_including(scheduling: 'immediate'), 1) + + Sidekiq::Testing.inline! { TestWorker.perform_async } + end + end + + context 'when scheduling jobs for future execution' do + it 'increments enqueued jobs metric with scheduling label set to delayed' do + expect(enqueued_jobs_metric).to receive(:increment).with(a_hash_including(scheduling: 'delayed'), 1) + + Sidekiq::Testing.inline! { TestWorker.perform_in(1.second) } + end + end + end end diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index 4efacae0a48..d89202ae7fe 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -46,7 +46,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s 'pipeline_authoring', 'epics_usage', 'epic_boards_usage', - 'secure' + 'secure', + 'network_policies' ) end end diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 8652f9c4a58..145ca750ad6 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -1269,7 +1269,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do let(:categories) { ::Gitlab::UsageDataCounters::HLLRedisCounter.categories } let(:ineligible_total_categories) do - %w[source_code ci_secrets_management incident_management_alerts snippets terraform incident_management_oncall secure] + %w[source_code ci_secrets_management incident_management_alerts snippets terraform incident_management_oncall secure network_policies] end context 'with redis_hll_tracking feature enabled' do diff --git a/spec/models/integrations/ewm_spec.rb b/spec/models/integrations/ewm_spec.rb index 38897adb447..2baf670f4ae 100644 --- a/spec/models/integrations/ewm_spec.rb +++ b/spec/models/integrations/ewm_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Integrations::Ewm do end describe 'Validations' do - context 'when service is active' do + context 'when integration is active' do before do subject.active = true end @@ -17,12 +17,12 @@ RSpec.describe Integrations::Ewm do it { is_expected.to validate_presence_of(:project_url) } it { is_expected.to validate_presence_of(:issues_url) } it { is_expected.to validate_presence_of(:new_issue_url) } - it_behaves_like 'issue tracker service URL attribute', :project_url - it_behaves_like 'issue tracker service URL attribute', :issues_url - it_behaves_like 'issue tracker service URL attribute', :new_issue_url + it_behaves_like 'issue tracker integration URL attribute', :project_url + it_behaves_like 'issue tracker integration URL attribute', :issues_url + it_behaves_like 'issue tracker integration URL attribute', :new_issue_url end - context 'when service is inactive' do + context 'when integration is inactive' do before do subject.active = false end diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index d63f5261915..37a0920153e 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -100,9 +100,9 @@ RSpec.describe Integrations::Jira do end 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 expect(fields.pluck(:name)).to eq(%w[url api_url username password]) @@ -146,39 +146,35 @@ RSpec.describe Integrations::Jira do } end - subject { described_class.create!(params) } + subject(:integration) { described_class.create!(params) } it 'does not store data into properties' do - expect(subject.properties).to be_nil + expect(integration.properties).to be_nil end it 'stores data in data_fields correctly' do - service = subject - - expect(service.jira_tracker_data.url).to eq(url) - expect(service.jira_tracker_data.api_url).to eq(api_url) - expect(service.jira_tracker_data.username).to eq(username) - expect(service.jira_tracker_data.password).to eq(password) - expect(service.jira_tracker_data.jira_issue_transition_id).to eq(transition_id) - expect(service.jira_tracker_data.deployment_cloud?).to be_truthy + expect(integration.jira_tracker_data.url).to eq(url) + expect(integration.jira_tracker_data.api_url).to eq(api_url) + expect(integration.jira_tracker_data.username).to eq(username) + expect(integration.jira_tracker_data.password).to eq(password) + expect(integration.jira_tracker_data.jira_issue_transition_id).to eq(transition_id) + expect(integration.jira_tracker_data.deployment_cloud?).to be_truthy end context 'when loading serverInfo' do - let(:jira_integration) { subject } - - context 'from a Cloud instance' do + context 'with a Cloud instance' do let(:server_info_results) { { 'deploymentType' => 'Cloud' } } 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 - context 'from a Server instance' do + context 'with a Server instance' do let(:server_info_results) { { 'deploymentType' => 'Server' } } 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 @@ -189,7 +185,7 @@ RSpec.describe Integrations::Jira do let(:api_url) { 'http://example-api.atlassian.net' } 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 @@ -197,7 +193,7 @@ RSpec.describe Integrations::Jira do let(:api_url) { 'http://my-jira-api.someserver.com' } 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 @@ -210,7 +206,7 @@ RSpec.describe Integrations::Jira 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(jira_integration.jira_tracker_data.deployment_cloud?).to be_truthy + expect(integration.jira_tracker_data).to be_deployment_cloud end end @@ -219,7 +215,7 @@ RSpec.describe Integrations::Jira 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(jira_integration.jira_tracker_data.deployment_server?).to be_truthy + expect(integration.jira_tracker_data).to be_deployment_server end end end @@ -253,11 +249,11 @@ RSpec.describe Integrations::Jira do context 'reading data' do it 'reads data correctly' do - expect(service.url).to eq(url) - expect(service.api_url).to eq(api_url) - expect(service.username).to eq(username) - expect(service.password).to eq(password) - expect(service.jira_issue_transition_id).to eq(transition_id) + expect(integration.url).to eq(url) + expect(integration.api_url).to eq(api_url) + expect(integration.username).to eq(username) + expect(integration.password).to eq(password) + expect(integration.jira_issue_transition_id).to eq(transition_id) end end @@ -267,15 +263,11 @@ RSpec.describe Integrations::Jira do let_it_be(:new_url) { 'http://jira-new.example.com' } before do - service.update!(username: new_username, url: new_url) - end - - it 'leaves properties field emtpy' do - # expect(service.reload.properties).to be_empty + integration.update!(username: new_username, url: new_url) end 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.api_url).to eq(api_url) @@ -288,15 +280,15 @@ RSpec.describe Integrations::Jira do context 'when updating the url, api_url, username, or password' do context 'when updating the integration' do it 'updates deployment type' do - service.update!(url: 'http://first.url') - service.jira_tracker_data.update!(deployment_type: 'server') + integration.update!(url: 'http://first.url') + 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') - service.jira_tracker_data.reload + integration.update!(api_url: 'http://another.url') + 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 end end @@ -305,34 +297,34 @@ RSpec.describe Integrations::Jira do let(:server_info_results) { {} } 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 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/) end 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/) end it 'calls serverInfo for username' do - service.update!(username: 'test-user') + integration.update!(username: 'test-user') expect(WebMock).to have_requested(:get, /serverInfo/) end it 'calls serverInfo for password' do - service.update!(password: 'test-password') + integration.update!(password: 'test-password') expect(WebMock).to have_requested(:get, /serverInfo/) end @@ -340,7 +332,8 @@ RSpec.describe Integrations::Jira do context 'when not updating the url, api_url, username, or password' 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/) end @@ -348,9 +341,9 @@ RSpec.describe Integrations::Jira do context 'when not allowed to test an instance or group' 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/) end @@ -368,68 +361,68 @@ RSpec.describe Integrations::Jira do end it 'resets password if url changed' do - service - service.url = 'http://jira_edited.example.com' - service.save! + integration + integration.url = 'http://jira_edited.example.com' + integration.save! - expect(service.reload.url).to eq('http://jira_edited.example.com') - expect(service.password).to be_nil + expect(integration.reload.url).to eq('http://jira_edited.example.com') + expect(integration.password).to be_nil end it 'does not reset password if url "changed" to the same url as before' do - service.url = 'http://jira.example.com' - service.save! + integration.url = 'http://jira.example.com' + integration.save! - expect(service.reload.url).to eq('http://jira.example.com') - expect(service.password).not_to be_nil + expect(integration.reload.url).to eq('http://jira.example.com') + expect(integration.password).not_to be_nil end it 'resets password if url not changed but api url added' do - service.api_url = 'http://jira_edited.example.com/rest/api/2' - service.save! + integration.api_url = 'http://jira_edited.example.com/rest/api/2' + integration.save! - expect(service.reload.api_url).to eq('http://jira_edited.example.com/rest/api/2') - expect(service.password).to be_nil + expect(integration.reload.api_url).to eq('http://jira_edited.example.com/rest/api/2') + expect(integration.password).to be_nil end 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' - service.password = password - service.save! + integration.url = 'http://jira_edited.example.com' + integration.password = password + integration.save! - expect(service.password).to eq(password) - expect(service.url).to eq('http://jira_edited.example.com') + expect(integration.password).to eq(password) + expect(integration.url).to eq('http://jira_edited.example.com') end it 'resets password if url changed, even if setter called multiple times' do - service.url = 'http://jira1.example.com/rest/api/2' - service.url = 'http://jira1.example.com/rest/api/2' - service.save! + integration.url = 'http://jira1.example.com/rest/api/2' + integration.url = 'http://jira1.example.com/rest/api/2' + integration.save! - expect(service.password).to be_nil + expect(integration.password).to be_nil end it 'does not reset password if username changed' do - service.username = 'some_name' - service.save! + integration.username = 'some_name' + integration.save! - expect(service.reload.password).to eq(password) + expect(integration.reload.password).to eq(password) end it 'does not reset password if password changed' do - service.url = 'http://jira_edited.example.com' - service.password = 'new_password' - service.save! + integration.url = 'http://jira_edited.example.com' + integration.password = 'new_password' + integration.save! - expect(service.reload.password).to eq('new_password') + expect(integration.reload.password).to eq('new_password') end it 'does not reset password if the password is touched and same as before' do - service.url = 'http://jira_edited.example.com' - service.password = password - service.save! + integration.url = 'http://jira_edited.example.com' + integration.password = password + integration.save! - expect(service.reload.password).to eq(password) + expect(integration.reload.password).to eq(password) end end @@ -443,23 +436,23 @@ RSpec.describe Integrations::Jira do end it 'resets password if api url changed' do - service.api_url = 'http://jira_edited.example.com/rest/api/2' - service.save! + integration.api_url = 'http://jira_edited.example.com/rest/api/2' + integration.save! - expect(service.password).to be_nil + expect(integration.password).to be_nil end it 'does not reset password if url changed' do - service.url = 'http://jira_edited.example.com' - service.save! + integration.url = 'http://jira_edited.example.com' + integration.save! - expect(service.password).to eq(password) + expect(integration.password).to eq(password) end 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 @@ -472,11 +465,11 @@ RSpec.describe Integrations::Jira do end it 'saves password if new url is set together with password' do - service.url = 'http://jira_edited.example.com/rest/api/2' - service.password = 'password' - service.save! - expect(service.reload.password).to eq('password') - expect(service.reload.url).to eq('http://jira_edited.example.com/rest/api/2') + integration.url = 'http://jira_edited.example.com/rest/api/2' + integration.password = 'password' + integration.save! + expect(integration.reload.password).to eq('password') + expect(integration.reload.url).to eq('http://jira_edited.example.com/rest/api/2') end end end @@ -486,7 +479,7 @@ RSpec.describe Integrations::Jira do # this will be removed as part of https://gitlab.com/gitlab-org/gitlab/issues/29404 context 'when data are stored in properties' do let(:properties) { data_params } - let!(:service) do + let!(:integration) do create(:jira_integration, :without_properties_callback, properties: properties.merge(additional: 'something')) end @@ -494,7 +487,7 @@ RSpec.describe Integrations::Jira do end context 'when data are stored in separated fields' do - let(:service) do + let(:integration) do create(:jira_integration, data_params.merge(properties: {})) end @@ -503,7 +496,7 @@ RSpec.describe Integrations::Jira do context 'when data are stored in both properties and separated fields' do 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_tracker_data, data_params.merge(integration: integration)) end diff --git a/spec/models/integrations/microsoft_teams_spec.rb b/spec/models/integrations/microsoft_teams_spec.rb index a7b45ebec87..ab2846d8ccb 100644 --- a/spec/models/integrations/microsoft_teams_spec.rb +++ b/spec/models/integrations/microsoft_teams_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Integrations::MicrosoftTeams do - let(:chat_service) { described_class.new } + let(:chat_integration) { described_class.new } let(:webhook_url) { 'https://example.gitlab.com/' } describe "Associations" do @@ -12,16 +12,16 @@ RSpec.describe Integrations::MicrosoftTeams do end describe 'Validations' do - context 'when service is active' do + context 'when integration is active' do before do subject.active = true end it { is_expected.to validate_presence_of(:webhook) } - it_behaves_like 'issue tracker service URL attribute', :webhook + it_behaves_like 'issue tracker integration URL attribute', :webhook end - context 'when service is inactive' do + context 'when integration is inactive' do before do subject.active = false end @@ -42,7 +42,7 @@ RSpec.describe Integrations::MicrosoftTeams do let_it_be(:project) { create(:project, :repository, :wiki_repo) } before do - allow(chat_service).to receive_messages( + allow(chat_integration).to receive_messages( project: project, project_id: project.id, service_hook: true, @@ -58,7 +58,7 @@ RSpec.describe Integrations::MicrosoftTeams do end it "calls Microsoft Teams API for push events" do - chat_service.execute(push_sample_data) + chat_integration.execute(push_sample_data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -67,7 +67,7 @@ RSpec.describe Integrations::MicrosoftTeams do integration = double(:microsoft_teams_integration).as_null_object expect(::MicrosoftTeams::Notifier).to receive(:new).with(webhook_url).and_return(integration) - chat_service.execute(push_sample_data) + chat_integration.execute(push_sample_data) end end @@ -80,7 +80,7 @@ RSpec.describe Integrations::MicrosoftTeams do end it "calls Microsoft Teams API" do - chat_service.execute(issues_sample_data) + chat_integration.execute(issues_sample_data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -107,7 +107,7 @@ RSpec.describe Integrations::MicrosoftTeams do end it "calls Microsoft Teams API" do - chat_service.execute(merge_sample_data) + chat_integration.execute(merge_sample_data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -127,7 +127,7 @@ RSpec.describe Integrations::MicrosoftTeams do let(:wiki_page_sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') } it "calls Microsoft Teams API" do - chat_service.execute(wiki_page_sample_data) + chat_integration.execute(wiki_page_sample_data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -139,7 +139,7 @@ RSpec.describe Integrations::MicrosoftTeams do let(:project) { create(:project, :repository, creator: user) } before do - allow(chat_service).to receive_messages( + allow(chat_integration).to receive_messages( project: project, project_id: project.id, service_hook: true, @@ -160,7 +160,7 @@ RSpec.describe Integrations::MicrosoftTeams do it "calls Microsoft Teams API for commit comment events" do data = Gitlab::DataBuilder::Note.build(commit_note, user) - chat_service.execute(data) + chat_integration.execute(data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -175,7 +175,7 @@ RSpec.describe Integrations::MicrosoftTeams do it "calls Microsoft Teams API for merge request comment events" do data = Gitlab::DataBuilder::Note.build(merge_request_note, user) - chat_service.execute(data) + chat_integration.execute(data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -189,7 +189,7 @@ RSpec.describe Integrations::MicrosoftTeams do it "calls Microsoft Teams API for issue comment events" do data = Gitlab::DataBuilder::Note.build(issue_note, user) - chat_service.execute(data) + chat_integration.execute(data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -204,7 +204,7 @@ RSpec.describe Integrations::MicrosoftTeams do it "calls Microsoft Teams API for snippet comment events" do data = Gitlab::DataBuilder::Note.build(snippet_note, user) - chat_service.execute(data) + chat_integration.execute(data) expect(WebMock).to have_requested(:post, webhook_url).once end @@ -222,7 +222,7 @@ RSpec.describe Integrations::MicrosoftTeams do end before do - allow(chat_service).to receive_messages( + allow(chat_integration).to receive_messages( project: project, service_hook: true, webhook: webhook_url @@ -232,14 +232,14 @@ RSpec.describe Integrations::MicrosoftTeams do shared_examples 'call Microsoft Teams API' do |branches_to_be_notified: nil| before do WebMock.stub_request(:post, webhook_url) - chat_service.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified + chat_integration.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified end it 'calls Microsoft Teams API for pipeline events' do data = Gitlab::DataBuilder::Pipeline.build(pipeline) data[:markdown] = true - chat_service.execute(data) + chat_integration.execute(data) message = Integrations::ChatMessage::PipelineMessage.new(data) @@ -251,11 +251,11 @@ RSpec.describe Integrations::MicrosoftTeams do shared_examples 'does not call Microsoft Teams API' do |branches_to_be_notified: nil| before do - chat_service.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified + chat_integration.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified end it 'does not call Microsoft Teams API for pipeline events' do data = Gitlab::DataBuilder::Pipeline.build(pipeline) - result = chat_service.execute(data) + result = chat_integration.execute(data) expect(result).to be_falsy end @@ -273,7 +273,7 @@ RSpec.describe Integrations::MicrosoftTeams do context 'with default to notify_only_broken_pipelines' do it 'does not call Microsoft Teams API for pipeline events' do data = Gitlab::DataBuilder::Pipeline.build(pipeline) - result = chat_service.execute(data) + result = chat_integration.execute(data) expect(result).to be_falsy end @@ -281,7 +281,7 @@ RSpec.describe Integrations::MicrosoftTeams do context 'with setting notify_only_broken_pipelines to false' do before do - chat_service.notify_only_broken_pipelines = false + chat_integration.notify_only_broken_pipelines = false end it_behaves_like 'call Microsoft Teams API' |