summaryrefslogtreecommitdiff
path: root/spec/services/users/update_assigned_open_issue_count_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/users/update_assigned_open_issue_count_service_spec.rb')
-rw-r--r--spec/services/users/update_assigned_open_issue_count_service_spec.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/services/users/update_assigned_open_issue_count_service_spec.rb b/spec/services/users/update_assigned_open_issue_count_service_spec.rb
new file mode 100644
index 00000000000..55fc60a7893
--- /dev/null
+++ b/spec/services/users/update_assigned_open_issue_count_service_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Users::UpdateAssignedOpenIssueCountService do
+ let_it_be(:user) { create(:user) }
+
+ describe '#initialize' do
+ context 'incorrect arguments provided' do
+ it 'raises an error if there are no target user' do
+ expect { described_class.new(target_user: nil) }.to raise_error(ArgumentError, /Please provide a target user/)
+ expect { described_class.new(target_user: "nonsense") }.to raise_error(ArgumentError, /Please provide a target user/)
+ end
+ end
+
+ context 'when correct arguments provided' do
+ it 'is successful' do
+ expect { described_class.new(target_user: user) }.not_to raise_error
+ end
+ end
+ end
+
+ describe "#execute", :clean_gitlab_redis_cache do
+ let(:fake_update_service) { double }
+ let(:fake_issue_count_service) { double }
+ let(:provided_value) { nil }
+
+ subject { described_class.new(target_user: user).execute }
+
+ context 'successful' do
+ it 'returns a success response' do
+ expect(subject).to be_success
+ end
+
+ it 'writes the cache with the new value' do
+ expect(Rails.cache).to receive(:write).with(['users', user.id, 'assigned_open_issues_count'], 0, expires_in: User::COUNT_CACHE_VALIDITY_PERIOD)
+
+ subject
+ end
+
+ it 'calls the issues finder to get the latest value' do
+ expect(IssuesFinder).to receive(:new).with(user, assignee_id: user.id, state: 'opened', non_archived: true).and_return(fake_issue_count_service)
+ expect(fake_issue_count_service).to receive(:execute)
+
+ subject
+ end
+ end
+ end
+end