Skip to content

Commit

Permalink
spec that tests for VM validity when a plan is being edited
Browse files Browse the repository at this point in the history
  • Loading branch information
AparnaKarve committed Oct 8, 2018
1 parent 36de171 commit c3a331d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/models/transformation_mapping_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

describe '#search_vms_and_validate' do
let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'test_vm', :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) }
let(:vm2) { FactoryGirl.create(:vm_vmware, :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) }
let(:inactive_vm) { FactoryGirl.create(:vm_vmware, :name => 'test_vm_inactive', :ems_cluster => src, :ext_management_system => nil) }
let(:storage) { FactoryGirl.create(:storage) }
let(:lan) { FactoryGirl.create(:lan) }
Expand Down Expand Up @@ -126,6 +127,35 @@
end
end

context 'with VM list and service_template_id' do
it 'returns valid vms when a ServiceTemplate record is edited with CSV containing the same VM already included in the ServiceTemplate record' do
service_template = FactoryGirl.create(:service_template_transformation_plan)

FactoryGirl.create(
:service_resource,
:resource => vm2,
:service_template => service_template,
:status => "Active"
)
result = mapping.search_vms_and_validate(['name' => vm2.name], service_template.id.to_s)
expect(result['valid'].first.reason).to match(/ok/)
end

it 'returns invalid vms when the Service Template record is edited with CSV containing a different VM that belongs to a different ServiceTemplate record' do
service_template = FactoryGirl.create(:service_template_transformation_plan)
service_template2 = FactoryGirl.create(:service_template_transformation_plan)

FactoryGirl.create(
:service_resource,
:resource => vm2,
:service_template => service_template,
:status => "Active"
)
result = mapping.search_vms_and_validate(['name' => vm2.name], service_template2.id.to_s)
expect(result['invalid'].first.reason).to match(/in_other_plan/)
end
end

context 'without VM list' do
it 'returns valid vms' do
result = mapping.search_vms_and_validate
Expand Down

0 comments on commit c3a331d

Please sign in to comment.