Fix bulk nameserver notification handling

This commit is contained in:
Karl Erik Õunapuu 2020-12-22 16:08:15 +02:00
parent f80c597be8
commit 8f25175cec
No known key found for this signature in database
GPG key ID: C9DD647298A34764
4 changed files with 19 additions and 8 deletions

View file

@ -49,12 +49,13 @@ class Registrar
if response.code == '200' if response.code == '200'
notices = [t('.replaced')] notices = [t('.replaced')]
notices << "#{t('.affected_domains')}: #{parsed_response[:affected_domains].join(', ')}" notices << "#{t('.affected_domains')}: " \
"#{parsed_response[:data][:affected_domains].join(', ')}"
flash[:notice] = notices flash[:notice] = notices.join(', ')
redirect_to registrar_domains_url redirect_to registrar_domains_url
else else
@api_errors = parsed_response[:errors] @api_errors = parsed_response[:message]
render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver } render file: 'registrar/bulk_change/new', locals: { active_tab: :nameserver }
end end
end end

View file

@ -1,9 +1,13 @@
<% if @api_errors %> <% if @api_errors %>
<div class="alert alert-danger"> <div class="alert alert-danger">
<ul> <ul>
<% if @api_errors.is_a?(String) %>
<li><%= @api_errors %></li>
<% else %>
<% @api_errors.each do |error| %> <% @api_errors.each do |error| %>
<li><%= error[:title] %></li> <li><%= error[:title] %></li>
<% end %> <% end %>
<% end %>
</ul> </ul>
</div> </div>
<% end %> <% end %>

View file

@ -1,9 +1,13 @@
<% if @api_errors %> <% if @api_errors %>
<div class="alert alert-danger"> <div class="alert alert-danger">
<ul> <ul>
<% if @api_errors.is_a?(String) %>
<li><%= @api_errors %></li>
<% else %>
<% @api_errors.each do |error| %> <% @api_errors.each do |error| %>
<li><%= error[:title] %></li> <li><%= error[:title] %></li>
<% end %> <% end %>
<% end %>
</ul> </ul>
</div> </div>
<% end %> <% end %>

View file

@ -15,10 +15,12 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body, request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body,
headers: { 'Content-type' => Mime[:json] }, headers: { 'Content-type' => Mime[:json] },
basic_auth: ['test_goodnames', 'testtest']) basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{ .to_return(body: { data: {
type: 'nameserver', type: 'nameserver',
id: 'new-ns.bestnames.test'}], id: 'new-ns.bestnames.test',
affected_domains: ["airport.test", "shop.test"]}.to_json, status: 200) affected_domains: ["airport.test", "shop.test"]
}
}.to_json, status: 200)
visit registrar_domains_url visit registrar_domains_url
click_link 'Bulk change' click_link 'Bulk change'
@ -38,7 +40,7 @@ class RegistrarAreaNameserverBulkChangeTest < ApplicationSystemTestCase
def test_fails_gracefully def test_fails_gracefully
stub_request(:put, /registrar\/nameservers/).to_return(status: 400, stub_request(:put, /registrar\/nameservers/).to_return(status: 400,
body: { errors: [{ title: 'epic fail' }] }.to_json, body: { message: 'epic fail' }.to_json,
headers: { 'Content-type' => Mime[:json] }) headers: { 'Content-type' => Mime[:json] })
visit registrar_domains_url visit registrar_domains_url