mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Fix CC issues
This commit is contained in:
parent
7b4214def1
commit
47cd7cc4f7
2 changed files with 26 additions and 28 deletions
|
@ -4,34 +4,28 @@ module Repp
|
|||
def balance
|
||||
resp = { balance: current_user.registrar.cash_account.balance,
|
||||
currency: current_user.registrar.cash_account.currency }
|
||||
resp[:activities] = activities if params[:detailed] == 'true'
|
||||
render_success(data: resp)
|
||||
end
|
||||
|
||||
def activity
|
||||
resp = { balance: current_user.registrar.cash_account.balance,
|
||||
currency: current_user.registrar.cash_account.currency }
|
||||
resp[:activities] = activities
|
||||
resp[:transactions] = activities if params[:detailed] == 'true'
|
||||
render_success(data: resp)
|
||||
end
|
||||
|
||||
def activities
|
||||
activities = current_user.registrar.cash_account.activities.order(created_at: :desc)
|
||||
activities = activities.where('created_at >= ?', params[:from]) if params[:from]
|
||||
activities = activities.where('created_at <= ?', params[:until]) if params[:until]
|
||||
arr = []
|
||||
activities.each do |a|
|
||||
arr << {
|
||||
created_at: a.created_at,
|
||||
description: a.description,
|
||||
type: a.activity_type == 'add_credit' ? 'credit' : 'debit',
|
||||
sum: a.sum,
|
||||
balance: a.new_balance,
|
||||
}
|
||||
registrar_activities.each do |a|
|
||||
arr << { created_at: a.created_at, description: a.description,
|
||||
type: a.activity_type == 'add_credit' ? 'credit' : 'debit',
|
||||
sum: a.sum, balance: a.new_balance }
|
||||
end
|
||||
|
||||
arr
|
||||
end
|
||||
|
||||
def registrar_activities
|
||||
activities = current_user.registrar.cash_account.activities.order(created_at: :desc)
|
||||
activities = activities.where('created_at >= ?', params[:from]) if params[:from]
|
||||
activities = activities.where('created_at <= ?', params[:until]) if params[:until]
|
||||
|
||||
activities
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ require 'test_helper'
|
|||
|
||||
class ReppV1BalanceTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
travel_to Time.zone.parse('2010-07-05')
|
||||
@registrar = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@registrar.username}:#{@registrar.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
@ -21,10 +22,13 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_can_query_balance_with_details
|
||||
started_from = "2020-01-01"
|
||||
# Create new billable action to get activity
|
||||
post "/repp/v1/domains/renew/bulk", headers: @auth_headers, params: { domains: ['shop.test'], renew_period: '1y' }
|
||||
|
||||
started_from = "2010-07-05"
|
||||
end_to = DateTime.current.to_date.to_s(:db)
|
||||
|
||||
get "/repp/v1/accounts/balance?detailed=true&from=#{started_from}&until=#{end_to}", headers: @auth_headers
|
||||
get "/repp/v1/accounts/balance?detailed=true", headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
@ -32,16 +36,16 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
|
|||
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]
|
||||
entry = json[:data][:transactions].last
|
||||
assert_equal @registrar.registrar.cash_account.account_activities.last.created_at, entry[:created_at]
|
||||
assert_equal @registrar.registrar.cash_account.account_activities.last.description, entry[:description]
|
||||
assert_equal 'debit', entry[:type]
|
||||
assert_equal @registrar.registrar.cash_account.account_activities.last.sum.to_s, entry[:sum]
|
||||
assert_equal @registrar.registrar.cash_account.account_activities.last.new_balance.to_s, entry[:balance]
|
||||
|
||||
json[:data][:transaction].map do |trans|
|
||||
json[:data][:transactions].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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue