Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Oct 19, 2023
1 parent faa4dea commit ca9b37c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/models/dns/domain_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def reserved?
end

def bsa_protected?
BsaProtectedDomain.where(name: name).any?
BsaProtectedDomain.where(domain_name: name).any?
end

def disputed?
Expand Down
4 changes: 2 additions & 2 deletions app/services/bsa/application_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion app/services/bsa/block_order_list_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions test/services/bsa/block_order_list_service_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'

RESPONSE = {
RESPONSE_BLOCK_ORDER_LIST_SERVICE = {
"list": [
{
"blockSubOrderId": 690_680_666_563_633,
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/services/bsa/block_order_view_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'test_helper'

RESPONSE = {
RESPONSE_BLOCK_VIEW_SERVICE = {
"list": %w[
label1
label2
Expand Down Expand Up @@ -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' }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'test_helper'

RESPONSE = 'some,csv,data'
RESPONSE_DOWNLOAD = 'some,csv,data'

class Bsa::BlockOrderViewServiceTest < ActiveSupport::TestCase
setup do
Expand All @@ -19,15 +19,15 @@ 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"' }
)

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
Expand Down

0 comments on commit ca9b37c

Please sign in to comment.