|
12 | 12 |
|
13 | 13 | let(:programme) { Programme.hpv } |
14 | 14 | let(:session) { create(:session, team:, programmes: [programme]) } |
15 | | - let(:patient) { create(:patient, :in_attendance, session:) } |
| 15 | + let(:patient) { create(:patient, :in_attendance, session:, date_of_birth: Date.new(2020, 8, 31)) } |
| 16 | + |
16 | 17 | let(:vaccine) { programme.vaccines.first } |
17 | 18 | let(:batch) { create(:batch, team:, vaccine:, expiry: Date.new(2026, 11, 1)) } |
18 | 19 |
|
|
64 | 65 | end |
65 | 66 | end |
66 | 67 |
|
67 | | - context "when performed_at is before the start of the academic year" do |
| 68 | + context "when the programme is flu" do |
68 | 69 | let(:attributes) do |
69 | 70 | valid_administered_attributes.merge( |
70 | | - performed_at: Time.zone.local(2023, 8, 31, 12) |
| 71 | + performed_at: Time.zone.local(2023, 8, 31, 12), |
| 72 | + programme_type: Programme.flu.type |
71 | 73 | ) |
72 | 74 | end |
73 | 75 |
|
74 | | - around { |example| travel_to(Date.new(2025, 8, 31)) { example.run } } |
| 76 | + context "when performed_at is before the start of the academic year" do |
| 77 | + around { |example| travel_to(Date.new(2025, 8, 31)) { example.run } } |
75 | 78 |
|
76 | | - before { draft_vaccination_record.wizard_step = :date_and_time } |
| 79 | + before { draft_vaccination_record.wizard_step = :date_and_time } |
77 | 80 |
|
78 | | - it "has an error" do |
79 | | - expect(draft_vaccination_record.save(context: :update)).to be(false) |
80 | | - expect(draft_vaccination_record.errors[:performed_at_date]).to include( |
81 | | - "The vaccination cannot take place before 1 September 2024" |
| 81 | + it "has an error" do |
| 82 | + expect(draft_vaccination_record.save(context: :update)).to be(false) |
| 83 | + expect(draft_vaccination_record.errors[:performed_at_date]).to include( |
| 84 | + "The vaccination cannot take place before 1 September 2024" |
| 85 | + ) |
| 86 | + end |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | + context "when the record is national reporting" do |
| 91 | + let(:team) { create(:team, :national_reporting, :with_one_nurse, programmes: [programme]) } |
| 92 | + let(:attributes) do |
| 93 | + valid_administered_attributes.merge( |
| 94 | + performed_at: Time.zone.local(2023, 8, 31, 12), |
| 95 | + programme_type: Programme.mmr.type, |
| 96 | + source: "national_reporting" |
82 | 97 | ) |
83 | 98 | end |
| 99 | + |
| 100 | + context "when performed_at is before the start of the academic year" do |
| 101 | + around { |example| travel_to(Date.new(2025, 8, 31)) { example.run } } |
| 102 | + |
| 103 | + before { draft_vaccination_record.wizard_step = :date_and_time } |
| 104 | + |
| 105 | + it "has an error" do |
| 106 | + expect(draft_vaccination_record.save(context: :update)).to be(false) |
| 107 | + expect(draft_vaccination_record.errors[:performed_at_date]).to include( |
| 108 | + "The vaccination cannot take place before 1 September 2024" |
| 109 | + ) |
| 110 | + end |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + context "when the programme is not flu" do |
| 115 | + let(:attributes) do |
| 116 | + valid_administered_attributes.merge( |
| 117 | + performed_at: Time.zone.local(2023, 8, 31, 12), |
| 118 | + programme_type: Programme.mmr.type |
| 119 | + ) |
| 120 | + end |
| 121 | + |
| 122 | + context "when performed_at is before the start of the academic year for an already vaccinated patient" do |
| 123 | + around { |example| travel_to(Date.new(2025, 8, 31)) { example.run } } |
| 124 | + |
| 125 | + before { draft_vaccination_record.wizard_step = :date_and_time } |
| 126 | + |
| 127 | + it "is valid" do |
| 128 | + expect(draft_vaccination_record.save(context: :update)).to be(true) |
| 129 | + expect(draft_vaccination_record.errors[:performed_at_date]).to be_empty |
| 130 | + end |
| 131 | + end |
| 132 | + |
| 133 | + context "when performed_at is before patient date of birth" do |
| 134 | + let(:patient) { create(:patient, :in_attendance, session:, date_of_birth: Date.new(2020, 8, 31)) } |
| 135 | + let(:attributes) do |
| 136 | + valid_administered_attributes.merge( |
| 137 | + performed_at: Time.zone.local(2020, 8, 30, 12), |
| 138 | + outcome: "already_had" |
| 139 | + ) |
| 140 | + end |
| 141 | + |
| 142 | + around { |example| travel_to(Date.new(2025, 8, 31)) { example.run } } |
| 143 | + |
| 144 | + before { draft_vaccination_record.wizard_step = :date_and_time } |
| 145 | + |
| 146 | + it "has an error" do |
| 147 | + expect(draft_vaccination_record.save(context: :update)).to be(false) |
| 148 | + expect(draft_vaccination_record.errors[:performed_at_date]).to include( |
| 149 | + "The vaccination cannot take place before 31 August 2020" |
| 150 | + ) |
| 151 | + end |
| 152 | + end |
84 | 153 | end |
85 | 154 |
|
86 | 155 | context "when performed_at is after the end of a previous academic year session" do |
|
0 commit comments