Commit acdf6fdf authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Igor Drozdov

Refactor Integration#can_test? and #test specs

parent 737ec1bb
...@@ -139,61 +139,40 @@ RSpec.describe Integration do ...@@ -139,61 +139,40 @@ RSpec.describe Integration do
end end
end end
describe "Test Button" do describe '#can_test?' do
let(:integration) { build(:service, project: project) } subject { integration.can_test? }
describe '#can_test?' do
subject { integration.can_test? }
context 'when project-level integration' do
let(:project) { create(: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 context 'when integration is project-level' do
Integration.available_integration_types.each do |type| let(:integration) { build(:service, project: project) }
let(:integration) do
described_class.send(:integration_type_to_model, type).new(group_id: group.id)
end
it { is_expected.to be false } it { is_expected.to be true }
end
end
end end
describe '#test' do context 'when integration is not project-level' do
let(:data) { 'test' } let(:integration) { build(:service, project: nil) }
context 'when repository is not empty' do it { is_expected.to be false }
let(:project) { build(:project, :repository) } end
end
it 'test runs execute' do describe '#test' do
expect(integration).to receive(:execute).with(data) let(:integration) { build(:service, project: project) }
let(:data) { 'test' }
integration.test(data) it 'calls #execute' do
end expect(integration).to receive(:execute).with(data)
end
context 'when repository is empty' do integration.test(data)
let(:project) { build(:project) } end
it 'test runs execute' do it 'returns a result' do
expect(integration).to receive(:execute).with(data) result = 'foo'
allow(integration).to receive(:execute).with(data).and_return(result)
integration.test(data) expect(integration.test(data)).to eq(
end success: true,
end result: result
)
end end
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