Skip to content

Commit 91fbcb1

Browse files
authored
build(Dr. Rai Indicators): Fix flakey test (#5711)
**Story card:** [sc-16891](https://app.shortcut.com/simpledotorg/story/16891/fix-contact-overdue-patients-indicator-flakey-test) ## Because Flakey tests cost CI money ## This addresses The flakey test in contact overdue patients indicator ## Test instructions suite tests
1 parent a11cfde commit 91fbcb1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

spec/models/dr_rai/contact_overdue_patients_indicator_spec.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,23 @@
5252
it "return the count of contactable patients called" do
5353
facility_1_contactable_patients = create_list(:patient, 3, :hypertension, assigned_facility: facility_1, recorded_at: five_months_ago)
5454
facility_1_patient_with_out_phone = create(:patient, :hypertension, :without_phone_number, assigned_facility: facility_1, recorded_at: five_months_ago)
55-
facility_1_patient_removed_from_list = create(:patient, :hypertension, :removed_from_overdue_list, assigned_facility: facility_1, recorded_at: five_months_ago)
55+
facility_1_patient_removed_from_list = create(:patient, :hypertension, assigned_facility: facility_1, recorded_at: five_months_ago)
56+
57+
# Create appointments for all patients
5658
facility_1_contactable_patients.each do |the_patient|
5759
create(:appointment, patient: the_patient, scheduled_date: one_month_ago, facility: facility_1, device_created_at: two_months_ago)
5860
end
59-
create(:call_result, patient: facility_1_contactable_patients.first, device_created_at: this_month + 15.days)
60-
create(:call_result, patient: facility_1_contactable_patients.second, device_created_at: this_month + 1.days)
61-
create(:call_result, patient: facility_1_contactable_patients.third, device_created_at: two_months_ago + 1.days)
62-
create(:call_result, patient: facility_1_patient_with_out_phone, device_created_at: this_month + 27.days)
63-
create(:call_result, patient: facility_1_patient_removed_from_list, device_created_at: this_month + 4.days)
61+
create(:appointment, patient: facility_1_patient_with_out_phone, scheduled_date: one_month_ago, facility: facility_1, device_created_at: two_months_ago)
62+
create(:appointment, patient: facility_1_patient_removed_from_list, scheduled_date: one_month_ago, facility: facility_1, device_created_at: two_months_ago)
63+
64+
# Create call results - deterministic result_type to avoid flakiness
65+
create(:call_result, patient: facility_1_contactable_patients.first, device_created_at: this_month + 15.days, result_type: :agreed_to_visit)
66+
create(:call_result, patient: facility_1_contactable_patients.second, device_created_at: this_month + 1.days, result_type: :agreed_to_visit)
67+
create(:call_result, patient: facility_1_contactable_patients.third, device_created_at: two_months_ago + 1.days, result_type: :agreed_to_visit)
68+
create(:call_result, patient: facility_1_patient_with_out_phone, device_created_at: this_month + 27.days, result_type: :agreed_to_visit)
69+
# Patient removed from overdue list has 2 call results: one initial removal, one follow-up
70+
create(:call_result, patient: facility_1_patient_removed_from_list, device_created_at: one_month_ago, result_type: :removed_from_overdue_list, remove_reason: :not_responding)
71+
create(:call_result, patient: facility_1_patient_removed_from_list, device_created_at: this_month + 4.days, result_type: :agreed_to_visit)
6472

6573
allow(Reports::PatientState).to receive(:get_refresh_months).and_return(ReportingHelpers.get_refresh_months_between_dates(5.months.ago.to_date, Date.today))
6674
RefreshReportingViews.new(views: views).call
@@ -72,7 +80,7 @@
7280
facility_1_denominator = indicator.denominator(region, period, with_non_contactable: true)
7381

7482
expect(facility_1_numerator).to eq 6
75-
expect(facility_1_denominator).to eq 4
83+
expect(facility_1_denominator).to eq 5 # 5 patients total: 3 contactable + 1 without phone + 1 removed from list
7684
end
7785
end
7886
end

0 commit comments

Comments
 (0)