Skip to content

Commit 2f6e554

Browse files
committed
Refactor reset organisation test
This changes the test from a feature test to a controller test, mostly to fix what is seemingly a bug where we can't do a feature test is the response data is streamed. Long term, it might make sense for us to have more controller tests as they're lightweight compared to feature tests.
1 parent 73625e3 commit 2f6e554

File tree

3 files changed

+77
-102
lines changed

3 files changed

+77
-102
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# frozen_string_literal: true
2+
3+
describe Dev::ResetOrganisationController do
4+
before { Flipper.enable(:dev_tools) }
5+
after { Flipper.disable(:dev_tools) }
6+
7+
describe "GET" do
8+
let(:programmes) { [create(:programme, :hpv_all_vaccines)] }
9+
10+
let(:organisation) { create(:organisation, ods_code: "R1L", programmes:) }
11+
12+
let(:cohort_import) do
13+
create(
14+
:cohort_import,
15+
csv: fixture_file_upload("spec/fixtures/cohort_import/valid.csv"),
16+
organisation:
17+
)
18+
end
19+
20+
let(:immunisation_import) do
21+
create(
22+
:immunisation_import,
23+
csv:
24+
fixture_file_upload(
25+
"spec/fixtures/immunisation_import/valid_hpv.csv"
26+
),
27+
organisation:
28+
)
29+
end
30+
31+
before do
32+
programmes.each do |programme|
33+
programme.vaccines.each do |vaccine|
34+
create_list(:batch, 4, organisation:, vaccine:)
35+
end
36+
end
37+
38+
create(:school, urn: "123456", organisation:) # to match cohort_import/valid.csv
39+
create(:school, urn: "110158", organisation:) # to match valid_hpv.csv
40+
41+
cohort_import.process!
42+
immunisation_import.process!
43+
44+
Patient.find_each do |patient|
45+
create(:notify_log_entry, :email, patient:, consent_form: nil)
46+
47+
consent_form = create(:consent_form, session: Session.first)
48+
parent =
49+
patient.parents.first || create(:parent_relationship, patient:).parent
50+
create(
51+
:consent,
52+
:given,
53+
patient:,
54+
parent:,
55+
consent_form:,
56+
programme: programmes.first
57+
)
58+
end
59+
60+
create(:school_move, :to_school, patient: Patient.first)
61+
end
62+
63+
it "deletes associated data" do
64+
expect { get :call, params: { organisation_ods_code: "r1l" } }.to(
65+
change(CohortImport, :count)
66+
.by(-1)
67+
.and(change(ImmunisationImport, :count).by(-1))
68+
.and(change(NotifyLogEntry, :count).by(-3))
69+
.and(change(Parent, :count).by(-4))
70+
.and(change(Patient, :count).by(-3))
71+
.and(change(PatientSession, :count).by(-3))
72+
.and(change(VaccinationRecord, :count).by(-11))
73+
)
74+
end
75+
end
76+
end

spec/features/dev_reset_organisation_spec.rb

Lines changed: 0 additions & 102 deletions
This file was deleted.

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
config.include ActiveJob::TestHelper, type: :feature
212212
config.include ActiveSupport::Testing::TimeHelpers
213213
config.include Capybara::RSpecMatchers, type: :component
214+
config.include Devise::Test::ControllerHelpers, type: :controller
214215
config.include Devise::Test::IntegrationHelpers, type: :feature
215216
config.include CIS2AuthHelper, type: :feature
216217
config.include PDSHelper, type: :feature

0 commit comments

Comments
 (0)