diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/services/members | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/services/members')
-rw-r--r-- | spec/services/members/destroy_service_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/members/invitation_reminder_email_service_spec.rb | 78 |
2 files changed, 86 insertions, 10 deletions
diff --git a/spec/services/members/destroy_service_spec.rb b/spec/services/members/destroy_service_spec.rb index 3b3f2f3b95a..4f731ad5852 100644 --- a/spec/services/members/destroy_service_spec.rb +++ b/spec/services/members/destroy_service_spec.rb @@ -29,15 +29,15 @@ RSpec.describe Members::DestroyService do end it 'destroys the member' do - expect { described_class.new(current_user).execute(member, opts) }.to change { member.source.members_and_requesters.count }.by(-1) + expect { described_class.new(current_user).execute(member, **opts) }.to change { member.source.members_and_requesters.count }.by(-1) end it 'destroys member notification_settings' do if member_user.notification_settings.any? - expect { described_class.new(current_user).execute(member, opts) } + expect { described_class.new(current_user).execute(member, **opts) } .to change { member_user.notification_settings.count }.by(-1) else - expect { described_class.new(current_user).execute(member, opts) } + expect { described_class.new(current_user).execute(member, **opts) } .not_to change { member_user.notification_settings.count } end end @@ -63,7 +63,7 @@ RSpec.describe Members::DestroyService do expect(service).to receive(:enqueue_unassign_issuables).with(member) end - service.execute(member, opts) + service.execute(member, **opts) expect(member_user.assigned_open_merge_requests_count).to be(0) expect(member_user.assigned_open_issues_count).to be(0) @@ -83,14 +83,14 @@ RSpec.describe Members::DestroyService do it 'calls Member#after_decline_request' do expect_any_instance_of(NotificationService).to receive(:decline_access_request).with(member) - described_class.new(current_user).execute(member, opts) + described_class.new(current_user).execute(member, **opts) end context 'when current user is the member' do it 'does not call Member#after_decline_request' do expect_any_instance_of(NotificationService).not_to receive(:decline_access_request).with(member) - described_class.new(member_user).execute(member, opts) + described_class.new(member_user).execute(member, **opts) end end end @@ -280,7 +280,6 @@ RSpec.describe Members::DestroyService do context 'subresources' do let(:user) { create(:user) } let(:member_user) { create(:user) } - let(:opts) { {} } let(:group) { create(:group, :public) } let(:subgroup) { create(:group, parent: group) } @@ -303,7 +302,7 @@ RSpec.describe Members::DestroyService do group_member = create(:group_member, :developer, group: group, user: member_user) - described_class.new(user).execute(group_member, opts) + described_class.new(user).execute(group_member) end it 'removes the project membership' do @@ -350,7 +349,6 @@ RSpec.describe Members::DestroyService do context 'deletion of invitations created by deleted project member' do let(:user) { project.owner } let(:member_user) { create(:user) } - let(:opts) { {} } let(:project) { create(:project) } @@ -359,7 +357,7 @@ RSpec.describe Members::DestroyService do project_member = create(:project_member, :maintainer, user: member_user, project: project) - described_class.new(user).execute(project_member, opts) + described_class.new(user).execute(project_member) end it 'removes project members invited by deleted user' do diff --git a/spec/services/members/invitation_reminder_email_service_spec.rb b/spec/services/members/invitation_reminder_email_service_spec.rb new file mode 100644 index 00000000000..88280869476 --- /dev/null +++ b/spec/services/members/invitation_reminder_email_service_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Members::InvitationReminderEmailService do + describe 'sending invitation reminders' do + subject { described_class.new(invitation).execute } + + let_it_be(:frozen_time) { Date.today.beginning_of_day } + let_it_be(:invitation) { build(:group_member, :invited, created_at: frozen_time) } + + context 'when the experiment is disabled' do + before do + allow(Gitlab::Experimentation).to receive(:enabled_for_attribute?).and_return(false) + invitation.expires_at = frozen_time + 2.days + end + + it 'does not send an invitation' do + travel_to(frozen_time + 1.day) do + expect(invitation).not_to receive(:send_invitation_reminder) + + subject + end + end + end + + context 'when the experiment is enabled' do + before do + allow(Gitlab::Experimentation).to receive(:enabled_for_attribute?).and_return(true) + invitation.expires_at = frozen_time + expires_at_days.days if expires_at_days + end + + using RSpec::Parameterized::TableSyntax + + where(:expires_at_days, :send_reminder_at_days) do + 0 | [] + 1 | [] + 2 | [1] + 3 | [1, 2] + 4 | [1, 2, 3] + 5 | [1, 2, 4] + 6 | [1, 3, 5] + 7 | [1, 3, 5] + 8 | [2, 3, 6] + 9 | [2, 4, 7] + 10 | [2, 4, 8] + 11 | [2, 4, 8] + 12 | [2, 5, 9] + 13 | [2, 5, 10] + 14 | [2, 5, 10] + 15 | [2, 5, 10] + nil | [2, 5, 10] + end + + with_them do + # Create an invitation today with an expiration date from 0 to 10 days in the future or without an expiration date + # We chose 10 days here, because we fetch invitations that were created at most 10 days ago. + (0..10).each do |day| + it 'sends an invitation reminder only on the expected days' do + next if day > (expires_at_days || 10) # We don't need to test after the invitation has already expired + + # We are traveling in a loop from today to 10 days from now + travel_to(frozen_time + day.days) do + # Given an expiration date and the number of days after the creation of the invitation based on the current day in the loop, a reminder may be sent + if (reminder_index = send_reminder_at_days.index(day)) + expect(invitation).to receive(:send_invitation_reminder).with(reminder_index) + else + expect(invitation).not_to receive(:send_invitation_reminder) + end + + subject + end + end + end + end + end + end +end |