diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-28 03:11:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-28 03:11:35 +0300 |
commit | 9968d394403ad6601fe8fdf24072fdb1ec08e1a3 (patch) | |
tree | 166816d8e27a067d55203641da6d4bc8a693c549 /spec | |
parent | ff2a881e2038a523c71f0d3f044c496bb7617fd5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/users/login_spec.rb | 6 | ||||
-rw-r--r-- | spec/frontend/vue_shared/alert_details/alert_metrics_spec.js | 63 | ||||
-rw-r--r-- | spec/lib/gitlab/database/async_indexes/migration_helpers_spec.rb | 76 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 24 | ||||
-rw-r--r-- | spec/scripts/pipeline/create_test_failure_issues_spec.rb | 11 | ||||
-rw-r--r-- | spec/services/issues/update_service_spec.rb | 20 |
6 files changed, 106 insertions, 94 deletions
diff --git a/spec/features/users/login_spec.rb b/spec/features/users/login_spec.rb index 55349ea9c46..30afe765044 100644 --- a/spec/features/users/login_spec.rb +++ b/spec/features/users/login_spec.rb @@ -348,7 +348,8 @@ RSpec.describe 'Login', :clean_gitlab_redis_sessions, feature_category: :system_ expect(page).to have_content('Invalid two-factor code') end - it 'allows login with invalid code, then valid code' do + it 'allows login with invalid code, then valid code', + quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/402322' do expect(authentication_metrics) .to increment(:user_authenticated_counter) .and increment(:user_two_factor_authenticated_counter) @@ -362,7 +363,8 @@ RSpec.describe 'Login', :clean_gitlab_redis_sessions, feature_category: :system_ expect(page).to have_current_path root_path, ignore_query: true end - it 'triggers ActiveSession.cleanup for the user', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/402322' do + it 'triggers ActiveSession.cleanup for the user', + quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/402322' do expect(authentication_metrics) .to increment(:user_authenticated_counter) .and increment(:user_two_factor_authenticated_counter) diff --git a/spec/frontend/vue_shared/alert_details/alert_metrics_spec.js b/spec/frontend/vue_shared/alert_details/alert_metrics_spec.js deleted file mode 100644 index 9d84a535d67..00000000000 --- a/spec/frontend/vue_shared/alert_details/alert_metrics_spec.js +++ /dev/null @@ -1,63 +0,0 @@ -import { shallowMount } from '@vue/test-utils'; -import axios from 'axios'; -import MockAdapter from 'axios-mock-adapter'; -import { nextTick } from 'vue'; -import waitForPromises from 'helpers/wait_for_promises'; -import MetricEmbed from '~/monitoring/components/embeds/metric_embed.vue'; -import AlertMetrics from '~/vue_shared/alert_details/components/alert_metrics.vue'; - -jest.mock('~/monitoring/stores', () => ({ - monitoringDashboard: {}, -})); - -jest.mock('~/monitoring/components/embeds/metric_embed.vue', () => ({ - render(h) { - return h('div'); - }, -})); - -describe('Alert Metrics', () => { - let wrapper; - const mock = new MockAdapter(axios); - - function mountComponent({ props } = {}) { - wrapper = shallowMount(AlertMetrics, { - propsData: { - ...props, - }, - }); - } - - const findChart = () => wrapper.findComponent(MetricEmbed); - const findEmptyState = () => wrapper.findComponent({ ref: 'emptyState' }); - - afterEach(() => { - if (wrapper) { - wrapper.destroy(); - } - }); - - afterAll(() => { - mock.restore(); - }); - - describe('Empty state', () => { - it('should display a message when metrics dashboard url is not provided', () => { - mountComponent(); - expect(findChart().exists()).toBe(false); - expect(findEmptyState().text()).toBe("Metrics weren't available in the alerts payload."); - }); - }); - - describe('Chart', () => { - it('should be rendered when dashboard url is provided', async () => { - mountComponent({ props: { dashboardUrl: 'metrics.url' } }); - - await waitForPromises(); - await nextTick(); - - expect(findEmptyState().exists()).toBe(false); - expect(findChart().exists()).toBe(true); - }); - }); -}); diff --git a/spec/lib/gitlab/database/async_indexes/migration_helpers_spec.rb b/spec/lib/gitlab/database/async_indexes/migration_helpers_spec.rb index 4b618d94fd6..b2ba1a60fbb 100644 --- a/spec/lib/gitlab/database/async_indexes/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/async_indexes/migration_helpers_spec.rb @@ -144,10 +144,10 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers, feature_categor end describe '#prepare_async_index_from_sql' do - let(:index_definition) { "CREATE INDEX #{index_name} ON #{table_name} USING btree(id)" } + let(:index_definition) { "CREATE INDEX CONCURRENTLY #{index_name} ON #{table_name} USING btree(id)" } subject(:prepare_async_index_from_sql) do - migration.prepare_async_index_from_sql(table_name, index_name, index_definition) + migration.prepare_async_index_from_sql(index_definition) end before do @@ -162,38 +162,68 @@ RSpec.describe Gitlab::Database::AsyncIndexes::MigrationHelpers, feature_categor expect(Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas).to have_received(:require_ddl_mode!) end - context 'when the async index creation is not available' do - before do - connection.drop_table(:postgres_async_indexes) - end + context 'when the given index is invalid' do + let(:index_definition) { "SELECT FROM users" } - it 'does not raise an error' do - expect { prepare_async_index_from_sql }.not_to raise_error + it 'raises a RuntimeError' do + expect { prepare_async_index_from_sql }.to raise_error(RuntimeError, 'Index statement not found!') end end - context 'when the async index creation is available' do - context 'when there is already an index with the given name' do - before do - connection.add_index(table_name, 'id', name: index_name) - end + context 'when the given index is valid' do + context 'when the index algorithm is not concurrent' do + let(:index_definition) { "CREATE INDEX #{index_name} ON #{table_name} USING btree(id)" } - it 'does not create the async index record' do - expect { prepare_async_index_from_sql }.not_to change { index_model.where(name: index_name).count } + it 'raises a RuntimeError' do + expect { prepare_async_index_from_sql }.to raise_error(RuntimeError, 'Index must be created concurrently!') end end - context 'when there is no index with the given name' do - let(:async_index) { index_model.find_by(name: index_name) } + context 'when the index algorithm is concurrent' do + context 'when the statement tries to create an index for non-existing table' do + let(:index_definition) { "CREATE INDEX CONCURRENTLY #{index_name} ON foo_table USING btree(id)" } - it 'creates the async index record' do - expect { prepare_async_index_from_sql }.to change { index_model.where(name: index_name).count }.by(1) + it 'raises a RuntimeError' do + expect { prepare_async_index_from_sql }.to raise_error(RuntimeError, 'Table does not exist!') + end end - it 'sets the async index attributes correctly' do - prepare_async_index_from_sql - - expect(async_index).to have_attributes(table_name: table_name, definition: index_definition) + context 'when the statement tries to create an index for an existing table' do + context 'when the async index creation is not available' do + before do + connection.drop_table(:postgres_async_indexes) + end + + it 'does not raise an error' do + expect { prepare_async_index_from_sql }.not_to raise_error + end + end + + context 'when the async index creation is available' do + context 'when there is already an index with the given name' do + before do + connection.add_index(table_name, 'id', name: index_name) + end + + it 'does not create the async index record' do + expect { prepare_async_index_from_sql }.not_to change { index_model.where(name: index_name).count } + end + end + + context 'when there is no index with the given name' do + let(:async_index) { index_model.find_by(name: index_name) } + + it 'creates the async index record' do + expect { prepare_async_index_from_sql }.to change { index_model.where(name: index_name).count }.by(1) + end + + it 'sets the async index attributes correctly' do + prepare_async_index_from_sql + + expect(async_index).to have_attributes(table_name: table_name, definition: index_definition) + end + end + end end end end diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 7f838e0caf9..83c132e0969 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -151,9 +151,27 @@ RSpec.describe Notify do it 'has the correct subject and body' do aggregate_failures do is_expected.to have_referable_subject(issue, reply: true) - is_expected.to have_body_text(previous_assignee.name) - is_expected.to have_body_text(assignee.name) - is_expected.to have_body_text(project_issue_path(project, issue)) + is_expected.to have_body_text("Assignee changed from <strong>#{previous_assignee.name}</strong> to <strong>#{assignee.name}</strong>") + is_expected.to have_body_text(%(<a href="#{project_issue_url(project, issue)}">view it on GitLab</a>)) + is_expected.to have_body_text("You're receiving this email because of your account") + end + end + + context 'without new assignee' do + before do + issue.update!(assignees: []) + end + + it 'uses "Unassigned" placeholder' do + is_expected.to have_body_text("Assignee changed from <strong>#{previous_assignee.name}</strong> to <strong>Unassigned</strong>") + end + end + + context 'without previous assignees' do + subject { described_class.reassigned_issue_email(recipient.id, issue.id, [], current_user.id) } + + it 'uses short text' do + is_expected.to have_body_text("Assignee changed to <strong>#{assignee.name}</strong>") end end diff --git a/spec/scripts/pipeline/create_test_failure_issues_spec.rb b/spec/scripts/pipeline/create_test_failure_issues_spec.rb index e8849c32255..9ae18147aaa 100644 --- a/spec/scripts/pipeline/create_test_failure_issues_spec.rb +++ b/spec/scripts/pipeline/create_test_failure_issues_spec.rb @@ -102,7 +102,7 @@ RSpec.describe CreateTestFailureIssues, feature_category: :tooling do ### Test file path - [`#{failed_test['file']}`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/#{failed_test['file']}) + [`#{failed_test['file']}`](https://gitlab.com/example/gitlab/-/blob/master/#{failed_test['file']}) <!-- Don't add anything after the report list since it's updated automatically --> ### Reports (1) @@ -131,8 +131,11 @@ RSpec.describe CreateTestFailureIssues, feature_category: :tooling do end it 'calls CreateIssue#execute(payload)' do + stub_const("#{described_class}::FILE_BASE_URL", 'https://gitlab.com/example/gitlab/-/blob/master/') + expect(CreateIssue).to receive(:new).with(project: project, api_token: api_token) .and_return(create_issue_stub) + expect(create_issue_stub).to receive(:execute).with(expected_create_payload).and_return(issue_stub) creator.upsert(failed_test) @@ -152,7 +155,7 @@ RSpec.describe CreateTestFailureIssues, feature_category: :tooling do ### Test file path - [`#{failed_test['file']}`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/#{failed_test['file']}) + [`#{failed_test['file']}`](https://gitlab.com/example/gitlab/-/blob/master/#{failed_test['file']}) <!-- Don't add anything after the report list since it's updated automatically --> ### Reports (1) @@ -165,7 +168,9 @@ RSpec.describe CreateTestFailureIssues, feature_category: :tooling do double('Issue', iid: 42, title: issue_title, description: issue_description, web_url: 'issue_web_url') end - let(:update_issue_stub) { double('UpdateIssue') } + let(:update_issue_stub) do + double('UpdateIssue', description: latest_format_issue_description) + end let(:expected_update_payload) do { diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb index 4c5d250fdb6..a5a18562ca5 100644 --- a/spec/services/issues/update_service_spec.rb +++ b/spec/services/issues/update_service_spec.rb @@ -1107,19 +1107,37 @@ RSpec.describe Issues::UpdateService, :mailer, feature_category: :team_planning end context 'updating asssignee_id' do + it 'changes assignee' do + expect_next_instance_of(NotificationService::Async) do |service| + expect(service).to receive(:reassigned_issue).with(issue, user, [user3]) + end + + update_issue(assignee_ids: [user2.id]) + + expect(issue.reload.assignees).to eq([user2]) + end + it 'does not update assignee when assignee_id is invalid' do + expect(NotificationService).not_to receive(:new) + update_issue(assignee_ids: [-1]) expect(issue.reload.assignees).to eq([user3]) end it 'unassigns assignee when user id is 0' do + expect_next_instance_of(NotificationService::Async) do |service| + expect(service).to receive(:reassigned_issue).with(issue, user, [user3]) + end + update_issue(assignee_ids: [0]) expect(issue.reload.assignees).to be_empty end it 'does not update assignee_id when user cannot read issue' do + expect(NotificationService).not_to receive(:new) + update_issue(assignee_ids: [create(:user).id]) expect(issue.reload.assignees).to eq([user3]) @@ -1130,6 +1148,8 @@ RSpec.describe Issues::UpdateService, :mailer, feature_category: :team_planning levels.each do |level| it "does not update with unauthorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do + expect(NotificationService).not_to receive(:new) + assignee = create(:user) project.update!(visibility_level: level) feature_visibility_attr = :"#{issue.model_name.plural}_access_level" |