-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract dialog local logic and add specs around it
- Loading branch information
Showing
4 changed files
with
134 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
class DialogLocalService | ||
def determine_dialog_locals_for_svc_catalog_provision(resource_action, target, finish_submit_endpoint) | ||
api_submit_endpoint = "/api/service_catalogs/#{target.service_template_catalog_id}/service_templates/#{target.id}" | ||
|
||
{ | ||
:resource_action_id => resource_action.id, | ||
:target_id => target.id, | ||
:target_type => target.class.name.underscore, | ||
:dialog_id => resource_action.dialog_id, | ||
:force_old_dialog_use => false, | ||
:api_submit_endpoint => api_submit_endpoint, | ||
:api_action => "order", | ||
:finish_submit_endpoint => finish_submit_endpoint, | ||
:cancel_endpoint => "/catalog/explorer" | ||
} | ||
end | ||
|
||
def determine_dialog_locals_for_custom_button(obj, button_name, resource_action_id) | ||
case obj.class.name.demodulize | ||
when /Vm/ | ||
api_collection_name = "vms" | ||
cancel_endpoint = "/vm_infra/explorer" | ||
force_old_dialog_use = false | ||
when /Service/ | ||
api_collection_name = "services" | ||
cancel_endpoint = "/service/explorer" | ||
force_old_dialog_use = false | ||
when /GenericObject/ | ||
api_collection_name = "generic_objects" | ||
cancel_endpoint = "/generic_object/show_list" | ||
force_old_dialog_use = false | ||
else | ||
force_old_dialog_use = true | ||
end | ||
|
||
{ | ||
:resource_action_id => resource_action_id, | ||
:target_id => obj.id, | ||
:target_type => obj.class.name.demodulize.underscore, | ||
:force_old_dialog_use => force_old_dialog_use, | ||
:api_submit_endpoint => "/api/#{api_collection_name}/#{obj.id}", | ||
:api_action => button_name, | ||
:finish_submit_endpoint => cancel_endpoint, | ||
:cancel_endpoint => cancel_endpoint | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
describe DialogLocalService do | ||
let(:service) { described_class.new } | ||
|
||
describe "#determine_dialog_locals_for_svc_catalog_provision" do | ||
let(:resource_action) { instance_double("ResourceAction", :id => 456, :dialog_id => 654) } | ||
let(:target) { instance_double("ServiceTemplate", :class => ServiceTemplate, :id => 321, :service_template_catalog_id => 123) } | ||
let(:finish_submit_endpoint) { "finishsubmitendpoint" } | ||
|
||
it "returns a hash" do | ||
expect(service.determine_dialog_locals_for_svc_catalog_provision( | ||
resource_action, target, finish_submit_endpoint | ||
)).to eq( | ||
:resource_action_id => 456, | ||
:target_id => 321, | ||
:target_type => 'service_template', | ||
:dialog_id => 654, | ||
:force_old_dialog_use => false, | ||
:api_submit_endpoint => "/api/service_catalogs/123/service_templates/321", | ||
:api_action => "order", | ||
:finish_submit_endpoint => "finishsubmitendpoint", | ||
:cancel_endpoint => "/catalog/explorer" | ||
) | ||
end | ||
end | ||
|
||
describe "#determine_dialog_locals_for_custom_button" do | ||
let(:button_name) { "custom-button-name" } | ||
let(:resource_action_id) { 321 } | ||
|
||
context "when the object is a Vm" do | ||
let(:obj) { double(:class => ManageIQ::Providers::Vmware::InfraManager::Vm, :id => 123) } | ||
|
||
it "returns a hash" do | ||
expect(service.determine_dialog_locals_for_custom_button(obj, button_name, resource_action_id)).to eq( | ||
:resource_action_id => 321, | ||
:target_id => 123, | ||
:target_type => 'vm', | ||
:force_old_dialog_use => false, | ||
:api_submit_endpoint => "/api/vms/123", | ||
:api_action => "custom-button-name", | ||
:finish_submit_endpoint => "/vm_infra/explorer", | ||
:cancel_endpoint => "/vm_infra/explorer" | ||
) | ||
end | ||
end | ||
|
||
context "when the object is a Service" do | ||
let(:obj) { double(:class => ManageIQ::Providers::Vmware::InfraManager::Service, :id => 123) } | ||
|
||
it "returns a hash" do | ||
expect(service.determine_dialog_locals_for_custom_button(obj, button_name, resource_action_id)).to eq( | ||
:resource_action_id => 321, | ||
:target_id => 123, | ||
:target_type => 'service', | ||
:force_old_dialog_use => false, | ||
:api_submit_endpoint => "/api/services/123", | ||
:api_action => "custom-button-name", | ||
:finish_submit_endpoint => "/service/explorer", | ||
:cancel_endpoint => "/service/explorer" | ||
) | ||
end | ||
end | ||
|
||
context "when the object is a GenericObject" do | ||
let(:obj) { double(:class => ManageIQ::Providers::Vmware::InfraManager::GenericObject, :id => 123) } | ||
|
||
it "returns a hash" do | ||
expect(service.determine_dialog_locals_for_custom_button(obj, button_name, resource_action_id)).to eq( | ||
:resource_action_id => 321, | ||
:target_id => 123, | ||
:target_type => 'generic_object', | ||
:force_old_dialog_use => false, | ||
:api_submit_endpoint => "/api/generic_objects/123", | ||
:api_action => "custom-button-name", | ||
:finish_submit_endpoint => "/generic_object/show_list", | ||
:cancel_endpoint => "/generic_object/show_list" | ||
) | ||
end | ||
end | ||
end | ||
end |