Skip to content

Commit 8585fdc

Browse files
Introduce Programme#all_as_variants
This is similar to `Programme.all`, but returns all `Programme::Variant`s where available, in place of the related full `Programme.` Jira-Issue: MAV-3195
1 parent 5978bd9 commit 8585fdc

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

app/jobs/search_vaccination_records_in_nhs_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def perform(patient_id)
1717
SemanticLogger.tagged(tx_id:, job_id:) do
1818
Sentry.set_tags(tx_id:, job_id:)
1919

20-
programmes = Programme.all.to_a
20+
programmes = Programme.all_as_variants
2121

2222
feature_flag_enabled =
2323
programmes.any? do |programme|

app/models/programme.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def find_all(types, disease_types: nil, patient: nil)
8888
types.map { |type| find(type, patient:, disease_types:) }
8989
end
9090

91+
def all_as_variants
92+
all.flat_map(&:variants)
93+
end
94+
9195
def find(type, disease_types: nil, patient: nil)
9296
validate_type!(type)
9397

spec/models/programme_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,41 @@
1717
describe Programme do
1818
subject(:programme) { described_class.sample }
1919

20+
describe "#all_as_variants" do
21+
subject(:all_as_variants) { described_class.all_as_variants }
22+
23+
context "with the mmrv feature flag off" do
24+
it "returns all the full programme objects" do
25+
expect(all_as_variants).to contain_exactly(
26+
described_class.flu,
27+
described_class.hpv,
28+
described_class.td_ipv,
29+
described_class.menacwy,
30+
described_class.mmr
31+
)
32+
end
33+
end
34+
35+
context "with the mmrv feature flag on" do
36+
before { Flipper.enable(:mmrv) }
37+
38+
it "returns all variants where applicable" do
39+
expect(all_as_variants).to contain_exactly(
40+
described_class.flu,
41+
described_class.hpv,
42+
described_class.td_ipv,
43+
described_class.menacwy,
44+
described_class.mmr.variant_for(
45+
disease_types: Programme::Variant::DISEASE_TYPES.fetch("mmr")
46+
),
47+
described_class.mmr.variant_for(
48+
disease_types: Programme::Variant::DISEASE_TYPES.fetch("mmrv")
49+
)
50+
)
51+
end
52+
end
53+
end
54+
2055
describe "#find" do
2156
subject(:find) { described_class.find(type) }
2257

0 commit comments

Comments
 (0)