added test for check balance activity in account balance overview

This commit is contained in:
Oleg Hasjanov 2021-01-27 15:59:17 +02:00
parent 35a6438cf4
commit 2321c3e5b4

View file

@ -13,10 +13,39 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
get '/repp/v1/accounts/balance', headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
puts response.body
puts @registrar.registrar.cash_account.balance
puts @registrar.registrar.cash_account.currency
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
assert_equal @registrar.registrar.cash_account.balance.to_s, json[:data][:balance]
assert_equal @registrar.registrar.cash_account.currency, json[:data][:currency]
end
def test_can_query_balance_with_details
started_from = "2020-01-01"
end_to = DateTime.current.to_date.to_s(:db)
get "/repp/v1/accounts/balance?detailed=true&started_from=#{started_from}&end_to=#{end_to}", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
assert_equal @registrar.registrar.cash_account.balance.to_s, json[:data][:balance]
assert_equal @registrar.registrar.cash_account.currency, json[:data][:currency]
assert_equal @registrar.registrar.cash_account.account_activities[0].created_at, json[:data][:transactions][0][:created_at]
assert_equal @registrar.registrar.cash_account.account_activities[0].description, json[:data][:transactions][0][:description]
assert_equal @registrar.registrar.cash_account.account_activities[0].activity_type, json[:data][:transactions][0][:action]
assert_equal @registrar.registrar.cash_account.account_activities[0].sum.to_s, json[:data][:transactions][0][:price]
assert_equal @registrar.registrar.cash_account.account_activities[0].new_balance.to_s, json[:data][:transactions][0][:new_balance]
json[:data][:transaction].map do |trans|
assert trans[:created_at].to_date.to_s(:db) >= started_from
assert trans[:created_at].to_date.to_s(:db) >= end_to
end
end
end