blob: 77b8771ee65d4d7096b478c4d9d3f95b8ebc6f6c (
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
50
51
52
53
54
55
56
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Import::Github::CancelProjectImportService 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
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
|