File: copy_timelogs_worker_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (57 lines) | stat: -rw-r--r-- 1,814 bytes parent folder | download
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
50
51
52
53
54
55
56
57
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe WorkItems::CopyTimelogsWorker, type: :worker, feature_category: :team_planning do
  let_it_be(:from_issue) { create(:issue) }
  let_it_be(:to_issue) { create(:issue) }
  let_it_be(:timelog) { create(:timelog, issue: from_issue) }

  it 'has the `until_executed` deduplicate strategy' do
    expect(described_class.get_deduplicate_strategy).to eq(:until_executed)
  end

  describe '#perform' do
    context 'when both issues exist and conditions are met' do
      it 'copies timelogs from one issue to another', :aggregate_failures do
        expect(Gitlab::AppLogger).to receive(:info).with(
          "Copying timelogs from issue #{from_issue.id} to issue #{to_issue.id}")

        expect do
          described_class.new.perform(from_issue.id, to_issue.id)
        end.to change { Timelog.count }.by(1)

        new_timelog = Timelog.last

        expect(new_timelog.issue_id).to eq(to_issue.id)
        expect(new_timelog.project_id).to eq(to_issue.project_id)
      end
    end

    context 'when from_issue does not exist' do
      it 'does not copy timelogs' do
        expect do
          described_class.new.perform(nil, to_issue.id)
        end.not_to change { Timelog.count }
      end
    end

    context 'when to_issue does not exist' do
      it 'does not copy timelogs' do
        expect do
          described_class.new.perform(from_issue.id, nil)
        end.not_to change { Timelog.count }
      end
    end

    context 'when from_issue has no timelogs' do
      let(:from_issue_without_timelog) { create(:issue) }

      it 'does not copy timelogs' do
        expect do
          described_class.new.perform(from_issue_without_timelog.id, to_issue.id)
        end.not_to change { Timelog.count }
      end
    end
  end
end