|
| 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