diff --git a/app/controllers/api/services_controller.rb b/app/controllers/api/services_controller.rb index 04ba41221fc..1ae29c0dcf1 100644 --- a/app/controllers/api/services_controller.rb +++ b/app/controllers/api/services_controller.rb @@ -109,19 +109,19 @@ def validate_service(service) end def fetch_ext_management_system(data) - orchestration_manager_id = parse_id(data, :orchestration_manager) + orchestration_manager_id = parse_id(data, :providers) raise BadRequestError, 'Missing ExtManagementSystem identifier id' if orchestration_manager_id.nil? resource_search(orchestration_manager_id, :ext_management_systems, ExtManagementSystem) end def fetch_service(data) - service_id = parse_id(data, :service) + service_id = parse_id(data, :services) raise BadRequestError, 'Missing Service identifier id' if service_id.nil? resource_search(service_id, :services, Service) end def fetch_orchestration_template(data) - orchestration_template_id = parse_id(data, :orchestration_template) + orchestration_template_id = parse_id(data, :orchestration_templates) raise BadRequestError, 'Missing OrchestrationTemplate identifier id' if orchestration_template_id.nil? resource_search(orchestration_template_id, :orchestration_templates, OrchestrationTemplate) end diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index c2feda07fbc..875f86cadf3 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -26,6 +26,8 @@ let(:svc) { FactoryGirl.create(:service, :name => "svc", :description => "svc description") } let(:svc1) { FactoryGirl.create(:service, :name => "svc1", :description => "svc1 description") } let(:svc2) { FactoryGirl.create(:service, :name => "svc2", :description => "svc2 description") } + let(:orchestration_template) { FactoryGirl.create(:orchestration_template) } + let(:ems) { FactoryGirl.create(:ext_management_system) } describe "Services create" do it "rejects requests without appropriate role" do @@ -61,6 +63,46 @@ [{"name" => "svc_new_1"}, {"name" => "svc_new_2"}]) end + + it 'supports creation of a single resource with href references' do + api_basic_authorize collection_action_identifier(:services, :create) + + request = { + 'action' => 'create', + 'resource' => { + 'type' => 'ServiceOrchestration', + 'name' => 'svc_new', + 'parent_service' => { 'href' => services_url(svc1.id)}, + 'orchestration_template' => { 'href' => orchestration_templates_url(orchestration_template.id) }, + 'orchestration_manager' => { 'href' => providers_url(ems.id) } + } + } + expect do + run_post(services_url, request) + end.to change(Service, :count).by(1) + expect(response).to have_http_status(:ok) + expect_results_to_match_hash("results", [{"name" => "svc_new"}]) + end + + it 'supports creation of a single resource with id references' do + api_basic_authorize collection_action_identifier(:services, :create) + + request = { + 'action' => 'create', + 'resource' => { + 'type' => 'ServiceOrchestration', + 'name' => 'svc_new', + 'parent_service' => { 'id' => svc1.id}, + 'orchestration_template' => { 'id' => orchestration_template.id }, + 'orchestration_manager' => { 'id' => ems.id } + } + } + expect do + run_post(services_url, request) + end.to change(Service, :count).by(1) + expect(response).to have_http_status(:ok) + expect_results_to_match_hash("results", [{"name" => "svc_new"}]) + end end describe "Services edit" do