diff --git a/app/services/bsa/application_service.rb b/app/services/bsa/application_service.rb index 284c0f7fc3..c315ccc159 100644 --- a/app/services/bsa/application_service.rb +++ b/app/services/bsa/application_service.rb @@ -32,9 +32,9 @@ def struct_response(response) parsed_data = parse_response(response) result = [OK, ACCEPTED].include? response.code - Struct.new(:result?, :error).new(result, OpenStruct.new(parsed_data)) unless result + return Struct.new(:result?, :error).new(result, OpenStruct.new(parsed_data)) unless result - if parsed_data.is_a?(Array) + if parsed_data.is_a?(Array) Struct.new(:result?, :body).new(result, parsed_data.map { |data| OpenStruct.new(data) }) else Struct.new(:result?, :body).new(result, OpenStruct.new(parsed_data)) diff --git a/app/services/bsa/block_order_list_service.rb b/app/services/bsa/block_order_list_service.rb index f85c4c52c3..d1055d0788 100644 --- a/app/services/bsa/block_order_list_service.rb +++ b/app/services/bsa/block_order_list_service.rb @@ -19,7 +19,6 @@ def initialize(sort_by:, order:, offset:, limit:, q:) def call http = connect(url: base_url) - response = http.get(endpoint, headers.merge(token_format(token))) struct_response(response) diff --git a/test/services/bsa/block_order_list_service_test.rb b/test/services/bsa/block_order_list_service_test.rb index 99d4a4f1e7..91f39720c9 100644 --- a/test/services/bsa/block_order_list_service_test.rb +++ b/test/services/bsa/block_order_list_service_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -RESPONSE = { +RESPONSE_BLOCK_ORDER_LIST_SERVICE = { "list": [ { "blockSubOrderId": 690_680_666_563_633, @@ -71,13 +71,14 @@ def test_for_succesfull_block_order_list stub_request(:get, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder') .to_return( status: 200, - body: RESPONSE.to_json, + body: RESPONSE_BLOCK_ORDER_LIST_SERVICE.to_json, headers: { 'Content-Type' => 'application/json' } ) r = Bsa::BlockOrderListService.call assert r.result? + assert_equal r.body.list.count, 2 end @@ -103,7 +104,7 @@ def test_parse_query_parameters result = instance_serive.send(:query_string) - assert_equal result, 'sortBy=createdAt&order=desc&offset=0&limit=100&tld=test' + assert_equal result, 'sortBy=createdBy&order=desc&offset=0&limit=100&q=tld%3Dtest' end private diff --git a/test/services/bsa/block_order_view_service_test.rb b/test/services/bsa/block_order_view_service_test.rb index e18b303552..4a6496d7e1 100644 --- a/test/services/bsa/block_order_view_service_test.rb +++ b/test/services/bsa/block_order_view_service_test.rb @@ -2,7 +2,7 @@ require 'test_helper' -RESPONSE = { +RESPONSE_BLOCK_VIEW_SERVICE = { "list": %w[ label1 label2 @@ -32,7 +32,7 @@ def test_for_succesfull_block_order_list stub_request(:get, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder/labels?blocksuborderid=1') .to_return( status: 200, - body: RESPONSE.to_json, + body: RESPONSE_BLOCK_VIEW_SERVICE.to_json, headers: { 'Content-Type' => 'application/json' } ) diff --git a/test/services/bsa/download_non_blocked_name_list_service_test.rb b/test/services/bsa/download_non_blocked_name_list_service_test.rb index 2a5d46dfc3..ca0945a48a 100644 --- a/test/services/bsa/download_non_blocked_name_list_service_test.rb +++ b/test/services/bsa/download_non_blocked_name_list_service_test.rb @@ -2,7 +2,7 @@ require 'test_helper' -RESPONSE = 'some,csv,data' +RESPONSE_DOWNLOAD = 'some,csv,data' class Bsa::BlockOrderViewServiceTest < ActiveSupport::TestCase setup do @@ -19,7 +19,7 @@ def test_for_succesfull_downloaded_non_blocked_name stub_request(:get, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder/1/nonblockednames') .to_return( status: 200, - body: RESPONSE.to_json, + body: RESPONSE_DOWNLOAD.to_json, headers: { 'Content-Type' => 'text/csv', 'Content-Disposition' => 'attachment; filename="mock-csv.csv"' } ) @@ -27,7 +27,7 @@ def test_for_succesfull_downloaded_non_blocked_name result = Bsa::DownloadNonBlockedNameListService.call(suborder_id: 1, filename: @filename) assert File.exist?("#{@filename}.csv") - assert_equal RESPONSE, File.read("#{@filename}.csv").gsub('"', '') + assert_equal RESPONSE_DOWNLOAD, File.read("#{@filename}.csv").gsub('"', '') assert result.result? assert_equal "Data was added to #{@filename}.csv file", result.body.message end