File: sync_service_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 (64 lines) | stat: -rw-r--r-- 1,831 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
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RemoteMirrors::SyncService, feature_category: :source_code_management do
  subject(:sync_service) { described_class.new(project, current_user) }

  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:maintainer) { create(:user, maintainer_of: project) }
  let_it_be_with_reload(:remote_mirror) { create(:remote_mirror, project: project, enabled: true) }

  let(:current_user) { maintainer }

  describe '#execute', :aggregate_failures do
    subject(:execute) { sync_service.execute(remote_mirror) }

    it 'triggers a mirror update worker' do
      expect { execute }.to change { RepositoryUpdateRemoteMirrorWorker.jobs.count }.by(1)

      is_expected.to be_success
    end

    context 'when user does not have permissions' do
      let(:current_user) { nil }

      it 'returns an error' do
        is_expected.to be_error
        expect(execute.message).to eq('Access Denied')
      end
    end

    context 'when mirror is missing' do
      let(:remote_mirror) { nil }

      it 'returns an error' do
        is_expected.to be_error
        expect(execute.message).to eq('Mirror does not exist')
      end
    end

    context 'when remote mirror is disabled' do
      before do
        remote_mirror.update!(enabled: false)
      end

      it 'returns an error' do
        is_expected.to be_error
        expect(execute.message).to match(/Cannot proceed with the push mirroring/)
      end
    end

    context 'when remote mirror update has been already started' do
      before do
        remote_mirror.update_start!
      end

      it 'does not trigger a mirror update worker' do
        expect { execute }.not_to change { RepositoryUpdateRemoteMirrorWorker.jobs.count }

        is_expected.to be_success
      end
    end
  end
end