Module: DaVinciDTRTestKit::CreateTest

Included in:
QuestionnaireResponseCreateTest, TaskCreateTest
Defined in:
lib/davinci_dtr_test_kit/create_test.rb

Instance Method Summary collapse

Instance Method Details

#perform_create_test(create_resources, resource_type) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/davinci_dtr_test_kit/create_test.rb', line 3

def perform_create_test(create_resources, resource_type)
  skip_if(create_resources.blank?, "No `#{resource_type}` resources to create provided, skipping test.")
  assert_valid_json(create_resources)
  create_resources_list = JSON.parse(create_resources)
  skip_if(!create_resources_list.is_a?(Array), 'Resources to create not inputted in list format, skipping test.')

  valid_create_resources =
    create_resources_list
      .compact_blank
      .map { |resource| FHIR.from_contents(resource.to_json) }
      .select { |resource| resource.resourceType == resource_type }
      .select { |resource| resource_is_valid?(resource:) }

  skip_if(valid_create_resources.blank?,
          %(No valid #{resource_type} resources were provided to send in Create requests, skipping test.))

  valid_create_resources.each do |create_resource|
    fhir_create(create_resource)
    assert_response_status(201)
  end
end