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
65
66
67
68
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Import::Github::CancelProjectImportService, feature_category: :importers do
subject(:import_cancel) { described_class.new(project, project.owner) }
let_it_be(:user) { create(:user) }
let_it_be_with_reload(:project) { create(:project, :import_started, import_type: 'github', import_url: 'https://fake.url') }
describe '.execute' do
context 'when user is an owner' do
context 'when import is in progress' do
it 'update import state to be canceled' do
expect(import_cancel.execute).to eq({ status: :success, project: project })
end
it 'tracks canceled imports' do
metrics_double = instance_double('Gitlab::Import::Metrics')
expect(Gitlab::Import::Metrics)
.to receive(:new)
.with(:github_importer, project)
.and_return(metrics_double)
expect(metrics_double).to receive(:track_import_state)
import_cancel.execute
end
end
context 'when import is finished' do
let(:expected_result) do
{
status: :error,
http_status: :bad_request,
message: 'The import cannot be canceled because it is finished'
}
end
before do
project.import_state.finish!
end
it 'returns error' do
expect(import_cancel.execute).to eq(expected_result)
end
end
end
context 'when user is not allowed to read project' do
it 'returns 404' do
expect(described_class.new(project, user).execute)
.to eq({ status: :error, http_status: :not_found, message: 'Not Found' })
end
end
context 'when user is not allowed to cancel project' do
before do
project.add_developer(user)
end
it 'returns 403' do
expect(described_class.new(project, user).execute)
.to eq({ status: :error, http_status: :forbidden, message: 'Unauthorized access' })
end
end
end
end
|