Commit 6c66cadd authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '334857-refactor-integrations-can_test-specs' into 'master'

Refactor Integration#can_test? and #test specs

See merge request gitlab-org/gitlab!65113
parents 0aecfcaa acdf6fdf
......@@ -139,61 +139,40 @@ RSpec.describe Integration do
end
end
describe "Test Button" do
let(:integration) { build(:service, project: project) }
describe '#can_test?' do
subject { integration.can_test? }
context 'when project-level integration' do
let(:project) { create(:project) }
context 'when integration is project-level' do
let(:integration) { build(:service, project: project) }
it { is_expected.to be true }
end
context 'when instance-level integration' do
Integration.available_integration_types.each do |type|
let(:integration) do
described_class.send(:integration_type_to_model, type).new(instance: true)
end
it { is_expected.to be false }
end
end
context 'when group-level integration' do
Integration.available_integration_types.each do |type|
let(:integration) do
described_class.send(:integration_type_to_model, type).new(group_id: group.id)
end
context 'when integration is not project-level' do
let(:integration) { build(:service, project: nil) }
it { is_expected.to be false }
end
end
end
describe '#test' do
let(:integration) { build(:service, project: project) }
let(:data) { 'test' }
context 'when repository is not empty' do
let(:project) { build(:project, :repository) }
it 'test runs execute' do
it 'calls #execute' do
expect(integration).to receive(:execute).with(data)
integration.test(data)
end
end
context 'when repository is empty' do
let(:project) { build(:project) }
it 'returns a result' do
result = 'foo'
allow(integration).to receive(:execute).with(data).and_return(result)
it 'test runs execute' do
expect(integration).to receive(:execute).with(data)
integration.test(data)
end
end
expect(integration.test(data)).to eq(
success: true,
result: result
)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment