mirror of
https://github.com/internetee/registry.git
synced 2025-06-05 12:17:30 +02:00
Merge pull request #1969 from internetee/show-all-domains-by-default-to-users-with-less-than-3000-associated-domains
added init which returns definitly count of domains
This commit is contained in:
commit
670d42ea5e
2 changed files with 73 additions and 1 deletions
|
@ -6,6 +6,8 @@ module Api
|
||||||
class DomainsController < ::Api::V1::Registrant::BaseController
|
class DomainsController < ::Api::V1::Registrant::BaseController
|
||||||
before_action :set_tech_flag, only: [:show]
|
before_action :set_tech_flag, only: [:show]
|
||||||
|
|
||||||
|
LIMIT_DOMAIN_TOTAL = 3000
|
||||||
|
|
||||||
def index
|
def index
|
||||||
limit = params[:limit] || 200
|
limit = params[:limit] || 200
|
||||||
offset = params[:offset] || 0
|
offset = params[:offset] || 0
|
||||||
|
@ -57,10 +59,34 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_user_domains
|
def current_user_domains
|
||||||
current_registrant_user.domains(admin: params[:tech] != 'true')
|
init_count_of_domains
|
||||||
rescue CompanyRegister::NotAvailableError
|
rescue CompanyRegister::NotAvailableError
|
||||||
|
init_count_of_direct_domains
|
||||||
|
end
|
||||||
|
|
||||||
|
def init_count_of_direct_domains
|
||||||
|
if params[:tech] == 'init'
|
||||||
|
if current_user_domains_total_count < LIMIT_DOMAIN_TOTAL
|
||||||
|
return current_registrant_user.direct_domains(admin: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
current_registrant_user.direct_domains(admin: true)
|
||||||
|
end
|
||||||
|
|
||||||
current_registrant_user.direct_domains(admin: params[:tech] != 'true')
|
current_registrant_user.direct_domains(admin: params[:tech] != 'true')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def init_count_of_domains
|
||||||
|
if params[:tech] == 'init'
|
||||||
|
if current_user_domains_total_count < LIMIT_DOMAIN_TOTAL
|
||||||
|
return current_registrant_user.domains(admin: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
current_registrant_user.domains(admin: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
current_registrant_user.domains(admin: params[:tech] != 'true')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
46
test/integration/api/v1/registrant/domains_test.rb
Normal file
46
test/integration/api/v1/registrant/domains_test.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
require 'test_helper'
|
||||||
|
require 'auth_token/auth_token_creator'
|
||||||
|
|
||||||
|
CompanyRegisterClientStub = Struct.new(:any_method) do
|
||||||
|
def representation_rights(citizen_personal_code:, citizen_country_code:)
|
||||||
|
raise CompanyRegister::NotAvailableError
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class RegistrantApiV1DomainsTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@user = users(:registrant)
|
||||||
|
@registrar = registrars(:bestnames)
|
||||||
|
@contact = contacts(:john)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_get_default_counts_of_domains
|
||||||
|
get api_v1_registrant_domains_path + "?tech=init", as: :json,
|
||||||
|
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||||
|
|
||||||
|
assert_response :ok
|
||||||
|
|
||||||
|
response_json = JSON.parse(response.body)
|
||||||
|
assert_equal response_json['total'], 4
|
||||||
|
assert_equal response_json['count'], 4
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_get_default_counts_of_direct_domains
|
||||||
|
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
|
||||||
|
get api_v1_registrant_domains_path + "?tech=init", as: :json,
|
||||||
|
headers: { 'HTTP_AUTHORIZATION' => auth_token }
|
||||||
|
end
|
||||||
|
|
||||||
|
response_json = JSON.parse(response.body)
|
||||||
|
assert_equal response_json['total'], 4
|
||||||
|
assert_equal response_json['count'], 4
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def auth_token
|
||||||
|
token_creator = AuthTokenCreator.create_with_defaults(@user)
|
||||||
|
hash = token_creator.token_in_hash
|
||||||
|
"Bearer #{hash[:access_token]}"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue