mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 12:47:29 +02:00
Tests for DirectoInvoiceForwardJob
This commit is contained in:
parent
26adaa9743
commit
ee332d8a7f
5 changed files with 144 additions and 11 deletions
|
@ -9,7 +9,7 @@ GIT
|
|||
|
||||
GIT
|
||||
remote: https://github.com/internetee/directo.git
|
||||
revision: 41f4b49da2d4155a76ab57f1cb07bb1d0ba9cdef
|
||||
revision: c688c46134ce04f5a75b7a0563abc18cd9af030a
|
||||
branch: directo-api
|
||||
specs:
|
||||
directo (0.1.0)
|
||||
|
|
|
@ -6,6 +6,8 @@ module BookKeeping
|
|||
|
||||
def monthly_summary(month:)
|
||||
activities = monthly_activites(month)
|
||||
return unless activities.any?
|
||||
|
||||
inv = {
|
||||
'number': 1,
|
||||
'customer_code': accounting_customer_code,
|
||||
|
@ -15,6 +17,8 @@ module BookKeeping
|
|||
}.as_json
|
||||
|
||||
lines = []
|
||||
|
||||
lines << { 'description': title_for_summary(month) }
|
||||
activities.each do |activity|
|
||||
fetch_invoice_lines(activity, lines)
|
||||
end
|
||||
|
@ -25,11 +29,23 @@ module BookKeeping
|
|||
inv
|
||||
end
|
||||
|
||||
def title_for_summary(date)
|
||||
if language == 'en'
|
||||
I18n.with_locale('en') do
|
||||
"Domains registrations - #{I18n.l(date, format: '%B %Y')}"
|
||||
end
|
||||
else
|
||||
I18n.with_locale('et') do
|
||||
"Domeenide registreerimine - #{I18n.l(date, format: '%B %Y')}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_invoice_lines(activity, lines)
|
||||
price = load_price(activity)
|
||||
if price.duration.include? 'year'
|
||||
price.duration.to_i.times do |duration|
|
||||
lines << new_montly_invoice_line(activity: activity, duration: duration + 1).as_json
|
||||
lines << new_monthly_invoice_line(activity: activity, duration: duration + 1).as_json
|
||||
end
|
||||
else
|
||||
lines << new_monthly_invoice_line(activity: activity).as_json
|
||||
|
@ -42,27 +58,28 @@ module BookKeeping
|
|||
.where(activity_type: [AccountActivity::CREATE, AccountActivity::RENEW])
|
||||
end
|
||||
|
||||
def new_montly_invoice_line(activity:, duration: nil)
|
||||
def new_monthly_invoice_line(activity:, duration: nil)
|
||||
price = load_price(activity)
|
||||
yearly = price.duration.include?('year')
|
||||
line = {
|
||||
'product_id': DOMAIN_TO_PRODUCT[price.zone_name.to_sym],
|
||||
'quantity': 1,
|
||||
'price': yearly ? (price.price.amount / price.duration.to_i) : price.amount,
|
||||
'price': yearly ? (price.price.amount / price.duration.to_i) : price.price.amount,
|
||||
'unit': language == 'en' ? 'pc' : 'tk'
|
||||
}
|
||||
|
||||
line['description'] = description_in_language(price: price, yearly: yearly)
|
||||
add_product_timeframe(line: line, activity: activity, duration: duration) if duration > 1
|
||||
if yearly && duration
|
||||
add_product_timeframe(line: line, activity: activity, duration: duration) if duration > 1
|
||||
end
|
||||
|
||||
line
|
||||
end
|
||||
|
||||
def add_product_timeframe(line:, activity:, duration:)
|
||||
create_time = activity.created_at
|
||||
start_date = (create_time + (duration - 1).year).end_of_month
|
||||
end_date = (create_time + (duration - 1).year + 1).end_of_month
|
||||
line['period'] = start_date..end_date
|
||||
line['start_date'] = (create_time + (duration - 1).year).end_of_month.strftime('%Y-%m-%d')
|
||||
line['end_date'] = (create_time + (duration - 1).year + 1).end_of_month.strftime('%Y-%m-%d')
|
||||
end
|
||||
|
||||
def description_in_language(price:, yearly:)
|
||||
|
|
|
@ -33,6 +33,8 @@ class DirectoInvoiceForwardJob < Que::Job
|
|||
next unless registrar.cash_account
|
||||
|
||||
invoice = registrar.monthly_summary(month: month)
|
||||
next if invoice.nil?
|
||||
|
||||
@client.invoices.add_with_schema(invoice: invoice, schema: 'summary')
|
||||
end
|
||||
|
||||
|
@ -104,9 +106,9 @@ class DirectoInvoiceForwardJob < Que::Job
|
|||
end
|
||||
|
||||
def update_directo_number(num:)
|
||||
return unless num.to_i > Setting.directo_monthly_number_last
|
||||
return unless num.to_i > Setting.directo_monthly_number_last.to_i
|
||||
|
||||
Setting.directo_monthly_number_last = num
|
||||
Setting.directo_monthly_number_last = num.to_i
|
||||
end
|
||||
|
||||
def directo_counter_exceedable?(invoice_count)
|
||||
|
|
2
test/fixtures/account_activities.yml
vendored
2
test/fixtures/account_activities.yml
vendored
|
@ -2,4 +2,4 @@ one:
|
|||
account: cash
|
||||
invoice: one
|
||||
bank_transaction: one
|
||||
created_at: <%= Time.zone.parse('2010-07-05 10:00') %>
|
||||
created_at: <%= Time.zone.parse('2010-07-05 10:00') %>
|
||||
|
|
|
@ -3,6 +3,15 @@ require "test_helper"
|
|||
class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@invoice = invoices(:one)
|
||||
@user = registrars(:bestnames)
|
||||
travel_to Time.zone.parse('2010-07-06')
|
||||
end
|
||||
|
||||
def teardown
|
||||
Setting.clear_cache
|
||||
Setting.directo_monthly_number_min = 309901
|
||||
Setting.directo_monthly_number_max = 309999
|
||||
Setting.directo_monthly_number_last = 309901
|
||||
end
|
||||
|
||||
def test_xml_is_include_transaction_date
|
||||
|
@ -26,4 +35,109 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
|
|||
|
||||
assert_not_empty @invoice.directo_records.first.request
|
||||
end
|
||||
|
||||
def test_fails_if_directo_bounds_exceedable
|
||||
Setting.clear_cache
|
||||
Setting.directo_monthly_number_max = 30990
|
||||
|
||||
assert_raises 'RuntimeError' do
|
||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
||||
end
|
||||
end
|
||||
|
||||
def test_monthly_summary_is_delivered_in_estonian
|
||||
activity = account_activities(:one)
|
||||
price = billing_prices(:create_one_year)
|
||||
activity.update!(activity_type: 'create', price: price)
|
||||
@user.update(language: 'et')
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
|
||||
(body.include? '.test registreerimine: 1 aasta') &&
|
||||
(body.include? 'Domeenide ettemaks') &&
|
||||
(body.include? '309902')
|
||||
end.to_return(status: 200, body: response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
||||
end
|
||||
end
|
||||
|
||||
def test_monthly_summary_is_delivered_in_english
|
||||
activity = account_activities(:one)
|
||||
price = billing_prices(:create_one_year)
|
||||
activity.update(activity_type: 'create', price: price)
|
||||
@user.update(language: 'en')
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'test registration') &&
|
||||
(body.include? 'Domains prepayment') &&
|
||||
(body.include? '309902')
|
||||
end.to_return(status: 200, body: response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
||||
end
|
||||
end
|
||||
|
||||
def test_multi_year_purchases_have_duration_assigned
|
||||
activity = account_activities(:one)
|
||||
price = billing_prices(:create_one_year)
|
||||
price.update(duration: '3 years')
|
||||
activity.update(activity_type: 'create', price: price)
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'StartDate') && (body.include? 'EndDate')
|
||||
end.to_return(status: 200, body: response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
||||
end
|
||||
end
|
||||
|
||||
def test_monthly_duration_products_are_present_in_summary
|
||||
activity = account_activities(:one)
|
||||
price = billing_prices(:create_one_month)
|
||||
activity.update(activity_type: 'create', price: price)
|
||||
|
||||
response = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<results>
|
||||
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
|
||||
</results>
|
||||
XML
|
||||
|
||||
stub_request(:post, ENV['directo_invoice_url']).with do |request|
|
||||
body = CGI.unescape(request.body)
|
||||
(body.include? 'months')
|
||||
end.to_return(status: 200, body: response)
|
||||
|
||||
assert_difference 'Setting.directo_monthly_number_last' do
|
||||
DirectoInvoiceForwardJob.run(monthly: true, dry: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue