Skip to content

Commit 4b599bc

Browse files
committed
Ensure vaccination record returns variants
This ensures that if the vaccination record has disease types, then the correct variable is returned for MMR or MMRV. Jira-Issue: MAV-2821
1 parent a0ed5a6 commit 4b599bc

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

app/models/concerns/belongs_to_programme.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ module BelongsToProgramme
2222
end
2323

2424
def programme
25-
find_options = {}
26-
find_options[:disease_types] = disease_types if respond_to?(:disease_types)
27-
find_options[:patient] = patient if respond_to?(:patient)
25+
if (type = programme_type)
26+
options = {}
27+
options[:disease_types] = disease_types if respond_to?(:disease_types)
28+
options[:patient] = patient if respond_to?(:patient)
2829

29-
Programme.find(programme_type, **find_options)
30+
Programme.find(type, **options)
31+
end
3032
end
3133

3234
def programme=(value)

spec/models/vaccination_record_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@
162162
end
163163
end
164164

165+
describe "#programme" do
166+
subject { vaccination_record.programme }
167+
168+
before { Flipper.enable(:mmrv) }
169+
170+
context "for an MMRV vaccine" do
171+
let(:programme) { Programme.mmr }
172+
let(:vaccine) { Vaccine.find_by!(brand: "ProQuad") }
173+
174+
let(:vaccination_record) do
175+
create(:vaccination_record, programme:, vaccine:)
176+
end
177+
178+
its(:name) { should eq("MMRV") }
179+
end
180+
181+
context "for an MMRV vaccination record without a vaccine" do
182+
let(:programme) { Programme.mmr }
183+
let(:disease_types) { %w[measles mumps rubella varicella] }
184+
185+
let(:vaccination_record) do
186+
create(:vaccination_record, programme:, disease_types:, vaccine: nil)
187+
end
188+
189+
its(:name) { should eq("MMRV") }
190+
end
191+
end
192+
165193
describe "#dose_volume_ml" do
166194
subject { vaccination_record.dose_volume_ml }
167195

0 commit comments

Comments
 (0)