blob: 5fff4e0af53e6114428018b872cbdc26fe59b9e2 (
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
57
58
59
60
61
62
63
64
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe StaticSiteEditor::ConfigService do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
# params
let(:ref) { double(:ref) }
let(:path) { double(:path) }
let(:return_url) { double(:return_url) }
# stub data
let(:generated_data) { { generated: true } }
let(:file_data) { { file: true } }
describe '#execute' do
subject(:execute) do
described_class.new(
container: project,
current_user: user,
params: {
ref: ref,
path: path,
return_url: return_url
}
).execute
end
context 'when insufficient permission' do
it 'returns an error' do
expect(execute).to be_error
expect(execute.message).to eq('Insufficient permissions to read configuration')
end
end
context 'for developer' do
before do
project.add_developer(user)
allow_next_instance_of(Gitlab::StaticSiteEditor::Config::GeneratedConfig) do |config|
allow(config).to receive(:data) { generated_data }
end
allow_next_instance_of(Gitlab::StaticSiteEditor::Config::FileConfig) do |config|
allow(config).to receive(:data) { file_data }
end
end
it 'returns merged generated data and config file data' do
expect(execute).to be_success
expect(execute.payload).to eq(generated: true, file: true)
end
it 'returns an error if any keys would be overwritten by the merge' do
generated_data[:duplicate_key] = true
file_data[:duplicate_key] = true
expect(execute).to be_error
expect(execute.message).to match(/duplicate key.*duplicate_key.*found/i)
end
end
end
end
|