mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 07:04:47 +02:00
Merge remote-tracking branch 'origin/master' into repp-domains
This commit is contained in:
commit
e2f377f1c2
187 changed files with 1934 additions and 2552 deletions
|
@ -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}"
|
||||
|
@ -19,4 +20,32 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
|
|||
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
|
||||
# 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", 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]
|
||||
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][: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
|
||||
|
|
|
@ -37,6 +37,43 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_keeps_update_prohibited_status
|
||||
domain = domains(:shop)
|
||||
domain.update(statuses: [DomainStatus::CLIENT_UPDATE_PROHIBITED, DomainStatus::SERVER_UPDATE_PROHIBITED])
|
||||
payload = {
|
||||
"domains": [
|
||||
'shop.test'
|
||||
],
|
||||
"renew_period": "1y"
|
||||
}
|
||||
|
||||
assert_changes -> { Domain.find_by(name: 'shop.test').valid_to } do
|
||||
post "/repp/v1/domains/renew/bulk", headers: @auth_headers, params: payload
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
assert json[:data][:updated_domains].include? 'shop.test'
|
||||
end
|
||||
domain.reload
|
||||
assert_equal domain.statuses, [DomainStatus::CLIENT_UPDATE_PROHIBITED, DomainStatus::SERVER_UPDATE_PROHIBITED]
|
||||
end
|
||||
|
||||
def test_multi_domains_сannot_be_renewed_with_renew_prohibited_status
|
||||
array_domains = [domains(:shop), domains(:airport)]
|
||||
payload = {
|
||||
"domains": array_domains.pluck(:name),
|
||||
"renew_period": "1y"
|
||||
}
|
||||
|
||||
array_domains.each do |domain|
|
||||
set_status_for_domain(domain, [DomainStatus::CLIENT_RENEW_PROHIBITED, DomainStatus::SERVER_RENEW_PROHIBITED])
|
||||
end
|
||||
|
||||
assert_renew_prohibited_domains(array_domains, payload)
|
||||
end
|
||||
|
||||
def test_throws_error_when_domain_not_renewable
|
||||
payload = {
|
||||
"domains": [
|
||||
|
@ -88,4 +125,36 @@ class ReppV1DomainsBulkRenewTest < ActionDispatch::IntegrationTest
|
|||
assert_equal 2005, json[:code]
|
||||
assert_equal 'Invalid renew period', json[:message]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_status_for_domain(domain, statuses)
|
||||
domain.update(statuses: statuses)
|
||||
|
||||
if statuses.size > 1
|
||||
statuses.each do |status|
|
||||
assert domain.statuses.include? status
|
||||
end
|
||||
else
|
||||
assert domain.statuses.include? statuses
|
||||
end
|
||||
end
|
||||
|
||||
def bulk_renew(payload)
|
||||
post "/repp/v1/domains/renew/bulk", headers: @auth_headers, params: payload
|
||||
JSON.parse(response.body, symbolize_names: true)
|
||||
end
|
||||
|
||||
def assert_renew_prohibited_domains(domains, payload)
|
||||
assert_no_changes -> { Domain.where(name: domains).pluck(:valid_to) } do
|
||||
json = bulk_renew(payload)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 2002, json[:code]
|
||||
assert domains.all? do |domain|
|
||||
json[:message].include? "Domain renew error for #{domain.name}"
|
||||
end
|
||||
assert json[:data].empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,6 +34,33 @@ class ReppV1RegistrarNameserversTest < ActionDispatch::IntegrationTest
|
|||
assert json[:data][:affected_domains].include? 'shop.test'
|
||||
end
|
||||
|
||||
def test_fails_to_update_if_prohibited
|
||||
domain = domains(:shop)
|
||||
domain.update(statuses: [DomainStatus::CLIENT_UPDATE_PROHIBITED])
|
||||
nameserver = nameservers(:shop_ns1)
|
||||
payload = {
|
||||
"data": {
|
||||
"id": nameserver.hostname,
|
||||
"type": "nameserver",
|
||||
"attributes": {
|
||||
"hostname": "#{nameserver.hostname}.test",
|
||||
"ipv4": ["1.1.1.1"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
put '/repp/v1/registrar/nameservers', headers: @auth_headers, params: payload
|
||||
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({ hostname: "#{nameserver.hostname}.test", ipv4: ["1.1.1.1"] }, json[:data][:attributes])
|
||||
assert_equal({ hostname: "#{nameserver.hostname}.test", ipv4: ["1.1.1.1"] }, json[:data][:attributes])
|
||||
assert json[:data][:affected_domains].include? 'airport.test'
|
||||
assert json[:data][:skipped_domains].include? 'shop.test'
|
||||
end
|
||||
|
||||
def test_nameserver_with_hostname_must_exist
|
||||
payload = {
|
||||
"data": {
|
||||
|
|
|
@ -21,7 +21,7 @@ class ReppV1RetainedDomainsTest < ActionDispatch::IntegrationTest
|
|||
status: 'reserved',
|
||||
punycode_name: 'reserved.test' }]
|
||||
|
||||
assert_equal response_json[:domains], expected_objects
|
||||
assert_empty response_json[:domains] - expected_objects
|
||||
end
|
||||
|
||||
def test_get_index_with_type_parameter
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue