Skip to content

Commit 934680b

Browse files
authored
Merge pull request #4453 from nhsuk/fix-tests-outside-preparation-period
Fix tests outside of preparation period
2 parents 4d539cb + d5a3353 commit 934680b

21 files changed

+77
-46
lines changed

app/views/sessions/manage_consent_reminders/show.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{ text: t("sessions.index.title"), href: sessions_path },
55
{ text: @session.location.name, href: session_path(@session) },
66
]) %>
7-
<%= render AppBacklinkComponent.new(session_path(@session), name: @session.location.name) %>
87
<% end %>
98

109
<%= h1 t(".title") %>
@@ -72,4 +71,4 @@
7271
class: "nhsuk-button" %>
7372
<% end %>
7473
</div>
75-
</div>
74+
</div>

db/seeds.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ def create_session(user, team, programmes:, completed: false, year_groups: nil)
8888

8989
session = FactoryBot.create(:session, date:, team:, programmes:, location:)
9090

91-
session.session_dates.create!(value: date - 1.day)
92-
session.session_dates.create!(value: date + 1.day)
91+
[date - 1.day, date + 1.day].each do |value|
92+
if value.in?(session.academic_year.to_academic_year_date_range)
93+
session.session_dates.create!(value:)
94+
end
95+
end
9396

9497
programmes.each do |programme|
9598
year_groups.each do |year_group|

spec/components/app_patient_session_table_component_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
let(:location) { create(:school, name: "Waterloo Road", programmes:) }
1818
let(:session) do
19-
create(
20-
:session,
21-
location:,
22-
programmes:,
23-
academic_year: 2024,
24-
date: Date.new(2025, 1, 1)
25-
)
19+
create(:session, location:, programmes:, date: Date.new(2025, 1, 1))
2620
end
2721

28-
let(:patient_sessions) { create_list(:patient_session, 1, session:) }
22+
# Can't use year_group here because we need an absolute date, not one
23+
# relative to the current academic year.
24+
let(:patient) { create(:patient, date_of_birth: Date.new(2011, 9, 1)) }
25+
26+
let(:patient_sessions) do
27+
create_list(:patient_session, 1, patient:, session:)
28+
end
2929

3030
it { should have_content("Location") }
3131
it { should have_content("Session dates") }

spec/features/cli_gias_check_import_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def and_there_are_schools_with_future_sessions
2222
create(
2323
:session,
2424
location: @school_with_future_session,
25-
dates: [Date.tomorrow],
25+
date: Date.tomorrow,
2626
programmes: [@programme]
2727
)
2828

@@ -32,7 +32,7 @@ def and_there_are_schools_with_future_sessions
3232
create(
3333
:session,
3434
location: @school2_with_future_session,
35-
dates: [Date.tomorrow],
35+
date: Date.tomorrow,
3636
programmes: [@programme]
3737
)
3838

@@ -42,7 +42,7 @@ def and_there_are_schools_with_future_sessions
4242
create(
4343
:session,
4444
location: @school_without_future_session,
45-
dates: [Date.yesterday],
45+
date: Date.yesterday,
4646
programmes: [@programme]
4747
)
4848
end

spec/features/cli_stats_organisations_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ def given_organisation_has_complete_data_with_filters
112112
create(
113113
:session,
114114
team: @team_a,
115-
academic_year: (Date.current.year - 1),
116-
programmes: [programme_flu]
115+
academic_year: AcademicYear.current - 1,
116+
programmes: [programme_flu],
117+
date: (AcademicYear.current - 1).to_academic_year_date_range.end
117118
)
118119

119120
patient_year_8 = create(:patient, team: @team_a, year_group: 8)

spec/features/hpv_vaccination_offline_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# frozen_string_literal: true
22

33
describe "HPV vaccination" do
4-
scenario "Download spreadsheet, record offline at a school session, upload vaccination outcomes back into Mavis" do
5-
travel_to(Time.zone.local(2024, 2, 1, 12, 0, 0))
4+
around do |example|
5+
travel_to(Time.zone.local(2024, 2, 1, 12)) { example.run }
6+
end
67

8+
scenario "Download spreadsheet, record offline at a school session, upload vaccination outcomes back into Mavis" do
79
stub_pds_get_nhs_number_to_return_a_patient
810

911
given_an_hpv_programme_is_underway
@@ -22,8 +24,6 @@
2224
end
2325

2426
scenario "Download spreadsheet, record offline at a clinic, upload vaccination outcomes back into Mavis" do
25-
travel_to(Time.zone.local(2024, 2, 1, 12, 0, 0))
26-
2727
stub_pds_get_nhs_number_to_return_a_patient
2828

2929
given_an_hpv_programme_is_underway(clinic: true)
@@ -355,6 +355,8 @@ def when_i_record_vaccination_outcomes_to_the_spreadsheet_and_export_it_to_csv
355355
end
356356

357357
def and_i_upload_the_modified_csv_file
358+
travel 1.minute
359+
358360
visit "/"
359361

360362
click_on "Import", match: :first

spec/forms/triage_form_spec.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
it { should_not validate_presence_of(:notes) }
1717
it { should_not validate_presence_of(:vaccine_methods) }
1818
it { should validate_length_of(:notes).is_at_most(1000) }
19-
20-
it do
21-
expect(form).to validate_inclusion_of(:add_psd).in_array(
22-
[true, false]
23-
).allow_nil
24-
end
19+
it { should allow_values(true, false).for(:add_psd) }
2520
end
2621

2722
describe "when the patient is safe to vaccinate for HPV" do

spec/lib/reports/careplus_exporter_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
)
1212
end
1313

14+
around { |example| travel_to(Date.new(2025, 8, 31)) { example.run } }
15+
1416
let(:academic_year) { AcademicYear.current }
1517

1618
shared_examples "generates a report" do

spec/lib/reports/systm_one_exporter_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
before { vaccination_record }
77

8+
around { |example| travel_to(Date.new(2025, 8, 31)) { example.run } }
9+
810
let(:csv) do
911
described_class.call(
1012
team:,

spec/lib/stats/consents_by_school_spec.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,20 @@
3131
team: team,
3232
location: school,
3333
programmes: [programme_flu],
34-
academic_year: academic_year,
34+
academic_year:,
3535
send_consent_requests_at: 10.days.ago
3636
)
3737
end
3838

39-
let!(:patient) { create(:patient, team: team) }
40-
let(:patient_session) do
41-
create(:patient_session, session: session, patient: patient)
42-
end
39+
let!(:patient) { create(:patient, team:) }
40+
let(:patient_session) { create(:patient_session, session:, patient:) }
4341

4442
let(:consent) do
4543
create(
4644
:consent,
4745
:given,
48-
patient: patient,
46+
patient:,
47+
academic_year:,
4948
programme: programme_flu,
5049
submitted_at: 8.days.ago,
5150
created_at: 8.days.ago
@@ -92,18 +91,18 @@
9291
described_class.new(
9392
teams: [team],
9493
programmes: [programme_flu],
95-
academic_year: academic_year
94+
academic_year:
9695
)
9796
end
9897

9998
let!(:flu_session) do
10099
create(
101100
:session,
102101
date: Date.new(AcademicYear.current, 12, 15),
103-
team: team,
102+
team:,
104103
location: school,
105104
programmes: [programme_flu],
106-
academic_year: academic_year,
105+
academic_year:,
107106
send_consent_requests_at: Date.new(AcademicYear.current, 12, 1)
108107
)
109108
end
@@ -112,10 +111,10 @@
112111
create(
113112
:session,
114113
date: Date.new(AcademicYear.current, 11, 15),
115-
team: team,
114+
team:,
116115
location: school,
117116
programmes: [programme_hpv],
118-
academic_year: academic_year,
117+
academic_year:,
119118
send_consent_requests_at: Date.new(AcademicYear.current, 11, 1)
120119
)
121120
end
@@ -143,7 +142,7 @@
143142
let!(:current_year_session) do
144143
create(
145144
:session,
146-
team: team,
145+
team:,
147146
location: school,
148147
programmes: [programme_flu],
149148
academic_year: current_year
@@ -154,7 +153,7 @@
154153
create(
155154
:session,
156155
date: Date.new(AcademicYear.current - 1, 12, 15),
157-
team: team,
156+
team:,
158157
location: school,
159158
programmes: [programme_flu],
160159
academic_year: previous_year
@@ -192,7 +191,8 @@
192191
create(
193192
:consent,
194193
:given,
195-
patient: patient,
194+
patient:,
195+
academic_year:,
196196
programme: programme_flu,
197197
submitted_at: 8.days.ago,
198198
created_at: 8.days.ago
@@ -203,7 +203,8 @@
203203
create(
204204
:consent,
205205
:given,
206-
patient: patient,
206+
patient:,
207+
academic_year:,
207208
programme: programme_hpv,
208209
submitted_at: 6.days.ago,
209210
created_at: 6.days.ago

0 commit comments

Comments
 (0)