From 2321c3e5b4766f5819a95e66037c2355fdd1841e Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Wed, 27 Jan 2021 15:59:17 +0200 Subject: [PATCH] added test for check balance activity in account balance overview --- .../repp/v1/accounts/balance_test.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/integration/repp/v1/accounts/balance_test.rb b/test/integration/repp/v1/accounts/balance_test.rb index 785e0aee8..38b793020 100644 --- a/test/integration/repp/v1/accounts/balance_test.rb +++ b/test/integration/repp/v1/accounts/balance_test.rb @@ -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