Skip to content

Commit 8a1b9ba

Browse files
committed
Add EnqueueSyncVaccinationRecordToNHSE
Encapsulates logic for whether to enqueue a vaccination record to sync it to NHSE or not. Jira-Issue: MAV-1482
1 parent d3d40e6 commit 8a1b9ba

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module EnqueueSyncVaccinationRecordToNHS
4+
def self.call(vaccination_record)
5+
if Flipper.enabled?(:sync_vaccination_records_to_nhs_on_create) &&
6+
vaccination_record.programme.type.in?(%w[flu hpv]) &&
7+
vaccination_record.administered?
8+
SyncVaccinationRecordToNHSJob.perform_later(vaccination_record)
9+
end
10+
end
11+
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
describe EnqueueSyncVaccinationRecordToNHS do
4+
context "when the feature flag is disabled" do
5+
before { Flipper.disable(:sync_vaccination_records_to_nhs_on_create) }
6+
7+
let(:vaccination_record) { create(:vaccination_record) }
8+
9+
it "does not enqueue the job" do
10+
expect {
11+
described_class.call(vaccination_record)
12+
}.not_to have_enqueued_job(SyncVaccinationRecordToNHSJob)
13+
end
14+
end
15+
16+
context "when the feature flag is enabled" do
17+
before { Flipper.enable(:sync_vaccination_records_to_nhs_on_create) }
18+
19+
let(:vaccination_record) do
20+
create(:vaccination_record, outcome:, programme:)
21+
end
22+
let(:outcome) { "administered" }
23+
let(:programme) { create(:programme, type: "flu") }
24+
25+
context "when the vaccination record is eligible for syncing" do
26+
it "enqueues the job" do
27+
expect {
28+
described_class.call(vaccination_record)
29+
}.to have_enqueued_job(SyncVaccinationRecordToNHSJob)
30+
end
31+
end
32+
33+
VaccinationRecord.defined_enums["outcome"].each_key do |outcome|
34+
next if outcome == "administered"
35+
36+
context "when the vaccination record outcome is #{outcome}" do
37+
let(:outcome) { outcome }
38+
39+
it "does not enqueue the job" do
40+
expect {
41+
described_class.call(vaccination_record)
42+
}.not_to have_enqueued_job(SyncVaccinationRecordToNHSJob)
43+
end
44+
end
45+
end
46+
47+
Programme.defined_enums["type"].each_key do |programme_type|
48+
next if programme_type.in? %w[flu hpv]
49+
50+
context "when the programme type is #{programme_type}" do
51+
let(:programme) { create(:programme, type: programme_type) }
52+
53+
it "does not enqueue the job" do
54+
expect {
55+
described_class.call(vaccination_record)
56+
}.not_to have_enqueued_job(SyncVaccinationRecordToNHSJob)
57+
end
58+
end
59+
end
60+
end
61+
end

0 commit comments

Comments
 (0)