Skip to content

Commit dfba49e

Browse files
Update tests to reflect new use of patient_teams
- Should create patient_teams instances for archiving (or not)
1 parent bde1884 commit dfba49e

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

spec/factories/patient_teams.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,33 @@
2222
#
2323
FactoryBot.define do
2424
factory :patient_team do
25+
# Required associations – these will be created automatically if not overridden
2526
patient
2627
team
2728
sources { %i[patient_location] }
29+
30+
trait :patient_location do
31+
sources { %i[patient_location] }
32+
end
33+
34+
trait :archive_reason do
35+
sources { %i[archive_reason] }
36+
end
37+
38+
trait :vaccination_record_session do
39+
sources { %i[vaccination_record_session] }
40+
end
41+
42+
trait :vaccination_record_organisation do
43+
sources { %i[vaccination_record_organisation] }
44+
end
45+
46+
trait :school_move_team do
47+
sources { %i[school_move_team] }
48+
end
49+
50+
trait :school_move_school do
51+
sources { %i[school_move_school] }
52+
end
2853
end
2954
end

spec/models/patient_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@
7777
let(:team) { create(:team) }
7878

7979
context "without an archive reason" do
80+
before { create(:patient_team, team:, patient:) }
81+
8082
it { should_not include(patient) }
8183
end
8284

8385
context "with an archive reason for the team" do
84-
before { create(:archive_reason, :moved_out_of_area, team:, patient:) }
86+
before { create(:patient_team, :archive_reason, team:, patient:) }
8587

8688
it { should include(patient) }
8789
end
8890

8991
context "with an archive reason for a different team" do
90-
before { create(:archive_reason, :imported_in_error, patient:) }
92+
before do
93+
create(:patient_team, team:, patient:)
94+
create(:patient_team, :archive_reason, team: create(:team), patient:)
95+
end
9196

9297
it { should_not include(patient) }
9398
end
@@ -100,17 +105,22 @@
100105
let(:team) { create(:team) }
101106

102107
context "without an archive reason" do
108+
before { create(:patient_team, team:, patient:) }
109+
103110
it { should include(patient) }
104111
end
105112

106113
context "with an archive reason for the team" do
107-
before { create(:archive_reason, :moved_out_of_area, team:, patient:) }
114+
before { create(:patient_team, :archive_reason, team:, patient:) }
108115

109116
it { should_not include(patient) }
110117
end
111118

112119
context "with an archive reason for a different team" do
113-
before { create(:archive_reason, :imported_in_error, patient:) }
120+
before do
121+
create(:patient_team, team:, patient:)
122+
create(:patient_team, :archive_reason, team: create(:team), patient:)
123+
end
114124

115125
it { should include(patient) }
116126
end
@@ -122,6 +132,8 @@
122132
let(:team) { create(:team) }
123133
let(:patient) { create(:patient) }
124134

135+
before { create(:patient_team, team:, patient:) }
136+
125137
context "without pending changes" do
126138
it { should_not include(patient) }
127139
end

0 commit comments

Comments
 (0)