From 66fd99bbbe70252ec21e7ac2c100581e41034701 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Fri, 19 Jun 2026 11:48:02 +0300 Subject: [PATCH] Handle missing contacts in contact update action serialization --- app/models/action.rb | 13 ++++++++---- .../repp/v1/registrar/summary_test.rb | 18 +++++++++++++++++ test/models/action_test.rb | 20 +++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/models/action.rb b/app/models/action.rb index cf214851e1..983c40718b 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -29,16 +29,21 @@ def bulk_action? end def to_non_available_contact_codes - return [serialized_contact(contact)] unless bulk_action? + return subaction_contact_codes if bulk_action? - subactions.map do |a| - serialized_contact(a.contact) - end + contact_code = serialized_contact(contact) + contact_code ? [contact_code] : [] end private + def subaction_contact_codes + subactions.filter_map { |a| serialized_contact(a.contact) } + end + def serialized_contact(contact) + return unless contact + { code: contact.code, avail: 0, diff --git a/test/integration/repp/v1/registrar/summary_test.rb b/test/integration/repp/v1/registrar/summary_test.rb index bd58d8e976..6b23365fc5 100644 --- a/test/integration/repp/v1/registrar/summary_test.rb +++ b/test/integration/repp/v1/registrar/summary_test.rb @@ -58,4 +58,22 @@ def test_returns_error_response_if_throttled ENV["shunter_default_threshold"] = '10000' ENV["shunter_enabled"] = 'false' end + + def test_handles_contact_update_notification_with_missing_contact + action = actions(:contact_update) + action.update!(contact: nil) + notifications(:complete).update!( + action: action, + attached_obj_type: 'ContactUpdateAction', + attached_obj_id: action.id, + text: 'Contact update notification' + ) + + get '/repp/v1/registrar/summary', headers: @auth_headers + json = JSON.parse(response.body, symbolize_names: true) + + assert_response :ok + assert_equal 1000, json[:code] + assert_equal [], json[:data][:notification][:attached_obj_data][:contacts] + end end diff --git a/test/models/action_test.rb b/test/models/action_test.rb index c68399abef..68de7687d4 100644 --- a/test/models/action_test.rb +++ b/test/models/action_test.rb @@ -17,4 +17,24 @@ def test_invalid_with_unsupported_operation def test_notification_key_for_contact assert_equal :contact_update, @action.notification_key end + + def test_to_non_available_contact_codes + assert_equal [{ code: @action.contact.code, avail: 0, reason: 'in use' }], + @action.to_non_available_contact_codes + end + + def test_to_non_available_contact_codes_with_missing_contact + @action.update!(contact: nil) + + assert_equal [], @action.to_non_available_contact_codes + end + + def test_to_non_available_contact_codes_for_bulk_action_with_missing_subaction_contact + bulk_action = actions(:contacts_update_bulk_action) + actions(:contact_update_subaction_one).update!(contact: nil) + + codes = bulk_action.to_non_available_contact_codes + assert_equal 1, codes.size + assert_equal actions(:contact_update_subaction_two).contact.code, codes.first[:code] + end end \ No newline at end of file