ref: master
plugins/financial/test/unit/financial_plugin/order_transactions_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
require_relative '../../test_helper' class FinancialPlugin::OrderTransactionsTest < ActiveSupport::TestCase include OrdersTestHelper should 'Do not create a transaction when an order is saved without changing its value' do sale = create_default_sale_with_item cycle, profile sale.status = 'ordered' sale.save transactions = sale.financial_transactions sale.status = 'received' sale.save assert_equal transactions, sale.reload.financial_transactions end should 'Do not create a transaction when an order is just created as draft or new' do sale = create_default_sale_with_item cycle, profile assert sale.financial_transactions.empty? end should 'create a transaction when an order is confirmed' do sale = create_default_sale_with_item cycle, profile total = sale.total sale.status = 'ordered' sale.save assert_equal total, sale.reload.financial_transactions.sum(:value) end should 'zero the sum of the order transactions when its state is changed to draft' do sale = create_default_sale_with_item cycle, profile sale.status = 'ordered' sale.save sale.status = 'draft' sale.save assert_equal 0, sale.reload.financial_transactions.sum(:value) end should 'update the transactions sum when an order has its value changed' do sale = create_default_sale_with_item cycle, profile total = sale.total sale.status = 'ordered' sale.save total = sale.financial_transactions.sum(:value) item = sale.items.first item.update_attribute :quantity_consumer_ordered, 20 v = sale.reload.financial_transactions.sum(:value) f = 20*item.price assert_equal v, f end end |