Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Aug 5, 2024
1 parent c0915e7 commit cd1762e
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Api::V1::BusinessRegistry::DomainNamesControllerTest < ActionDispatch::Int
assert_includes json_response['variants'], 'testcompanyas'
assert_includes json_response['variants'], 'test-company-as'
assert_includes json_response['variants'], 'test_company_as'
assert_includes json_response['variants'], "testcompany#{Time.current.year}"
end

test "should handle invalid organization name" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def setup
)
ENV['ALLOWED_ORIGINS'] = 'https://example.com,https://test.com'
ENV['auction_api_allowed_ips'] = '127.0.0.1'
ENV['eis_billing_system_base_url'] = 'https://eis_billing_system:3000'

stub_request(:patch, "#{ENV['eis_billing_system_base_url']}/api/v1/invoice/reserved_domain_cancellation_statuses")
.to_return(status: 200, body: "", headers: {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def setup
ENV['ALLOWED_ORIGINS'] = @allowed_origins.join(',')
@valid_ip = '127.0.0.1'
ENV['auction_api_allowed_ips'] = @valid_ip
ENV['eis_billing_system_base_url'] = 'https://eis_billing_system:3000'
ENV['billing_secret'] = 'test_secret'

stub_invoice_number_request
stub_add_deposits_request
Expand Down Expand Up @@ -80,12 +78,12 @@ def setup
private

def stub_invoice_number_request
stub_request(:post, "#{ENV['eis_billing_system_base_url']}/api/v1/invoice_generator/invoice_number_generator")
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
.to_return(status: 200, body: { invoice_number: '12345' }.to_json, headers: { 'Content-Type' => 'application/json' })
end

def stub_add_deposits_request
stub_request(:post, "#{ENV['eis_billing_system_base_url']}/api/v1/invoice_generator/invoice_generator")
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator")
.to_return(status: 201, body: { everypay_link: 'https://pay.example.com' }.to_json, headers: { 'Content-Type' => 'application/json' })
end
end
1 change: 0 additions & 1 deletion test/models/reserved_domain_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class ReservedDomainStatusTest < ActiveSupport::TestCase
def setup
ENV['eis_billing_system_base_url'] ||= 'https://eis_billing_system:3000'
@reserved_domain_status = ReservedDomainStatus.new(name: 'example.test')
stub_eis_billing_requests
end
Expand Down
10 changes: 0 additions & 10 deletions test/services/eis_billing_system/add_deposit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@

class AddDepositsTest < ActiveSupport::TestCase
setup do
@original_base_url = ENV['eis_billing_system_base_url']
@original_billing_secret = ENV['billing_secret']
ENV['eis_billing_system_base_url'] = 'http://eis_billing_system:3000'
ENV['billing_secret'] = 'test_secret'

@invoice = Struct.new(:total, :number, :buyer_name, :buyer_email, :description, :initiator, :reference_no, :reserved_domain_name, :token).new(
100.50, '12345', 'John Doe', '[email protected]', 'Test invoice', 'test_initiator', 'REF001', 'example.com', 'test_token'
)
end

teardown do
ENV['eis_billing_system_base_url'] = @original_base_url
ENV['billing_secret'] = @original_billing_secret
end

test "parse_invoice returns correct data" do
add_deposits = EisBilling::AddDeposits.new(@invoice)
parsed_data = add_deposits.send(:parse_invoice)
Expand Down
21 changes: 2 additions & 19 deletions test/services/eis_billing_system/get_invoice_number_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,18 @@
require 'webmock/minitest'

class GetInvoiceNumberTest < ActionDispatch::IntegrationTest
setup do
@original_base_url = ENV['eis_billing_system_base_url']
@original_billing_secret = ENV['billing_secret']
ENV['eis_billing_system_base_url'] = 'http://eis_billing_system:3000'
ENV['billing_secret'] = 'test_secret'
end

teardown do
ENV['eis_billing_system_base_url'] = @original_base_url
ENV['billing_secret'] = @original_billing_secret
end

test "call returns expected result" do
expected_response = '{"invoice_number": "12345"}'

stub_request(:post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
.to_return(status: 200, body: expected_response, headers: { 'Content-Type' => 'application/json' })

result = EisBilling::GetInvoiceNumber.call

assert_equal expected_response, result.body
assert_equal '200', result.code

assert_requested :post, "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator", {
assert_requested :post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator", {
headers: {
'Content-Type' => 'application/json',
'Authorization' => /^Bearer .+$/
Expand All @@ -34,11 +22,6 @@ class GetInvoiceNumberTest < ActionDispatch::IntegrationTest
}
end

test "invoice_number_generator_url returns correct URL" do
expected_url = "http://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator"
assert_equal expected_url, EisBilling::GetInvoiceNumber.send(:invoice_number_generator_url)
end

test "headers from base class are correct" do
EisBilling::Base.stub :generate_token, 'test_token' do
expected_headers = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ def setup
@domain_name = 'example.com'
@token = 'test_token'
@service = EisBilling::GetReservedDomainInvoiceStatus.new(domain_name: @domain_name, token: @token)

@original_base_url = ENV['eis_billing_system_base_url']
ENV['eis_billing_system_base_url'] = 'https://test-billing.example.com'
end

def teardown
ENV['eis_billing_system_base_url'] = @original_base_url
end

test 'initialization sets domain_name and token' do
Expand Down

0 comments on commit cd1762e

Please sign in to comment.