|
16 | 16 | context "when the feature flag is enabled" do |
17 | 17 | before { Flipper.enable(:sync_vaccination_records_to_nhs_on_create) } |
18 | 18 |
|
19 | | - let(:vaccination_record) do |
20 | | - create(:vaccination_record, outcome:, programme:) |
21 | | - end |
22 | 19 | let(:outcome) { "administered" } |
23 | 20 | let(:programme) { create(:programme, type: "flu") } |
| 21 | + let(:session) { create(:session, programmes: [programme]) } |
| 22 | + let(:vaccination_record) do |
| 23 | + create(:vaccination_record, outcome:, programme:, session:) |
| 24 | + end |
24 | 25 |
|
25 | | - context "when the vaccination record is eligible for syncing" do |
26 | | - it "enqueues the job" do |
| 26 | + context "with a single vaccination record" do |
| 27 | + it "enqueues the job if the vaccination record is elligible to sync" do |
27 | 28 | expect { |
28 | 29 | described_class.call(vaccination_record) |
29 | 30 | }.to have_enqueued_job(SyncVaccinationRecordToNHSJob) |
|
57 | 58 | end |
58 | 59 | end |
59 | 60 | end |
| 61 | + |
| 62 | + context "with a vaccinaton record relation" do |
| 63 | + # The strategy is to create a vaccination record for each of the various |
| 64 | + # variations, and test that only the correct ones are allowed through |
| 65 | + |
| 66 | + before do |
| 67 | + # Generate historic vaccination record (no session) |
| 68 | + create(:vaccination_record, outcome:, programme:) |
| 69 | + |
| 70 | + # Generate vaccination records for all programme types |
| 71 | + Programme.defined_enums["type"].each_key do |programme_type| |
| 72 | + next if programme_type == "flu" |
| 73 | + programme = create(:programme, type: programme_type) |
| 74 | + create(:vaccination_record, outcome: "refused", session:, programme:) |
| 75 | + end |
| 76 | + |
| 77 | + # Generate vaccination records for all outcomes |
| 78 | + VaccinationRecord.defined_enums["outcome"].each_key do |outcome| |
| 79 | + next if outcome == "administered" |
| 80 | + create(:vaccination_record, outcome:, session:, programme:) |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + let(:flu_programme) { Programme.flu.first || create(:programme, :flu) } |
| 85 | + let(:hpv_programme) { Programme.hpv.first || create(:programme, :hpv) } |
| 86 | + let!(:flu_vaccination_record) do |
| 87 | + create( |
| 88 | + :vaccination_record, |
| 89 | + programme: flu_programme, |
| 90 | + session:, |
| 91 | + outcome: :administered |
| 92 | + ) |
| 93 | + end |
| 94 | + let!(:hpv_vaccination_record) do |
| 95 | + create( |
| 96 | + :vaccination_record, |
| 97 | + programme: hpv_programme, |
| 98 | + session:, |
| 99 | + outcome: :administered |
| 100 | + ) |
| 101 | + end |
| 102 | + |
| 103 | + it "enqueues the job for each eligible vaccination record" do |
| 104 | + expect { |
| 105 | + described_class.call(VaccinationRecord.all) |
| 106 | + }.to have_enqueued_job(SyncVaccinationRecordToNHSJob).exactly(2).times |
| 107 | + end |
| 108 | + |
| 109 | + it "enqueues the eligible flu job" do |
| 110 | + expect { |
| 111 | + described_class.call(VaccinationRecord.all) |
| 112 | + }.to have_enqueued_job(SyncVaccinationRecordToNHSJob).with( |
| 113 | + flu_vaccination_record |
| 114 | + ) |
| 115 | + end |
| 116 | + |
| 117 | + it "enqueues the eligible hpv job" do |
| 118 | + expect { |
| 119 | + described_class.call(VaccinationRecord.all) |
| 120 | + }.to have_enqueued_job(SyncVaccinationRecordToNHSJob).with( |
| 121 | + hpv_vaccination_record |
| 122 | + ) |
| 123 | + end |
| 124 | + end |
60 | 125 | end |
61 | 126 | end |
0 commit comments