mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-06 01:08:21 +01:00
test wallet credit with refund invoice generation
This commit is contained in:
parent
c582d4665d
commit
df411b10b2
@ -74,5 +74,38 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
|||||||
w.reload
|
w.reload
|
||||||
assert_equal w.amount, expected_amount
|
assert_equal w.amount, expected_amount
|
||||||
assert_equal w.amount, wallet[:amount]
|
assert_equal w.amount, wallet[:amount]
|
||||||
|
|
||||||
|
# no refund invoices should have been generated
|
||||||
|
assert_empty Invoice.where(invoiced: w.wallet_transactions.last)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
test 'admin credit wallet with refund invoice generation' do
|
||||||
|
admin = users(:user_1)
|
||||||
|
login_as(admin, scope: :user)
|
||||||
|
w = @vlonchamp.wallet
|
||||||
|
amount = 10
|
||||||
|
avoir_date = Time.now.end_of_day
|
||||||
|
expected_amount = w.amount + amount
|
||||||
|
put "/api/wallet/#{w.id}/credit",
|
||||||
|
{
|
||||||
|
amount: amount,
|
||||||
|
avoir: true,
|
||||||
|
avoir_date: avoir_date,
|
||||||
|
avoir_description: 'Some text'
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_equal 200, response.status
|
||||||
|
assert_equal Mime::JSON, response.content_type
|
||||||
|
wallet = json_response(response.body)
|
||||||
|
w.reload
|
||||||
|
assert_equal w.amount, expected_amount
|
||||||
|
assert_equal w.amount, wallet[:amount]
|
||||||
|
|
||||||
|
# refund invoice must be generated
|
||||||
|
invoice = Invoice.where(invoiced: w.wallet_transactions.last).first
|
||||||
|
assert_equal amount, (invoice.total / 100.0), 'Avoir total does not match the amount credited to the wallet'
|
||||||
|
assert_equal amount, (invoice.invoice_items.first.amount / 100.0), 'Invoice item amount does not match'
|
||||||
|
assert_invoice_pdf invoice
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user