Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/models/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions test/integration/repp/v1/registrar/summary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions test/models/action_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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