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

update_assigned_open_issue_count_service_spec.rb « users « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55fc60a7893269652affbba2da6c8b0cd188da8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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