|
8 | 8 | file_fixture("pds/get-patient-response-deceased.json").read |
9 | 9 | end |
10 | 10 |
|
11 | | - before do |
12 | | - allow(NHS::PDS).to receive(:get_patient).and_return( |
13 | | - instance_double( |
14 | | - Faraday::Response, |
15 | | - status: 200, |
16 | | - body: JSON.parse(json_response) |
17 | | - ) |
18 | | - ) |
19 | | - end |
| 11 | + context "with pds.enabled is false" do |
| 12 | + before { Settings.pds.enabled = false } |
20 | 13 |
|
21 | | - it "calls get_patient on PDS library" do |
22 | | - find |
23 | | - expect(NHS::PDS).to have_received(:get_patient).with("9000000009") |
| 14 | + after { Settings.reload! } |
| 15 | + |
| 16 | + it { should be_nil } |
24 | 17 | end |
25 | 18 |
|
26 | | - it "parses the patient information" do |
27 | | - expect(find).to have_attributes( |
28 | | - nhs_number: "9000000009", |
29 | | - family_name: "Smith", |
30 | | - date_of_birth: Date.new(2010, 10, 22), |
31 | | - date_of_death: Date.new(2010, 10, 22), |
32 | | - restricted: true, |
33 | | - gp_ods_code: "Y12345" |
34 | | - ) |
| 19 | + context "when the patient exists" do |
| 20 | + before do |
| 21 | + allow(NHS::PDS).to receive(:get_patient).and_return( |
| 22 | + instance_double( |
| 23 | + Faraday::Response, |
| 24 | + status: 200, |
| 25 | + body: JSON.parse(json_response) |
| 26 | + ) |
| 27 | + ) |
| 28 | + end |
| 29 | + |
| 30 | + it "calls get_patient on PDS library" do |
| 31 | + find |
| 32 | + expect(NHS::PDS).to have_received(:get_patient).with("9000000009") |
| 33 | + end |
| 34 | + |
| 35 | + it "parses the patient information" do |
| 36 | + expect(find).to have_attributes( |
| 37 | + nhs_number: "9000000009", |
| 38 | + family_name: "Smith", |
| 39 | + date_of_birth: Date.new(2010, 10, 22), |
| 40 | + date_of_death: Date.new(2010, 10, 22), |
| 41 | + restricted: true, |
| 42 | + gp_ods_code: "Y12345" |
| 43 | + ) |
| 44 | + end |
35 | 45 | end |
36 | 46 | end |
37 | 47 |
|
|
49 | 59 | file_fixture("pds/search-patients-response.json").read |
50 | 60 | end |
51 | 61 |
|
52 | | - before do |
53 | | - allow(NHS::PDS).to receive(:search_patients).and_return( |
54 | | - instance_double( |
55 | | - Faraday::Response, |
56 | | - status: 200, |
57 | | - body: JSON.parse(json_response) |
58 | | - ) |
59 | | - ) |
60 | | - end |
| 62 | + context "with pds.enabled is false" do |
| 63 | + before { Settings.pds.enabled = false } |
61 | 64 |
|
62 | | - it "calls find on PDS library" do |
63 | | - search |
64 | | - expect(NHS::PDS).to have_received(:search_patients).with( |
65 | | - { |
66 | | - "_history" => true, |
67 | | - "address-postalcode" => "SW11 1AA", |
68 | | - "birthdate" => "eq2020-01-01", |
69 | | - "family" => "Smith", |
70 | | - "given" => "John" |
71 | | - } |
72 | | - ) |
| 65 | + after { Settings.reload! } |
| 66 | + |
| 67 | + it { should be_nil } |
73 | 68 | end |
74 | 69 |
|
75 | | - it "parses the patient information" do |
76 | | - expect(search).to have_attributes( |
77 | | - nhs_number: "9449306168", |
78 | | - family_name: "LAWMAN", |
79 | | - date_of_birth: Date.new(1939, 1, 9), |
80 | | - date_of_death: nil, |
81 | | - restricted: false, |
82 | | - gp_ods_code: "H81109" |
83 | | - ) |
| 70 | + context "when the patient exists" do |
| 71 | + before do |
| 72 | + allow(NHS::PDS).to receive(:search_patients).and_return( |
| 73 | + instance_double( |
| 74 | + Faraday::Response, |
| 75 | + status: 200, |
| 76 | + body: JSON.parse(json_response) |
| 77 | + ) |
| 78 | + ) |
| 79 | + end |
| 80 | + |
| 81 | + it "calls find on PDS library" do |
| 82 | + search |
| 83 | + expect(NHS::PDS).to have_received(:search_patients).with( |
| 84 | + { |
| 85 | + "_history" => true, |
| 86 | + "address-postalcode" => "SW11 1AA", |
| 87 | + "birthdate" => "eq2020-01-01", |
| 88 | + "family" => "Smith", |
| 89 | + "given" => "John" |
| 90 | + } |
| 91 | + ) |
| 92 | + end |
| 93 | + |
| 94 | + it "parses the patient information" do |
| 95 | + expect(search).to have_attributes( |
| 96 | + nhs_number: "9449306168", |
| 97 | + family_name: "LAWMAN", |
| 98 | + date_of_birth: Date.new(1939, 1, 9), |
| 99 | + date_of_death: nil, |
| 100 | + restricted: false, |
| 101 | + gp_ods_code: "H81109" |
| 102 | + ) |
| 103 | + end |
84 | 104 | end |
85 | 105 | end |
86 | 106 | end |
0 commit comments