|
3 | 3 | require "rails_helper" |
4 | 4 |
|
5 | 5 | RSpec.describe EventProcedures::Create, type: :operation do |
| 6 | + let(:user) { create(:user) } |
| 7 | + let(:patient) { create(:patient, user: user) } |
| 8 | + |
6 | 9 | describe ".result" do |
7 | 10 | context "when params are valid" do |
8 | 11 | it "is successful" do |
9 | | - user = create(:user) |
10 | 12 | cbhpm = create(:cbhpm) |
11 | 13 | procedure = create(:procedure) |
12 | 14 | create(:cbhpm_procedure, procedure: procedure, cbhpm: cbhpm, anesthetic_port: "1A") |
|
19 | 21 | urgency: false, |
20 | 22 | room_type: EventProcedures::RoomTypes::WARD, |
21 | 23 | payment: EventProcedures::Payments::HEALTH_INSURANCE, |
22 | | - patient_attributes: { id: create(:patient).id }, |
| 24 | + patient_attributes: { id: patient.id, user_id: user.id }, |
23 | 25 | procedure_attributes: { id: procedure.id }, |
24 | 26 | health_insurance_attributes: { id: create(:health_insurance).id } |
25 | 27 | } |
|
30 | 32 | end |
31 | 33 |
|
32 | 34 | it "creates a new event_procedure" do |
33 | | - user = create(:user) |
34 | 35 | cbhpm = create(:cbhpm) |
35 | 36 | procedure = create(:procedure) |
36 | 37 | create(:cbhpm_procedure, procedure: procedure, cbhpm: cbhpm, anesthetic_port: "1A") |
|
43 | 44 | urgency: true, |
44 | 45 | room_type: EventProcedures::RoomTypes::WARD, |
45 | 46 | payment: EventProcedures::Payments::HEALTH_INSURANCE, |
46 | | - patient_attributes: { id: create(:patient).id }, |
| 47 | + patient_attributes: { id: patient.id, user_id: user.id }, |
47 | 48 | procedure_attributes: { id: procedure.id }, |
48 | 49 | health_insurance_attributes: { id: create(:health_insurance).id } |
49 | 50 | } |
|
68 | 69 |
|
69 | 70 | context "when create a new patient" do |
70 | 71 | it "creates and does not duplicate the creation" do |
71 | | - user = create(:user) |
72 | 72 | cbhpm = create(:cbhpm) |
73 | 73 | procedure = create(:procedure) |
74 | 74 | create(:cbhpm_procedure, procedure: procedure, cbhpm: cbhpm, anesthetic_port: "1A") |
|
94 | 94 | context "when create a new procedure" do |
95 | 95 | context "when procedure attributes are valid" do |
96 | 96 | it "does not duplicate the creation" do |
97 | | - user = create(:user) |
98 | 97 | cbhpm = create(:cbhpm) |
99 | 98 | procedure = create(:procedure) |
100 | 99 | create(:cbhpm_procedure, procedure: procedure, cbhpm: cbhpm, anesthetic_port: "1A") |
|
117 | 116 | urgency: true, |
118 | 117 | room_type: EventProcedures::RoomTypes::WARD, |
119 | 118 | payment: EventProcedures::Payments::HEALTH_INSURANCE, |
120 | | - patient_attributes: { id: create(:patient).id }, |
| 119 | + patient_attributes: { id: patient.id, user_id: user.id }, |
121 | 120 | procedure_attributes: procedure_attributes, |
122 | 121 | health_insurance_attributes: { id: create(:health_insurance).id } |
123 | 122 | } |
|
163 | 162 | context "when create a new health_insurance" do |
164 | 163 | context "when health_insurance attributes are valid" do |
165 | 164 | it "does not duplicate the creation" do |
166 | | - user = create(:user) |
167 | 165 | cbhpm = create(:cbhpm) |
168 | 166 | procedure = create(:procedure) |
169 | 167 | create(:cbhpm_procedure, procedure: procedure, cbhpm: cbhpm, anesthetic_port: "1A") |
|
182 | 180 | urgency: nil, |
183 | 181 | room_type: nil, |
184 | 182 | payment: EventProcedures::Payments::OTHERS, |
185 | | - patient_attributes: { id: create(:patient).id }, |
| 183 | + patient_attributes: { id: patient.id, user_id: user.id }, |
186 | 184 | procedure_attributes: { id: procedure.id }, |
187 | 185 | health_insurance_attributes: health_insurance_attributes |
188 | 186 | } |
|
249 | 247 | end |
250 | 248 |
|
251 | 249 | it "returns errors" do |
252 | | - user = create(:user) |
253 | 250 | procedure = create(:procedure) |
254 | | - patient = create(:patient) |
255 | 251 | health_insurance = create(:health_insurance) |
256 | 252 | attributes = { |
257 | 253 | patient_attributes: { id: patient.id }, |
|
0 commit comments