Merge branch 'master' into registry-791

This commit is contained in:
Artur Beljajev 2018-06-09 08:01:10 +03:00
commit 36b137eb84
129 changed files with 2226 additions and 3275 deletions

View file

@ -20,7 +20,7 @@ class DomainTransferTest < ActiveSupport::TestCase
body = 'Transfer of domain shop.test has been approved.' \
' It was associated with registrant john-001' \
' and contacts jane-001, william-001.'
' and contacts acme-ltd-001, jane-001, william-001.'
id = @domain_transfer.id
class_name = @domain_transfer.class.name

View file

@ -50,9 +50,11 @@ class NameserverTest < ActiveSupport::TestCase
end
def test_hostnames
assert_equal %w[ns1.bestnames.test
assert_equal %w[
ns1.bestnames.test
ns2.bestnames.test
ns1.bestnames.test
ns2.bestnames.test
ns1.bestnames.test], Nameserver.hostnames
end

View file

@ -0,0 +1,134 @@
require 'test_helper'
class BankLinkTest < ActiveSupport::TestCase
# Note: Files stored in: test/fixtures/files/seb_seller_key.pem
# test/fixtures/files/seb_bank_cert.pem
# are autogenerated, they will not work against production or even staging.
def setup
super
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
@invoice.invoice_items << invoice_item
@invoice.invoice_items << invoice_item
travel_to '2018-04-01 00:30 +0300'
create_new_bank_link
create_completed_bank_link
create_cancelled_bank_link
end
def teardown
super
travel_back
end
def create_completed_bank_link
params = {
'VK_SERVICE': '1111',
'VK_VERSION': '008',
'VK_SND_ID': 'testvpos',
'VK_REC_ID': 'seb',
'VK_STAMP': 1,
'VK_T_NO': '1',
'VK_AMOUNT': '12.00',
'VK_CURR': 'EUR',
'VK_REC_ACC': '1234',
'VK_REC_NAME': 'Eesti Internet',
'VK_SND_ACC': '1234',
'VK_SND_NAME': 'John Doe',
'VK_REF': '',
'VK_MSG': 'Order nr 1',
'VK_T_DATETIME': '2018-04-01T00:30:00+0300',
'VK_MAC': 'CZZvcptkxfuOxRR88JmT4N+Lw6Hs4xiQfhBWzVYldAcRTQbcB/lPf9MbJzBE4e1/HuslQgkdCFt5g1xW2lJwrVDBQTtP6DAHfvxU3kkw7dbk0IcwhI4whUl68/QCwlXEQTAVDv1AFnGVxXZ40vbm/aLKafBYgrirB5SUe8+g9FE=',
'VK_ENCODING': 'UTF-8',
'VK_LANG': 'ENG'
}.with_indifferent_access
@completed_bank_link = PaymentOrders::BankLink.new(
'seb', @invoice, { response: params }
)
end
def create_cancelled_bank_link
params = {
'VK_SERVICE': '1911',
'VK_VERSION': '008',
'VK_SND_ID': 'testvpos',
'VK_REC_ID': 'seb',
'VK_STAMP': 1,
'VK_REF': '',
'VK_MSG': 'Order nr 1',
'VK_MAC': 'PElE2mYXXN50q2UBvTuYU1rN0BmOQcbafPummDnWfNdm9qbaGQkGyOn0XaaFGlrdEcldXaHBbZKUS0HegIgjdDfl2NOk+wkLNNH0Iu38KzZaxHoW9ga7vqiyKHC8dcxkHiO9HsOnz77Sy/KpWCq6cz48bi3fcMgo+MUzBMauWoQ=',
'VK_ENCODING': 'UTF-8',
'VK_LANG': 'ENG'
}.with_indifferent_access
@cancelled_bank_link = PaymentOrders::BankLink.new(
'seb', @invoice, { response: params }
)
end
def create_new_bank_link
params = { return_url: 'return.url', response_url: 'response.url' }
@new_bank_link = PaymentOrders::BankLink.new('seb', @invoice, params)
end
def test_response_is_not_valid_when_it_is_missing
refute(false, @new_bank_link.valid_response_from_intermediary?)
end
def test_form_fields
expected_response = {
'VK_SERVICE': '1012',
'VK_VERSION': '008',
'VK_SND_ID': 'testvpos',
'VK_STAMP': 1,
'VK_AMOUNT': '12.00',
'VK_CURR': 'EUR',
'VK_REF': '',
'VK_MSG': 'Order nr. 1',
'VK_RETURN': 'return.url',
'VK_CANCEL': 'return.url',
'VK_DATETIME': '2018-04-01T00:30:00+0300',
'VK_MAC': 'q70UNFV4ih1qYij2+CyrHaApc3OE66igy3ijuR1m9dl0Cg+lIrAUsP47JChAF7PRErwZ78vSuZwrg0Vabhlp3WoC934ik2FiE04BBxUUTndONvguaNR1wvl0FiwfXFljLncX7TOmRraywJljKC5vTnIRNT2+1HXvmv0v576PGao=',
'VK_ENCODING': 'UTF-8',
'VK_LANG': 'ENG'
}.with_indifferent_access
assert_equal(expected_response, @new_bank_link.form_fields)
end
def test_valid_success_response_from_intermediary?
assert(@completed_bank_link.valid_response_from_intermediary?)
end
def test_valid_cancellation_response_from_intermediary?
assert(@cancelled_bank_link.valid_response_from_intermediary?)
end
def test_settled_payment?
assert(@completed_bank_link.settled_payment?)
refute(@cancelled_bank_link.settled_payment?)
end
def test_complete_transaction_calls_methods_on_transaction
mock_transaction = MiniTest::Mock.new
mock_transaction.expect(:sum= , '12.00', ['12.00'])
mock_transaction.expect(:bank_reference= , '1', ['1'])
mock_transaction.expect(:buyer_bank_code= , 'testvpos', ['testvpos'])
mock_transaction.expect(:buyer_iban= , '1234', ['1234'])
mock_transaction.expect(:paid_at= , Date.parse('2018-04-01 00:30:00 +0300'), [Time.parse('2018-04-01T00:30:00+0300')])
mock_transaction.expect(:buyer_name=, 'John Doe', ['John Doe'])
mock_transaction.expect(:save!, true)
mock_transaction.expect(:autobind_invoice, AccountActivity.new)
BankTransaction.stub(:find_by, mock_transaction) do
@completed_bank_link.complete_transaction
end
mock_transaction.verify
end
end

View file

@ -0,0 +1,92 @@
require 'test_helper'
class EveryPayTest < ActiveSupport::TestCase
def setup
super
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
@invoice.invoice_items << invoice_item
@invoice.invoice_items << invoice_item
params = {
response:
{
utf8: '✓',
_method: 'put',
authenticity_token: 'OnA69vbccQtMt3C9wxEWigs5Gpf/7z+NoxRCMkFPlTvaATs8+OgMKF1I4B2f+vuK37zCgpWZaWWtyuslRRSwkw==',
nonce: '392f2d7748bc8cb0d14f263ebb7b8932',
timestamp: '1524136727',
api_username: 'ca8d6336dd750ddb',
transaction_result: 'completed',
payment_reference: 'fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56',
payment_state: 'settled',
amount: '12.00',
order_reference: 'e468a2d59a731ccc546f2165c3b1a6',
account_id: 'EUR3D1',
cc_type: 'master_card',
cc_last_four_digits: '0487',
cc_month: '10',
cc_year: '2018',
cc_holder_name: 'John Doe',
hmac_fields: 'account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result',
hmac: 'efac1c732835668cd86023a7abc140506c692f0d',
invoice_id: '1',
},
}
@every_pay = PaymentOrders::EveryPay.new('every_pay', @invoice, params)
@other_pay = PaymentOrders::EveryPay.new('every_pay', @invoice, {})
travel_to Time.zone.parse('2018-04-01 00:30:00 +0000')
end
def teardown
super
travel_back
end
def test_form_fields
expected_fields = {
api_username: 'api_user',
account_id: 'EUR3D1',
timestamp: '1522542600',
amount: '12.00',
transaction_type: 'charge',
hmac_fields: 'account_id,amount,api_username,callback_url,customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
}
form_fields = @every_pay.form_fields
expected_fields.each do |k, v|
assert_equal(v, form_fields[k])
end
end
def test_valid_response_from_intermediary?
assert(@every_pay.valid_response_from_intermediary?)
refute(@other_pay.valid_response_from_intermediary?)
end
def test_settled_payment?
assert(@every_pay.settled_payment?)
other_pay = PaymentOrders::EveryPay.new(
'every_pay', @invoice, {response: {payment_state: 'CANCELLED'}}
)
refute(other_pay.settled_payment?)
end
def test_complete_transaction_calls_methods_on_transaction
mock_transaction = MiniTest::Mock.new
mock_transaction.expect(:sum= , '12.00', ['12.00'])
mock_transaction.expect(:paid_at= , Date.strptime('1524136727', '%s'), [Date.strptime('1524136727', '%s')])
mock_transaction.expect(:buyer_name=, 'John Doe', ['John Doe'])
mock_transaction.expect(:save!, true)
mock_transaction.expect(:autobind_invoice, AccountActivity.new)
BankTransaction.stub(:find_by, mock_transaction) do
@every_pay.complete_transaction
end
mock_transaction.verify
end
end

View file

@ -0,0 +1,58 @@
require 'test_helper'
class PaymentOrdersTest < ActiveSupport::TestCase
def setup
super
@original_methods = ENV['payment_methods']
@original_seb_URL = ENV['seb_payment_url']
ENV['payment_methods'] = 'seb, swed, credit_card'
ENV['seb_payment_url'] = nil
@not_implemented_payment = PaymentOrders::Base.new(
'not_implemented', Invoice.new
)
end
def teardown
super
ENV['payment_methods'] = @original_methods
ENV['seb_payment_url'] = @original_seb_URL
end
def test_variable_assignment
assert_equal 'not_implemented', @not_implemented_payment.type
assert_nil @not_implemented_payment.response_url
assert_nil @not_implemented_payment.return_url
assert_nil @not_implemented_payment.form_url
end
def test_that_errors_are_raised_on_missing_methods
assert_raise NoMethodError do
@not_implemented_payment.valid_response?
end
assert_raise NoMethodError do
@not_implemented_payment.settled_payment?
end
assert_raise NoMethodError do
@not_implemented_payment.form_fields
end
assert_raise NoMethodError do
@not_implemented_payment.complete_transaction
end
end
def test_that_create_with_type_raises_argument_error
assert_raise ArgumentError do
PaymentOrders.create_with_type("not_implemented", Invoice.new)
end
end
def test_create_with_correct_subclass
payment = PaymentOrders.create_with_type('seb', Invoice.new)
assert_equal PaymentOrders::BankLink, payment.class
end
end

View file

@ -10,7 +10,11 @@ class RegistryTest < ActiveSupport::TestCase
end
def test_vat_rate
original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.25
assert_equal BigDecimal(25), @registry.vat_rate
Setting.registry_vat_prc = original_vat_prc
end
end

View file

@ -0,0 +1,60 @@
require 'test_helper'
class WhoisRecordTest < ActiveSupport::TestCase
def setup
super
@domain = domains(:shop)
@record = WhoisRecord.new(domain: @domain)
@record.populate
end
def test_generated_json_has_expected_values
expected_disclaimer_text = <<-TEXT.squish
Search results may not be used for commercial, advertising, recompilation,
repackaging, redistribution, reuse, obscuring or other similar activities.
TEXT
expected_partial_hash = {
disclaimer: expected_disclaimer_text,
name: 'shop.test',
registrant: 'John',
registrant_kind: 'priv',
email: 'john@inbox.test',
expire: '2010-07-05',
nameservers: ['ns1.bestnames.test', 'ns2.bestnames.test'],
registrar_address: 'Main Street, New York, New York, 12345',
dnssec_keys: [],
}
expected_partial_hash.each do |key, value|
assert_equal(value, @record.generated_json[key])
end
end
def test_generated_body_has_justified_disclaimer
expected_disclaimer = begin
'Search results may not be used for commercial, advertising, recompilation,\n' \
'repackaging, redistribution, reuse, obscuring or other similar activities.'
end
expected_technical_contact = begin
'Technical contact:\n' \
'name: Not Disclosed\n' \
'email: Not Disclosed - Visit www.internet.ee for webbased WHOIS\n' \
'changed: Not Disclosed'
end
regexp_contact = Regexp.new(expected_technical_contact, Regexp::MULTILINE)
regexp_disclaimer = Regexp.new(expected_disclaimer, Regexp::MULTILINE)
assert_match(regexp_disclaimer, @record.body)
assert_match(regexp_contact, @record.body)
end
def test_whois_record_has_no_disclaimer_if_Setting_is_blank
Setting.stubs(:registry_whois_disclaimer, '') do
refute(@record.json['disclaimer'])
refute_match(/Search results may not be used for commercial/, @record.body)
end
end
end