2023-03-22 17:30:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-18 18:16:54 +02:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class WalletTest < ActiveSupport::TestCase
|
2019-06-03 16:00:09 +02:00
|
|
|
test 'default amount must be zero' do
|
2016-07-18 18:16:54 +02:00
|
|
|
w = Wallet.new
|
2019-06-03 16:00:09 +02:00
|
|
|
assert w.amount.zero?
|
2016-07-18 18:16:54 +02:00
|
|
|
end
|
|
|
|
|
2019-06-03 16:00:09 +02:00
|
|
|
test 'should invoicing_profile present' do
|
2016-07-18 18:16:54 +02:00
|
|
|
w = Wallet.create
|
2019-06-03 16:00:09 +02:00
|
|
|
assert w.errors[:invoicing_profile].present?
|
2016-07-18 18:16:54 +02:00
|
|
|
end
|
2016-07-04 19:20:10 +02:00
|
|
|
|
|
|
|
test 'can credit amount' do
|
|
|
|
w = Wallet.first
|
2016-07-11 16:04:15 +02:00
|
|
|
expected_amount = w.amount + 5.5
|
|
|
|
assert w.credit(5.5)
|
2016-07-04 19:20:10 +02:00
|
|
|
assert_equal w.amount, expected_amount
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'can debit amount' do
|
|
|
|
w = Wallet.first
|
|
|
|
w.credit(5)
|
2016-07-05 13:20:25 +02:00
|
|
|
expected_amount = w.amount - 5
|
2016-07-04 19:20:10 +02:00
|
|
|
assert w.debit(5)
|
|
|
|
assert_equal w.amount, expected_amount
|
|
|
|
end
|
2016-07-05 10:38:39 +02:00
|
|
|
|
|
|
|
test 'cant debit/credit a negative' do
|
|
|
|
w = Wallet.new
|
|
|
|
assert_not w.credit(-5)
|
|
|
|
assert_not w.debit(-5)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'wallet amount cant < 0 after debit' do
|
|
|
|
w = Wallet.new
|
|
|
|
assert_not w.debit(5)
|
|
|
|
end
|
2016-07-18 18:16:54 +02:00
|
|
|
end
|