diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-12 21:08:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-12 21:08:58 +0300 |
commit | 31f59b55c63f6a7add79c5987731387ae3a4f7ab (patch) | |
tree | 3786af9493ae5634b35098a184993b2f134a5286 /spec/services | |
parent | 8562dfae56800770e729dcb8215ebf7e1e29a55f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/award_emojis/add_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/award_emojis/base_service_spec.rb | 37 | ||||
-rw-r--r-- | spec/services/award_emojis/destroy_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/test_hooks/project_service_spec.rb | 21 |
4 files changed, 66 insertions, 4 deletions
diff --git a/spec/services/award_emojis/add_service_spec.rb b/spec/services/award_emojis/add_service_spec.rb index 99dbe6dc606..e90ea284f29 100644 --- a/spec/services/award_emojis/add_service_spec.rb +++ b/spec/services/award_emojis/add_service_spec.rb @@ -53,6 +53,12 @@ RSpec.describe AwardEmojis::AddService, feature_category: :team_planning do expect(award.user).to eq(user) end + it 'executes hooks' do + expect(service).to receive(:execute_hooks).with(kind_of(AwardEmoji), 'award') + + service.execute + end + describe 'marking Todos as done' do subject { service.execute } diff --git a/spec/services/award_emojis/base_service_spec.rb b/spec/services/award_emojis/base_service_spec.rb index f1ee4d1cfb8..0f67c619a48 100644 --- a/spec/services/award_emojis/base_service_spec.rb +++ b/spec/services/award_emojis/base_service_spec.rb @@ -3,15 +3,17 @@ require 'spec_helper' RSpec.describe AwardEmojis::BaseService, feature_category: :team_planning do - let(:awardable) { build(:note) } - let(:current_user) { build(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:current_user) { create(:user) } + let_it_be_with_reload(:awardable) { create(:note, project: project) } + + let(:emoji_name) { 'horse' } describe '.initialize' do subject { described_class } it 'uses same emoji name if not an alias' do - emoji_name = 'horse' - expect(subject.new(awardable, emoji_name, current_user).name).to eq(emoji_name) end @@ -22,4 +24,31 @@ RSpec.describe AwardEmojis::BaseService, feature_category: :team_planning do expect(subject.new(awardable, emoji_alias, current_user).name).to eq(emoji_name) end end + + describe '.execute_hooks' do + let(:award_emoji) { create(:award_emoji, awardable: awardable) } + let(:action) { 'award' } + + subject { described_class.new(awardable, emoji_name, current_user) } + + context 'with no emoji hooks configured' do + it 'does not build hook_data' do + expect(Gitlab::DataBuilder::Emoji).not_to receive(:build) + expect(award_emoji.awardable.project).not_to receive(:execute_hooks) + + subject.execute_hooks(award_emoji, action) + end + end + + context 'with emoji hooks configured' do + it 'builds hook_data and calls execute_hooks for project' do + hook_data = {} + create(:project_hook, project: project, emoji_events: true) + expect(Gitlab::DataBuilder::Emoji).to receive(:build).and_return(hook_data) + expect(award_emoji.awardable.project).to receive(:execute_hooks).with(hook_data, :emoji_hooks) + + subject.execute_hooks(award_emoji, action) + end + end + end end diff --git a/spec/services/award_emojis/destroy_service_spec.rb b/spec/services/award_emojis/destroy_service_spec.rb index 109bdbfa986..fbadee87f45 100644 --- a/spec/services/award_emojis/destroy_service_spec.rb +++ b/spec/services/award_emojis/destroy_service_spec.rb @@ -85,6 +85,12 @@ RSpec.describe AwardEmojis::DestroyService, feature_category: :team_planning do expect(result[:award]).to eq(award_from_user) expect(result[:award]).to be_destroyed end + + it 'executes hooks' do + expect(service).to receive(:execute_hooks).with(award_from_user, 'revoke') + + service.execute + end end end end diff --git a/spec/services/test_hooks/project_service_spec.rb b/spec/services/test_hooks/project_service_spec.rb index 31f97edbd08..35c827d5448 100644 --- a/spec/services/test_hooks/project_service_spec.rb +++ b/spec/services/test_hooks/project_service_spec.rb @@ -207,5 +207,26 @@ RSpec.describe TestHooks::ProjectService, feature_category: :code_testing do expect(service.execute).to include(success_result) end end + + context 'emoji' do + let(:trigger) { 'emoji_events' } + let(:trigger_key) { :emoji_hooks } + + it 'returns error message if not enough data' do + expect(hook).not_to receive(:execute) + expect(service.execute).to have_attributes(status: :error, message: 'Ensure the project has notes.') + end + + it 'executes hook' do + note = create(:note) + allow(project).to receive_message_chain(:notes, :any?).and_return(true) + allow(project).to receive_message_chain(:notes, :last).and_return(note) + allow(Gitlab::DataBuilder::Emoji).to receive(:build).with(anything, current_user, 'award') + .and_return(sample_data) + + expect(hook).to receive(:execute).with(sample_data, trigger_key, force: true).and_return(success_result) + expect(service.execute).to include(success_result) + end + end end end |