forked from fhir-crucible/fhir_client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_test.rb
50 lines (40 loc) · 2.29 KB
/
create_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require_relative '../../test_helper'
class ClientInterfaceCreateTest < Test::Unit::TestCase
def client
@client ||= FHIR::Client.new('create-test')
end
def test_create_response_properly_parsed_xml
patient = FHIR::Patient.new({'gender'=>'female', 'active'=>true, 'deceasedBoolean'=>false})
outcome = FHIR::OperationOutcome.new({'issue'=>[{'code'=>'informational', 'severity'=>'information', 'diagnostics'=>'Successfully created "Patient/foo" in 0 ms'}]})
stub_request(:post, /create-test/).to_return(body: outcome.to_xml, headers: {'Content-Type'=>'application/fhir+xml', 'Content-Location'=>'Patient/foo/_history/0'})
reply = client.create(patient)
assert reply.resource.is_a?(FHIR::OperationOutcome)
assert reply.resource_class == FHIR::Patient
assert reply.id == 'foo'
end
def test_create_response_properly_parsed_json
patient = FHIR::Patient.new({'gender'=>'female', 'active'=>true, 'deceasedBoolean'=>false})
outcome = FHIR::OperationOutcome.new({'issue'=>[{'code'=>'informational', 'severity'=>'information', 'diagnostics'=>'Successfully created "Patient/foo" in 0 ms'}]})
stub_request(:post, /create-test/).to_return(body: outcome.to_json, headers: {'Content-Type'=>'application/fhir+json', 'Content-Location'=>'Patient/foo/_history/0'})
reply = client.create(patient)
assert reply.resource.is_a?(FHIR::OperationOutcome)
assert reply.resource_class == FHIR::Patient
assert reply.id == 'foo'
end
def test_create_response_blank
patient = FHIR::Patient.new({'gender'=>'female', 'active'=>true, 'deceasedBoolean'=>false})
stub_request(:post, /create-test/).to_return(headers: {'Content-Location'=>'Patient/foo/_history/0'})
reply = client.create(patient)
assert reply.resource.is_a?(FHIR::Patient)
assert reply.resource_class == FHIR::Patient
assert reply.id == 'foo'
end
def test_read
patient = FHIR::Patient.new({'gender'=>'female', 'active'=>true, 'deceasedBoolean'=>false})
stub_request(:get, /create-test/).to_return(body: patient.to_json, headers: {'Content-Type'=>'application/fhir+json', 'Content-Location'=>'Patient/foo/_history/0'})
reply = client.read(FHIR::Patient,'foo')
assert reply.resource.is_a?(FHIR::Patient)
assert reply.resource_class == FHIR::Patient
assert reply.id == 'foo'
end
end