|
86 | 86 | end |
87 | 87 | end |
88 | 88 |
|
| 89 | + context "when the case belongs to someone else's caseload" do |
| 90 | + let(:other_case) { create(:casa_case, casa_org: volunteer.casa_org, case_number: "CINA-OTHER-1") } |
| 91 | + |
| 92 | + before do |
| 93 | + other_case.court_reports.attach(io: StringIO.new("secret"), filename: "stored-report.docx") |
| 94 | + end |
| 95 | + |
| 96 | + it "does not send an unassigned volunteer the stored report, and looks the same as a missing case", :aggregate_failures do |
| 97 | + get case_court_report_path(other_case.case_number, format: "docx") |
| 98 | + |
| 99 | + expect(response).to redirect_to(case_court_reports_path) |
| 100 | + expect(response.body).not_to include("secret") |
| 101 | + expect(flash[:alert]).to eq "Report #{other_case.case_number} is not found." |
| 102 | + end |
| 103 | + |
| 104 | + it "does not send a volunteer whose assignment was deactivated" do |
| 105 | + create(:case_assignment, casa_case: other_case, volunteer: volunteer, active: false) |
| 106 | + |
| 107 | + get case_court_report_path(other_case.case_number, format: "docx") |
| 108 | + |
| 109 | + expect(response).to redirect_to(case_court_reports_path) |
| 110 | + end |
| 111 | + |
| 112 | + it "still sends a supervisor in the same org the stored report" do |
| 113 | + sign_in create(:supervisor, casa_org: volunteer.casa_org) |
| 114 | + |
| 115 | + get case_court_report_path(other_case.case_number, format: "docx") |
| 116 | + |
| 117 | + expect(response).to have_http_status(:ok) |
| 118 | + end |
| 119 | + |
| 120 | + it "does not send a supervisor from another org the stored report" do |
| 121 | + sign_in create(:supervisor, casa_org: create(:casa_org)) |
| 122 | + |
| 123 | + get case_court_report_path(other_case.case_number, format: "docx") |
| 124 | + |
| 125 | + expect(response).to redirect_to(case_court_reports_path) |
| 126 | + end |
| 127 | + end |
| 128 | + |
89 | 129 | context "when an INVALID / non-existing case is sent" do |
90 | 130 | let(:invalid_casa_case) { build_stubbed(:casa_case) } |
91 | 131 |
|
|
143 | 183 | expect(request).to have_http_status(:ok) |
144 | 184 | end |
145 | 185 |
|
| 186 | + context "when the case is not on the volunteer's caseload" do |
| 187 | + let(:other_case) { create(:casa_case, casa_org: volunteer.casa_org, case_number: "CINA-OTHER-2") } |
| 188 | + let(:missing_params) { {case_court_report: {case_number: "NO-SUCH-CASE", start_date: "January 1, 2020", end_date: "January 1, 2021"}} } |
| 189 | + let(:params) { {case_court_report: {case_number: other_case.case_number, start_date: "January 1, 2020", end_date: "January 1, 2021"}} } |
| 190 | + |
| 191 | + it "does not generate or store a report, and answers exactly like an unknown case number", :aggregate_failures do |
| 192 | + expect { request }.not_to change { other_case.court_reports.count } |
| 193 | + not_yours_status = response.status |
| 194 | + not_yours_body = response.parsed_body.slice("link", "status") |
| 195 | + |
| 196 | + post generate_case_court_reports_path, params: missing_params, headers: {ACCEPT: "application/json"} |
| 197 | + |
| 198 | + expect(response.status).to eq not_yours_status |
| 199 | + expect(response.parsed_body.slice("link", "status")).to eq not_yours_body |
| 200 | + expect(not_yours_status).to eq 404 |
| 201 | + end |
| 202 | + |
| 203 | + it "does not let a previously unassigned volunteer replace the case's latest report" do |
| 204 | + create(:case_assignment, casa_case: other_case, volunteer: volunteer, active: false) |
| 205 | + |
| 206 | + expect { request }.not_to change { other_case.court_reports.count } |
| 207 | + expect(response).to have_http_status(:not_found) |
| 208 | + end |
| 209 | + end |
| 210 | + |
146 | 211 | context "when no custom template is set" do |
147 | 212 | it "sends response as a JSON string", :aggregate_failures do |
148 | 213 | expect(request.content_type).to eq("application/json; charset=utf-8") |
|
0 commit comments