Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js18
-rw-r--r--spec/lib/gitlab/error_tracking_spec.rb32
-rw-r--r--spec/lib/gitlab/http_spec.rb15
-rw-r--r--spec/models/member_spec.rb80
-rw-r--r--spec/models/members/group_member_spec.rb14
-rw-r--r--spec/services/event_create_service_spec.rb34
-rw-r--r--spec/services/notification_service_spec.rb99
-rw-r--r--spec/support/helpers/features/invite_members_modal_helpers.rb1
-rw-r--r--spec/support/helpers/stub_configuration.rb4
-rw-r--r--spec/support/shared_examples/models/members_notifications_shared_example.rb12
10 files changed, 222 insertions, 87 deletions
diff --git a/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js b/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js
index 86dc9afaacc..745886161ce 100644
--- a/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js
+++ b/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js
@@ -42,6 +42,8 @@ describe('Source Viewer component', () => {
let wrapper;
let fakeApollo;
const CHUNKS_MOCK = [CHUNK_1, CHUNK_2];
+ const projectPath = 'test';
+ const currentRef = 'main';
const hash = '#L142';
const blameDataQueryHandlerSuccess = jest.fn().mockResolvedValue(BLAME_DATA_QUERY_RESPONSE_MOCK);
@@ -57,8 +59,8 @@ describe('Source Viewer component', () => {
propsData: {
blob: { ...blob, ...BLOB_DATA_MOCK },
chunks: CHUNKS_MOCK,
- projectPath: 'test',
- currentRef: 'main',
+ projectPath,
+ currentRef,
showBlame,
},
});
@@ -116,6 +118,18 @@ describe('Source Viewer component', () => {
expect(findBlameComponents().at(0).props()).toMatchObject({ blameInfo });
});
+ it('calls the blame data query', async () => {
+ await triggerChunkAppear();
+
+ expect(blameDataQueryHandlerSuccess).toHaveBeenCalledWith(
+ expect.objectContaining({
+ filePath: BLOB_DATA_MOCK.path,
+ fullPath: projectPath,
+ ref: currentRef,
+ }),
+ );
+ });
+
it('calls the query only once per chunk', async () => {
// We trigger the `appear` event multiple times here in order to simulate the user scrolling past the chunk more than once.
// In this scenario we only want to query the backend once.
diff --git a/spec/lib/gitlab/error_tracking_spec.rb b/spec/lib/gitlab/error_tracking_spec.rb
index c9b2e21d934..7b2c5ca27cb 100644
--- a/spec/lib/gitlab/error_tracking_spec.rb
+++ b/spec/lib/gitlab/error_tracking_spec.rb
@@ -173,6 +173,20 @@ RSpec.describe Gitlab::ErrorTracking, feature_category: :shared do
)
end.to raise_error(RuntimeError)
end
+
+ it 'processes the exception even it is called within a `restrict_within_concurrent_ruby` block' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error).with(logger_payload)
+
+ expect do
+ Gitlab::Utils.restrict_within_concurrent_ruby do
+ described_class.track_and_raise_exception(
+ exception,
+ issue_url: issue_url,
+ some_other_info: 'info'
+ )
+ end
+ end.to raise_error(RuntimeError, /boom/)
+ end
end
describe '.log_and_raise_exception' do
@@ -188,6 +202,16 @@ RSpec.describe Gitlab::ErrorTracking, feature_category: :shared do
expect { log_and_raise_exception }.to raise_error(RuntimeError)
end
+ it 'processes the exception even it is called within a `restrict_within_concurrent_ruby` block' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error).with(logger_payload)
+
+ expect do
+ Gitlab::Utils.restrict_within_concurrent_ruby do
+ log_and_raise_exception
+ end
+ end.to raise_error(RuntimeError)
+ end
+
context 'when extra details are provided' do
let(:extra) { { test: 1, my_token: 'test' } }
@@ -230,6 +254,14 @@ RSpec.describe Gitlab::ErrorTracking, feature_category: :shared do
expect(Gitlab::ErrorTracking::Logger).to have_received(:error).with(logger_payload)
end
+ it 'processes the exception even it is called within a `restrict_within_concurrent_ruby` block' do
+ Gitlab::Utils.restrict_within_concurrent_ruby do
+ track_exception
+ end
+
+ expect(Gitlab::ErrorTracking::Logger).to have_received(:error).with(logger_payload)
+ end
+
context 'with tags' do
let(:tags) { { 'mytag' => 2 } }
diff --git a/spec/lib/gitlab/http_spec.rb b/spec/lib/gitlab/http_spec.rb
index 402790616b6..c23f4ea8ffa 100644
--- a/spec/lib/gitlab/http_spec.rb
+++ b/spec/lib/gitlab/http_spec.rb
@@ -55,8 +55,19 @@ RSpec.describe Gitlab::HTTP, feature_category: :shared do
end
context 'when there is a DB call in the concurrent thread' do
- it 'raises Gitlab::Utils::ConcurrentRubyThreadIsUsedError error',
- quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/432145' do
+ before do
+ # Simulating Sentry is active and configured.
+ # More info: https://gitlab.com/gitlab-org/gitlab/-/issues/432145#note_1671305713
+ stub_sentry_settings
+ allow(Gitlab::ErrorTracking).to receive(:sentry_configurable?).and_return(true)
+ Gitlab::ErrorTracking.configure
+ end
+
+ after do
+ clear_sentry_settings
+ end
+
+ it 'raises Gitlab::Utils::ConcurrentRubyThreadIsUsedError error' do
stub_request(:get, 'http://example.org').to_return(status: 200, body: 'hello world')
result = described_class.get('http://example.org', async: true) do |_fragment|
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb
index 38b1cf35bbf..9ebff2a8886 100644
--- a/spec/models/member_spec.rb
+++ b/spec/models/member_spec.rb
@@ -1121,6 +1121,86 @@ RSpec.describe Member, feature_category: :groups_and_projects do
end
end
+ context 'when after_create :post_create_hook' do
+ include NotificationHelpers
+
+ let_it_be(:source) { create(:group) }
+ let(:member) { create(:group_member, source: source) }
+
+ subject(:create_member) { member }
+
+ shared_examples_for 'invokes a notification' do
+ it 'enqueues an email to user' do
+ create_member
+
+ expect_delivery_jobs_count(1)
+ expect_enqueud_email(member.real_source_type, member.id, mail: 'member_access_granted_email')
+ end
+ end
+
+ shared_examples_for 'performs all the common hooks' do
+ it_behaves_like 'invokes a notification'
+
+ it 'creates an event' do
+ expect { create_member }.to change { Event.count }.by(1)
+ end
+ end
+
+ it 'calls the system hook service' do
+ expect_next_instance_of(SystemHooksService) do |instance|
+ expect(instance).to receive(:execute_hooks_for).with(an_instance_of(GroupMember), :create)
+ end
+
+ create_member
+ end
+
+ context 'when source is a group' do
+ it_behaves_like 'invokes a notification'
+
+ it 'does not create an event' do
+ expect { create_member }.not_to change { Event.count }
+ end
+ end
+
+ context 'when source is a project' do
+ context 'when source is a personal project' do
+ let_it_be(:namespace) { create(:namespace) }
+
+ context 'when member is the owner of the namespace' do
+ subject(:create_member) { create(:project, namespace: namespace) }
+
+ it 'does not enqueue an email' do
+ create_member
+
+ expect_delivery_jobs_count(0)
+ end
+
+ it 'does not create an event' do
+ expect { create_member }.not_to change { Event.count }
+ end
+ end
+
+ context 'when member is not the namespace owner' do
+ let_it_be(:project) { create(:project, namespace: namespace) }
+ let(:member) { create(:project_member, source: project) }
+
+ subject(:create_member) { member }
+
+ it_behaves_like 'performs all the common hooks'
+ end
+ end
+
+ context 'when source is not a personal project' do
+ let_it_be(:project) { create(:project, namespace: create(:group)) }
+ let(:member) { create(:project_member, source: project) }
+
+ subject(:create_member) { member }
+
+ it_behaves_like 'performs all the common hooks'
+ end
+ end
+ end
+
describe 'log_invitation_token_cleanup' do
let_it_be(:project) { create :project }
diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb
index a7508f0e616..4df0b1e6af5 100644
--- a/spec/models/members/group_member_spec.rb
+++ b/spec/models/members/group_member_spec.rb
@@ -276,18 +276,4 @@ RSpec.describe GroupMember, feature_category: :cell do
it_behaves_like 'calls AuthorizedProjectsWorker inline to recalculate authorizations'
end
end
-
- context 'group member welcome email', :sidekiq_inline, :saas do
- let_it_be(:group) { create(:group) }
-
- let(:user) { create(:user) }
-
- it 'schedules plain welcome to the group email' do
- expect_next_instance_of(NotificationService) do |notification|
- expect(notification).to receive(:new_group_member)
- end
-
- group.add_developer(user)
- end
- end
end
diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb
index 6a4769d77d5..f7041fb818e 100644
--- a/spec/services/event_create_service_spec.rb
+++ b/spec/services/event_create_service_spec.rb
@@ -364,19 +364,37 @@ RSpec.describe EventCreateService, :clean_gitlab_redis_cache, :clean_gitlab_redi
end
end
- describe 'Project' do
- describe '#join_project' do
- subject { service.join_project(project, user) }
+ describe '#join_source' do
+ let(:source) { project }
+ subject(:join_source) { service.join_source(source, user) }
+
+ context 'when source is a group' do
+ let_it_be(:source) { create(:group) }
+
+ it { is_expected.to be_falsey }
+
+ specify do
+ expect { join_source }.not_to change { Event.count }
+ end
+ end
+
+ context 'when source is a project' do
it { is_expected.to be_truthy }
- it { expect { subject }.to change { Event.count }.from(0).to(1) }
+
+ specify do
+ expect { join_source }.to change { Event.count }.from(0).to(1)
+ end
end
+ end
- describe '#expired_leave_project' do
- subject { service.expired_leave_project(project, user) }
+ describe '#expired_leave_project' do
+ subject(:expired_leave_project) { service.expired_leave_project(project, user) }
- it { is_expected.to be_truthy }
- it { expect { subject }.to change { Event.count }.from(0).to(1) }
+ it { is_expected.to be_truthy }
+
+ specify do
+ expect { expired_leave_project }.to change { Event.count }.from(0).to(1)
end
end
diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb
index 910e1d85a6b..15e7f794795 100644
--- a/spec/services/notification_service_spec.rb
+++ b/spec/services/notification_service_spec.rb
@@ -3294,31 +3294,6 @@ RSpec.describe NotificationService, :mailer, feature_category: :team_planning do
let(:source) { group }
end
end
-
- describe '#new_group_member' do
- let(:group) { create(:group) }
-
- it 'sends a notification' do
- group.add_guest(added_user)
- should_only_email(added_user)
- end
-
- describe 'when notifications are disabled' do
- before do
- create_global_setting_for(added_user, :disabled)
- end
-
- it 'does not send a notification' do
- group.add_guest(added_user)
- should_not_email_anyone
- end
- end
-
- it_behaves_like 'group emails are disabled' do
- let(:notification_target) { group }
- let(:notification_trigger) { group.add_guest(added_user) }
- end
- end
end
describe 'ProjectMember', :deliver_mails_inline do
@@ -3448,29 +3423,6 @@ RSpec.describe NotificationService, :mailer, feature_category: :team_planning do
end
end
- describe '#new_project_member' do
- it do
- create_member!
- should_only_email(added_user)
- end
-
- it_behaves_like 'project emails are disabled' do
- let(:notification_target) { project }
- let(:notification_trigger) { create_member! }
- end
-
- context 'when notifications are disabled' do
- before do
- create_global_setting_for(added_user, :disabled)
- end
-
- it do
- create_member!
- should_not_email_anyone
- end
- end
- end
-
describe '#member_about_to_expire' do
let_it_be(:group_member) { create(:group_member, expires_at: 7.days.from_now.to_date) }
let_it_be(:project_member) { create(:project_member, expires_at: 7.days.from_now.to_date) }
@@ -3491,9 +3443,56 @@ RSpec.describe NotificationService, :mailer, feature_category: :team_planning do
end
end
end
+ end
+
+ describe '#new_member', :deliver_mails_inline do
+ let_it_be(:source) { create(:group) }
+ let_it_be(:added_user) { create(:user) }
+
+ subject(:new_member) { notification.new_member(member) }
+
+ shared_examples_for 'new member added' do |source_type|
+ it 'triggers a notification about about the added access', deliver_mails_inline: false do
+ new_member
- def create_member!
- create(:project_member, user: added_user, project: project)
+ expect_delivery_jobs_count(1)
+ expect_enqueud_email(source_type, member.id, mail: 'member_access_granted_email')
+ end
+ end
+
+ context 'when source is a Group' do
+ it_behaves_like 'new member added', 'Group' do
+ let_it_be(:member) { create(:group_member, source: source) }
+ end
+
+ it_behaves_like 'group emails are disabled' do
+ let(:notification_target) { source }
+ let(:notification_trigger) { notification_target.add_guest(added_user) }
+ end
+ end
+
+ context 'when source is a Project' do
+ let_it_be(:source) { create(:project) }
+
+ it_behaves_like 'new member added', 'Project' do
+ let_it_be(:member) { create(:project_member, source: project) }
+ end
+
+ it_behaves_like 'project emails are disabled' do
+ let_it_be(:notification_target) { source }
+ let(:notification_trigger) { source.add_guest(added_user) }
+ end
+ end
+
+ context 'when notifications are disabled' do
+ before do
+ create_global_setting_for(added_user, :disabled)
+ end
+
+ it 'does not send a notification' do
+ source.add_guest(added_user)
+ should_not_email_anyone
+ end
end
end
diff --git a/spec/support/helpers/features/invite_members_modal_helpers.rb b/spec/support/helpers/features/invite_members_modal_helpers.rb
index c40e060bc8e..fd37abd7381 100644
--- a/spec/support/helpers/features/invite_members_modal_helpers.rb
+++ b/spec/support/helpers/features/invite_members_modal_helpers.rb
@@ -66,6 +66,7 @@ module Features
def choose_options(role, expires_at)
page.within role_dropdown_selector do
+ wait_for_requests
toggle_listbox
select_listbox_item(role, exact_text: true)
end
diff --git a/spec/support/helpers/stub_configuration.rb b/spec/support/helpers/stub_configuration.rb
index e043d1249b9..f76a208fee3 100644
--- a/spec/support/helpers/stub_configuration.rb
+++ b/spec/support/helpers/stub_configuration.rb
@@ -120,6 +120,10 @@ module StubConfiguration
.to receive(:sentry_clientside_dsn) { clientside_dsn }
end
+ def clear_sentry_settings
+ Sentry.get_current_scope.clear
+ end
+
def stub_microsoft_graph_mailer_setting(messages)
allow(Gitlab.config.microsoft_graph_mailer).to receive_messages(to_settings(messages))
end
diff --git a/spec/support/shared_examples/models/members_notifications_shared_example.rb b/spec/support/shared_examples/models/members_notifications_shared_example.rb
index 17dc927f3cc..58ce3daec40 100644
--- a/spec/support/shared_examples/models/members_notifications_shared_example.rb
+++ b/spec/support/shared_examples/models/members_notifications_shared_example.rb
@@ -9,16 +9,6 @@ RSpec.shared_examples 'members notifications' do |entity_type|
allow(member).to receive(:notification_service).and_return(notification_service)
end
- describe "#after_create" do
- let(:member) { build(:"#{entity_type}_member", "#{entity_type}": create(entity_type.to_s), user: user) }
-
- it "sends email to user" do
- expect(notification_service).to receive(:"new_#{entity_type}_member").with(member)
-
- member.save!
- end
- end
-
describe '#after_commit' do
context 'on creation of a member requesting access' do
let(:member) do
@@ -37,7 +27,7 @@ RSpec.shared_examples 'members notifications' do |entity_type|
let(:member) { create(:"#{entity_type}_member", :access_request) }
it "calls NotificationService.new_#{entity_type}_member" do
- expect(notification_service).to receive(:"new_#{entity_type}_member").with(member)
+ expect(notification_service).to receive(:new_member).with(member)
member.accept_request(create(:user))
end