Merge branch 'master' into refactor-devise-integration

This commit is contained in:
Artur Beljajev 2018-08-08 14:13:53 +03:00
commit bf3b54367b
43 changed files with 50 additions and 43 deletions

View file

@ -0,0 +1,28 @@
require 'test_helper'
class BalanceTopUpTest < ApplicationSystemTestCase
setup do
sign_in users(:api_bestnames)
end
def test_creates_new_invoice
original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.1
visit registrar_invoices_url
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '25.5'
assert_difference 'Invoice.count' do
click_link_or_button 'Add'
end
invoice = Invoice.last
assert_equal BigDecimal(10), invoice.vat_rate
assert_equal BigDecimal('28.05'), invoice.total
assert_text 'Please pay the following invoice'
Setting.registry_vat_prc = original_vat_prc
end
end

View file

@ -0,0 +1,42 @@
require 'test_helper'
class RegistrarAreaBulkTransferTest < ApplicationSystemTestCase
setup do
sign_in users(:api_goodnames)
end
def test_transfer_multiple_domains_in_bulk
request_body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
headers = { 'Content-type' => 'application/json' }
request_stub = stub_request(:post, /domain_transfers/).with(body: request_body,
headers: headers,
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
type: 'domain_transfer'
}] }.to_json, status: 200)
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Bulk transfer'
attach_file 'Batch file', Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_transfer.csv').to_s
click_button 'Transfer'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text '1 domains have been successfully transferred'
end
def test_fail_gracefully
body = { errors: [{ title: 'epic fail' }] }.to_json
headers = { 'Content-type' => 'application/json' }
stub_request(:post, /domain_transfers/).to_return(status: 400, body: body, headers: headers)
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Bulk transfer'
attach_file 'Batch file', Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_transfer.csv').to_s
click_button 'Transfer'
assert_text 'epic fail'
end
end

View file

@ -0,0 +1,59 @@
require 'test_helper'
class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
setup do
sign_in users(:api_goodnames)
end
def test_replaces_current_registrar_nameservers
request_body = { data: { type: 'nameserver',
id: 'ns1.bestnames.test',
attributes: { hostname: 'new-ns.bestnames.test',
ipv4: %w[192.0.2.55 192.0.2.56],
ipv6: %w[2001:db8::55 2001:db8::56] } } }
request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body,
headers: { 'Content-type' => 'application/json' },
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
type: 'nameserver',
id: 'new-ns.bestnames.test'}],
affected_domains: ["airport.test", "shop.test"]}.to_json, status: 200)
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Nameserver'
fill_in 'Old hostname', with: 'ns1.bestnames.test'
fill_in 'New hostname', with: 'new-ns.bestnames.test'
fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56"
fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56"
click_on 'Replace nameserver'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Nameserver have been successfully replaced'
assert_text 'Affected domains: airport.test, shop.test'
end
def test_fails_gracefully
stub_request(:put, /registrar\/nameservers/).to_return(status: 400,
body: { errors: [{ title: 'epic fail' }] }.to_json,
headers: { 'Content-type' => 'application/json' })
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Nameserver'
fill_in 'Old hostname', with: 'old hostname'
fill_in 'New hostname', with: 'new hostname'
fill_in 'ipv4', with: 'ipv4'
fill_in 'ipv6', with: 'ipv6'
click_on 'Replace nameserver'
assert_text 'epic fail'
assert_field 'Old hostname', with: 'old hostname'
assert_field 'New hostname', with: 'new hostname'
assert_field 'ipv4', with: 'ipv4'
assert_field 'ipv6', with: 'ipv6'
end
end

View file

@ -0,0 +1,47 @@
require 'test_helper'
class RegistrarAreaTechContactBulkChangeTest < ApplicationSystemTestCase
setup do
sign_in users(:api_bestnames)
end
def test_replace_domain_contacts_of_current_registrar
request_stub = stub_request(:patch, /domains\/contacts/)
.with(body: { current_contact_id: 'william-001', new_contact_id: 'john-001' },
basic_auth: ['test_bestnames', 'testtest'])
.to_return(body: { affected_domains: %w[foo.test bar.test],
skipped_domains: %w[baz.test qux.test] }.to_json,
status: 200)
visit registrar_domains_url
click_link 'Bulk change'
fill_in 'Current contact ID', with: 'william-001'
fill_in 'New contact ID', with: 'john-001'
click_on 'Replace technical contacts'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Technical contacts have been successfully replaced'
assert_text 'Affected domains: foo.test, bar.test'
assert_text 'Skipped domains: baz.test, qux.test'
end
def test_fails_gracefully
stub_request(:patch, /domains\/contacts/)
.to_return(status: 400,
body: { error: { message: 'epic fail' } }.to_json,
headers: { 'Content-type' => 'application/json' })
visit registrar_domains_url
click_link 'Bulk change'
fill_in 'Current contact ID', with: 'william-001'
fill_in 'New contact ID', with: 'john-001'
click_on 'Replace technical contacts'
assert_text 'epic fail'
assert_field 'Current contact ID', with: 'william-001'
assert_field 'New contact ID', with: 'john-001'
end
end

View file

@ -0,0 +1,21 @@
require 'test_helper'
class RegistrarDomainsTest < ApplicationSystemTestCase
def test_downloads_domain_list_as_csv
sign_in users(:api_bestnames)
travel_to Time.zone.parse('2010-07-05 10:30')
expected_csv = <<-CSV.strip_heredoc
Domain,Transfer code,Registrant name,Registrant code,Date of expiry
library.test,45118f5,Acme Ltd,acme-ltd-001,2010-07-05
shop.test,65078d5,John,john-001,2010-07-05
invalid.test,1438d6,any,invalid,2010-07-05
airport.test,55438j5,John,john-001,2010-07-05
CSV
visit registrar_domains_url
click_button 'Download as CSV'
assert_equal 'attachment; filename="Domains_2010-07-05_10.30.csv"', response_headers['Content-Disposition']
assert_equal expected_csv, page.body
end
end

View file

@ -0,0 +1,28 @@
require 'test_helper'
class ListInvoicesTest < ApplicationSystemTestCase
def setup
super
@user = users(:api_bestnames)
@registrar_invoices = @user.registrar.invoices
sign_in @user
end
def test_show_balance
visit registrar_invoices_path
assert_text "Your current account balance is 100,00 EUR"
end
def test_show_multiple_invoices
@invoices = invoices
@registrar_invoices = []
@invoices.each do |invoice|
@registrar_invoices << invoice
end
visit registrar_invoices_path
assert_text "Unpaid", count: 5
assert_text "Invoice no.", count: 7
end
end

View file

@ -0,0 +1,48 @@
require 'test_helper'
class NewInvoicePaymentTest < ApplicationSystemTestCase
def setup
super
@original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.2
@user = users(:api_bestnames)
sign_in @user
end
def teardown
super
Setting.registry_vat_prc = @original_vat_prc
end
def create_invoice_and_visit_its_page
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
fill_in 'Description', with: 'My first invoice'
click_link_or_button 'Add'
end
def test_create_new_SEB_payment
create_invoice_and_visit_its_page
click_link_or_button 'Seb'
form = page.find('form')
assert_equal('https://www.seb.ee/cgi-bin/dv.sh/ipank.r', form['action'])
assert_equal('post', form['method'])
assert_equal('240.00', form.find_by_id('VK_AMOUNT', visible: false).value)
end
def test_create_new_Every_Pay_payment
create_invoice_and_visit_its_page
click_link_or_button 'Every pay'
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
form = page.find('form')
assert_equal('https://igw-demo.every-pay.com/transactions/', form['action'])
assert_equal('post', form['method'])
assert_equal(expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value)
assert_equal('240.00', form.find_by_id('amount', visible: false).value)
end
end

View file

@ -0,0 +1,48 @@
require 'test_helper'
class NewInvoiceTest < ApplicationSystemTestCase
def setup
super
@user = users(:api_bestnames)
sign_in @user
end
def test_show_balance
visit registrar_invoices_path
assert_text "Your current account balance is 100,00 EUR"
end
def test_create_new_invoice_with_positive_amount
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do
click_link_or_button 'Add'
end
assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050'
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end
# This test case should fail once issue #651 gets fixed
def test_create_new_invoice_with_amount_0_goes_through
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '0.00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do
click_link_or_button 'Add'
end
assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050'
assert_text 'Subtotal 0,00 €'
assert_text 'Pay invoice'
end
end

View file

@ -0,0 +1,49 @@
require 'test_helper'
class PaymentCallbackTest < ApplicationSystemTestCase
def setup
super
@user = users(:api_bestnames)
sign_in @user
end
def create_invoice_with_items
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
@invoice.invoice_items << invoice_item
@invoice.invoice_items << invoice_item
@user.registrar.invoices << @invoice
end
def every_pay_request_params
{
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: "12900000",
payment_method: "every_pay"
}
end
def test_every_pay_callback_returns_status_200
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: @invoice.id)
post "/registrar/pay/callback/every_pay", request_params
assert_equal(200, response.status)
end
end

View file

@ -0,0 +1,100 @@
require 'test_helper'
class PaymentReturnTest < ApplicationSystemTestCase
def setup
super
@user = users(:api_bestnames)
sign_in @user
end
def create_invoice_with_items
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
@invoice.invoice_items << invoice_item
@invoice.invoice_items << invoice_item
@user.registrar.invoices << @invoice
end
def every_pay_request_params
{
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: "12900000",
payment_method: "every_pay"
}
end
def bank_link_request_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",
payment_method: "seb"
}
end
def test_every_pay_return_creates_activity_redirects_to_invoice_path
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: @invoice.id)
post "/registrar/pay/return/every_pay", request_params
assert_equal(302, response.status)
assert_redirected_to(registrar_invoice_path(@invoice))
end
def test_Every_Pay_return_raises_RecordNotFound
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: "178907")
assert_raises(ActiveRecord::RecordNotFound) do
post "/registrar/pay/return/every_pay", request_params
end
end
def test_bank_link_return_redirects_to_invoice_paths
create_invoice_with_items
request_params = bank_link_request_params.merge(invoice_id: @invoice.id)
post "/registrar/pay/return/seb", request_params
assert_equal(302, response.status)
assert_redirected_to(registrar_invoice_path(@invoice))
end
def test_bank_link_return
create_invoice_with_items
request_params = bank_link_request_params.merge(invoice_id: "178907")
assert_raises(ActiveRecord::RecordNotFound) do
post "/registrar/pay/return/seb", request_params
end
end
end

View file

@ -0,0 +1,35 @@
require 'test_helper'
class RegistrarAreaSignInTest < JavaScriptApplicationSystemTestCase
def setup
super
WebMock.allow_net_connect!
@user = users(:api_bestnames)
@user.identity_code = '1234'
@user.save
end
def test_mobile_id_sign_in_page
mock_client = Minitest::Mock.new
mock_client.expect(:authenticate,
OpenStruct.new(user_id_code: '1234', challenge_id: '1234'),
[{ phone: "+3721234",
message_to_display: "Authenticating",
service_name: "Testimine" }])
mock_client.expect(:session_code, 1234)
Digidoc::Client.stub(:new, mock_client) do
visit new_registrar_user_session_path
click_on 'login-with-mobile-id-btn'
fill_in 'user[phone]', with: '1234'
click_button 'Login'
flash_message = page.find('div.bg-success')
assert_equal('Confirmation sms was sent to your phone. Verification code is 1234.',
flash_message.text)
end
end
end