diff --git a/config/routes.rb b/config/routes.rb index 44feb60d4..3e696e521 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,8 +58,19 @@ get '/api/health/status', to: 'api/health#status' + # :nocov: mount StrictAuthentication::Engine, at: '/api/auth' if defined?(StrictAuthentication::Engine) mount RegistrationSharing::Engine, at: '/api/regsharing' if defined?(RegistrationSharing::Engine) mount InstanceVerification::Engine, at: '/api/instance' if defined?(InstanceVerification::Engine) - mount SccSumaApi::Engine, at: '/api/scc' if defined?(SccSumaApi::Engine) + + if defined?(SccSumaApi::Engine) + mount SccSumaApi::Engine, at: '/api/scc' + + get '/connect/organizations/products/unscoped', to: redirect(path: '/api/scc/unscoped-products') + get '/connect/organizations/repositories', to: redirect(path: '/api/scc/repos') + get '/connect/organizations/subscriptions', to: redirect(path: '/api/scc/subs') + get '/connect/organizations/orders', to: redirect(path: '/api/scc/orders') + get '/suma/product_tree.json', to: redirect(path: '/api/scc/product-tree') + end + # :nocov: end diff --git a/engines/scc_suma_api/app/controllers/scc_suma_api/scc_suma_api_controller.rb b/engines/scc_suma_api/app/controllers/scc_suma_api/scc_suma_api_controller.rb index cc636195e..5d1d844e5 100644 --- a/engines/scc_suma_api/app/controllers/scc_suma_api/scc_suma_api_controller.rb +++ b/engines/scc_suma_api/app/controllers/scc_suma_api/scc_suma_api_controller.rb @@ -12,15 +12,15 @@ def unscoped_products update_cache unless cache_is_valid? unscoped_products_json = File.read(@unscoped_products_path) - render status: :ok, json: { result: JSON.parse(unscoped_products_json) } + render status: :ok, json: JSON.parse(unscoped_products_json) end def list - render status: :ok, json: { result: [] } + render status: :ok, json: [] end def product_tree - render status: :ok, json: { result: product_tree_json } + render status: :ok, json: product_tree_json end protected diff --git a/engines/scc_suma_api/spec/requests/scc_suma_api/scc_suma_api_controller_spec.rb b/engines/scc_suma_api/spec/requests/scc_suma_api/scc_suma_api_controller_spec.rb index 203dc9cf5..4eb40efa8 100644 --- a/engines/scc_suma_api/spec/requests/scc_suma_api/scc_suma_api_controller_spec.rb +++ b/engines/scc_suma_api/spec/requests/scc_suma_api/scc_suma_api_controller_spec.rb @@ -37,14 +37,27 @@ module SccSumaApi file_fixture('products/dummy_products.json'), Rails.root.join('tmp/unscoped_products.json') ) - - get '/api/scc/unscoped-products', params: payload end after { File.delete(unscoped_file) if File.exist?(unscoped_file) } - its(:code) { is_expected.to eq '200' } - its(:body) { is_expected.to eq "{\"result\":#{products.to_json}}" } + context 'redirect from SCC endpoint' do + before do + get '/connect/organizations/products/unscoped', params: payload + end + + its(:code) { is_expected.to eq '301' } + its(:body) { is_expected.to include 'http://www.example.com/api/scc/unscoped-products' } + end + + context 'endpoints return unscoped products' do + before do + get '/api/scc/unscoped-products', params: payload + end + + its(:code) { is_expected.to eq '200' } + its(:body) { is_expected.to eq products.to_json.to_s } + end end context 'cache is not valid' do @@ -62,15 +75,22 @@ module SccSumaApi end its(:code) { is_expected.to eq '200' } - its(:body) { is_expected.to eq "{\"result\":#{products.to_json}}" } + its(:body) { is_expected.to eq products.to_json.to_s } end end + context 'get repos redirect' do + before { get '/connect/organizations/repositories' } + + its(:code) { is_expected.to eq '301' } + its(:body) { is_expected.to include 'http://www.example.com/api/scc/repos' } + end + context 'get repos' do before { get '/api/scc/repos' } its(:code) { is_expected.to eq '200' } - its(:body) { is_expected.to eq '{"result":[]}' } + its(:body) { is_expected.to eq '[]' } end context 'get product tree' do @@ -82,13 +102,28 @@ module SccSumaApi allow_any_instance_of(File).to receive(:read).and_return products.to_json FileUtils.cp(file_fixture('products/dummy_products.json'), product_tree_file) - get '/api/scc/product-tree' + get '/suma/product_tree.json' end after { File.delete(product_tree_file) if File.exist?(product_tree_file) } - its(:code) { is_expected.to eq '200' } - its(:body) { is_expected.to eq "{\"result\":#{products.to_json}}" } + context 'SCC endpoint redirect' do + before do + get '/suma/product_tree.json' + end + + its(:code) { is_expected.to eq '301' } + its(:body) { is_expected.to include 'http://www.example.com/api/scc/product-tree' } + end + + context 'endpoint returns product tree json output' do + before do + get '/api/scc/product-tree' + end + + its(:code) { is_expected.to eq '200' } + its(:body) { is_expected.to eq products.to_json.to_s } + end end end end