mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 19:20:37 +02:00
Refactor and improve invoices
- `runner 'Invoice.cancel_overdue_invoices'` in `schedule.rb` is changed to `rake 'invoices:cancel_overdue'`. - `invoices.payment_term` database column is removed and its value is hardcoded in UI. - `invoices.paid_at` is removed as unused - `invoices.due_date` column's type is now `date`. - `Invoice#invoice_items` renamed to `Invoice#items` and `Invoice` interface to get a list of items is unified. - Default date format in UI. - Default translations are used. - Tests improved. - Specs converted to tests and removed along with factories. - Database structure improved.
This commit is contained in:
parent
d86ec026e3
commit
a97728c0f3
65 changed files with 758 additions and 341 deletions
62
test/services/overdue_invoice_canceller_test.rb
Normal file
62
test/services/overdue_invoice_canceller_test.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
require 'test_helper'
|
||||
|
||||
class OverdueInvoiceCancellerTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@invoice = invoices(:one)
|
||||
end
|
||||
|
||||
def test_default_delay
|
||||
assert_equal 30.days, OverdueInvoiceCanceller.default_delay
|
||||
end
|
||||
|
||||
def test_uses_default_delay_when_not_configured
|
||||
Setting.days_to_keep_overdue_invoices_active = nil
|
||||
canceller = OverdueInvoiceCanceller.new
|
||||
assert_equal OverdueInvoiceCanceller.default_delay, canceller.delay
|
||||
end
|
||||
|
||||
def test_uses_configured_delay
|
||||
Setting.days_to_keep_overdue_invoices_active = 1
|
||||
canceller = OverdueInvoiceCanceller.new
|
||||
assert_equal 1.day, canceller.delay
|
||||
end
|
||||
|
||||
def test_cancels_overdue_invoices
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
@invoice.update!(account_activity: nil, cancelled_at: nil, due_date: '2010-07-03')
|
||||
assert @invoice.cancellable?
|
||||
|
||||
canceller = OverdueInvoiceCanceller.new(delay: 1.day)
|
||||
canceller.cancel
|
||||
@invoice.reload
|
||||
|
||||
assert @invoice.cancelled?
|
||||
end
|
||||
|
||||
def test_yields_cancelled_invoices
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
@invoice.update!(account_activity: nil, cancelled_at: nil, due_date: '2010-07-03')
|
||||
assert @invoice.cancellable?
|
||||
|
||||
canceller = OverdueInvoiceCanceller.new(delay: 1.day)
|
||||
|
||||
iteration_count = 0
|
||||
canceller.cancel do |invoice|
|
||||
assert_equal @invoice, invoice
|
||||
iteration_count += 1
|
||||
end
|
||||
assert_equal 1, iteration_count
|
||||
end
|
||||
|
||||
def test_keeps_not_overdue_invoices_intact
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
@invoice.update!(account_activity: nil, cancelled_at: nil, due_date: '2010-07-04')
|
||||
assert @invoice.cancellable?
|
||||
|
||||
canceller = OverdueInvoiceCanceller.new(delay: 1.day)
|
||||
canceller.cancel
|
||||
@invoice.reload
|
||||
|
||||
assert @invoice.not_cancelled?
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue