Module: USCoreTestKit::GranularScope
- Included in:
- GranularScopeReadTest, GranularScopeSearchTest
- Defined in:
- lib/us_core_test_kit/granular_scope.rb
Instance Method Summary collapse
- #granular_scope_search_params ⇒ Object
- #granular_scopes ⇒ Object
- #previous_request_resources ⇒ Object
- #resource_specific_granular_scope_search_params ⇒ Object
Instance Method Details
#granular_scope_search_params ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/us_core_test_kit/granular_scope.rb', line 14 def granular_scope_search_params @granular_scope_search_params ||= granular_scopes.map do |scope| _, granular_scope = scope.split('?') name, value = granular_scope.split('=') { name:, value: } end end |
#granular_scopes ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/us_core_test_kit/granular_scope.rb', line 4 def granular_scopes @granular_scopes ||= received_scopes .split(' ') .select do |scope| (scope.start_with?("patient/#{resource_type}") || scope.start_with?("user/#{resource_type}")) && scope.include?('?') end end |
#previous_request_resources ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/us_core_test_kit/granular_scope.rb', line 40 def previous_request_resources first_request = previous_requests.first next_page_url = nil hash = Hash.new { |hash, key| hash[key] = [] } previous_requests.each_with_object(hash) do |request, request_resource_hash| request_resources = if request.status == 200 request.resource.entry.map(&:resource).select { |resource| resource.resourceType == resource_type } else [] end first_request = request if request.url != next_page_url request_resource_hash[first_request].concat(request_resources) next if request.resource&.resourceType != 'Bundle' next_page_url = request.resource&.link&.find { |link| link.relation == 'next' }&.url end end |
#resource_specific_granular_scope_search_params ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/us_core_test_kit/granular_scope.rb', line 27 def resource_specific_granular_scope_search_params @resource_specific_granular_scope_search_params ||= granular_scopes.select {|scope| scope.include?(resource_type)}.map do |scope| _, granular_scope = scope.split('?') name, value = granular_scope.split('=') _, value = value.split('|') { name:, value: } end end |