Skip to content

Commit

Permalink
Fix Organization validation so that it skips to the next one if there…
Browse files Browse the repository at this point in the history
… is a necessary field needed for validation missing
  • Loading branch information
emichaud998 committed Dec 6, 2024
1 parent b90c94f commit 534c116
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/service_base_url_test_kit/service_base_url_validate_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def limit_bundle_entries(resource_validation_limit, bundle_resource)
elsif organization_resource.partOf.present?
parent_org = find_parent_organization_entry(organization_entries, organization_resource.partOf.reference)

unless resource_already_exists?(new_entries, parent_org, 'Organization')
unless parent_org.blank? || resource_already_exists?(new_entries, parent_org, 'Organization')
new_entries.append(parent_org)
resource_validation_limit -= 1

Expand All @@ -138,12 +138,25 @@ def limit_bundle_entries(resource_validation_limit, bundle_resource)
end

found_endpoint_entries.each do |found_endpoint_entry|
unless resource_already_exists?(new_entries, found_endpoint_entry, 'Endpoint')
new_entries.append(found_endpoint_entry)
resource_validation_limit -= 1
next if resource_already_exists?(new_entries, found_endpoint_entry, 'Endpoint')

new_entries.append(found_endpoint_entry)

endpoint_entries.delete_if do |entry|
entry.resource.resourceType == 'Endpoint' && entry.resource.id == found_endpoint_entry.resource.id
end

resource_validation_limit -= 1
end
end

endpoint_entries.each do |endpoint_entry|
break if resource_validation_limit <= 0

new_entries.append(endpoint_entry)
resource_validation_limit -= 1
end

new_entries
end

Expand All @@ -158,7 +171,7 @@ def find_referenced_endpoints(organization_endpoints, endpoint_entries)
found_endpoint = endpoint_entries.find do |endpoint_entry|
endpoint_ref.reference.include?(endpoint_entry.resource.id)
end
endpoints.append(found_endpoint)
endpoints.append(found_endpoint) if found_endpoint.present?
end
endpoints
end
Expand Down Expand Up @@ -448,6 +461,7 @@ def resource_already_exists?(new_entries, found_resource_entry, resource_type)
add_message('error', %(
Organization with id: #{organization.id} does not have the endpoint or partOf field populated
))
next
end

parent_organization = find_parent_organization(bundle_resource, organization.partOf.reference)
Expand All @@ -457,6 +471,7 @@ def resource_already_exists?(new_entries, found_resource_entry, resource_type)
Organization with id: #{organization.id} references parent Organization not found in the Bundle:
#{organization.partOf.reference}
))
next
end

if parent_organization.endpoint.empty?
Expand Down

0 comments on commit 534c116

Please sign in to comment.