Skip to content

Commit e2b42bf

Browse files
test: the patient_id is included in the logs
Jira-Issue: MAV-1069
1 parent d1e9281 commit e2b42bf

13 files changed

Lines changed: 342 additions & 1 deletion

app/lib/team_cached_counts.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def school_moves
3939
Rails
4040
.cache
4141
.fetch(school_moves_key) do
42-
SchoolMovePolicy::Scope.new(current_user, SchoolMove).resolve.count
42+
x = SchoolMovePolicy::Scope.new(current_user, SchoolMove).resolve
43+
x.count
4344
end
4445
end
4546

spec/controllers/consent_forms_controller_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,27 @@
6161

6262
it_behaves_like "a method that updates team cached counts"
6363
end
64+
65+
describe "PatientLoggingConcern" do
66+
let(:consent_form) { create(:consent_form, :recorded) }
67+
let(:patient) { create(:patient) }
68+
69+
it_behaves_like "a controller that logs the patient ID",
70+
-> do
71+
get :edit_match,
72+
params: {
73+
id: consent_form.id,
74+
patient_id: patient.id
75+
}
76+
end
77+
78+
it_behaves_like "a controller that logs the patient ID",
79+
-> do
80+
post :update_match,
81+
params: {
82+
id: consent_form.id,
83+
patient_id: patient.id
84+
}
85+
end
86+
end
6487
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
describe DraftConsentsController do
4+
let(:patient) { create(:patient) }
5+
let(:programme) { create(:programme) }
6+
7+
describe "PatientLoggingConcern" do
8+
before do
9+
allow(controller).to receive_messages(
10+
session: {
11+
"consent" => {
12+
"patient_id" => patient.id,
13+
"programme_id" => programme.id
14+
}
15+
}
16+
)
17+
18+
# Avoid hitting complex persistence paths irrelevant to logging in update action
19+
allow(controller).to receive(:handle_confirm).and_return(nil)
20+
end
21+
22+
it_behaves_like "a controller that logs the patient ID",
23+
-> { get :show, params: { id: "confirm" } }
24+
25+
it_behaves_like "a controller that logs the patient ID",
26+
-> do
27+
put :update,
28+
params: {
29+
id: "confirm",
30+
draft_consent: {
31+
wizard_step: :confirm,
32+
notes: "ok"
33+
}
34+
}
35+
end
36+
end
37+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
describe DraftVaccinationRecordsController do
4+
let(:patient) { create(:patient) }
5+
6+
describe "PatientLoggingConcern" do
7+
before do
8+
allow(controller).to receive(:session).and_return(
9+
{ "vaccination_record" => { "patient_id" => patient.id } }
10+
)
11+
end
12+
13+
it_behaves_like "a controller that logs the patient ID",
14+
-> { get :show, params: { id: "confirm" } }
15+
16+
it_behaves_like "a controller that logs the patient ID",
17+
-> do
18+
put :update,
19+
params: {
20+
id: "confirm",
21+
draft_vaccination_record: {
22+
wizard_step: :confirm,
23+
notes: "ok"
24+
}
25+
}
26+
end
27+
end
28+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
describe Imports::IssuesController do
4+
let(:patient) { create(:patient) }
5+
6+
describe "PatientLoggingConcern" do
7+
before do
8+
# Ensure the patient appears in import issues
9+
patient.update!(pending_changes: { foo: "bar" })
10+
end
11+
12+
it_behaves_like "a controller that logs the patient ID",
13+
-> do
14+
get :show, params: { id: patient.id, type: "patient" }
15+
end
16+
17+
it_behaves_like "a controller that logs the patient ID",
18+
-> do
19+
patch :update,
20+
params: {
21+
id: patient.id,
22+
type: "patient",
23+
import_duplicate_form: {
24+
apply_changes: true
25+
}
26+
}
27+
end
28+
end
29+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
describe ParentRelationshipsController do
4+
let(:patient) { create(:patient) }
5+
let(:relationship) { create(:parent_relationship, patient:) }
6+
7+
describe "PatientLoggingConcern" do
8+
it_behaves_like "a controller that logs the patient ID",
9+
-> do
10+
get :edit,
11+
params: {
12+
patient_id: patient.id,
13+
id: relationship.parent_id
14+
}
15+
end
16+
17+
it_behaves_like "a controller that logs the patient ID",
18+
-> do
19+
patch :update,
20+
params: {
21+
patient_id: patient.id,
22+
id: relationship.parent_id,
23+
parent_relationship: {
24+
type: relationship.type
25+
}
26+
}
27+
end
28+
end
29+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
describe PatientSessions::ActivitiesController do
4+
let(:session) { create(:session) }
5+
let(:patient) { create(:patient) }
6+
7+
before do
8+
create(
9+
:patient_location,
10+
patient: patient,
11+
location: session.location,
12+
academic_year: session.academic_year
13+
)
14+
end
15+
16+
describe "PatientLoggingConcern" do
17+
it_behaves_like "a controller that logs the patient ID",
18+
-> do
19+
get :show,
20+
params: {
21+
session_slug: session.slug,
22+
patient_id: patient.id
23+
}
24+
end
25+
26+
it_behaves_like "a controller that logs the patient ID",
27+
-> do
28+
post :create,
29+
params: {
30+
session_slug: session.slug,
31+
patient_id: patient.id,
32+
note: {
33+
body: "Hello"
34+
}
35+
}
36+
end
37+
end
38+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
describe Patients::ArchiveController do
4+
let(:patient) { create(:patient) }
5+
6+
describe "PatientLoggingConcern" do
7+
it_behaves_like "a controller that logs the patient ID",
8+
-> { get :new, params: { patient_id: patient.id } }
9+
10+
it_behaves_like "a controller that logs the patient ID",
11+
-> do
12+
post :create,
13+
params: {
14+
patient_id: patient.id,
15+
patient_archive_form: {
16+
nhs_number: patient.nhs_number,
17+
type: "other",
18+
other_details: "duplicate"
19+
}
20+
}
21+
end
22+
end
23+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
describe Patients::EditController do
4+
let(:patient) { create(:patient) }
5+
6+
describe "PatientLoggingConcern" do
7+
it_behaves_like "a controller that logs the patient ID",
8+
-> { get :edit_nhs_number, params: { id: patient.id } }
9+
it_behaves_like "a controller that logs the patient ID",
10+
-> do
11+
put :update_nhs_number,
12+
params: {
13+
id: patient.id,
14+
patient: {
15+
nhs_number: patient.nhs_number
16+
}
17+
}
18+
end
19+
end
20+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
describe PatientsController do
4+
let(:team) { create(:team) }
5+
let(:user) { create(:user, team:) }
6+
let(:session) { create(:session, team:) }
7+
let(:patient) { create(:patient, session:) }
8+
9+
before { allow(controller).to receive(:current_user).and_return(user) }
10+
11+
describe "PatientLoggingConcern" do
12+
it_behaves_like "a controller that logs the patient ID",
13+
-> { get :show, params: { id: patient.id } }
14+
15+
it_behaves_like "a controller that logs the patient ID",
16+
-> { get :log, params: { id: patient.id } }
17+
18+
it_behaves_like "a controller that logs the patient ID",
19+
-> { get :edit, params: { id: patient.id } }
20+
end
21+
end

0 commit comments

Comments
 (0)