Skip to content

Commit caaff39

Browse files
stefannibrasilcompwron
authored andcommitted
Add coverage for Followups and Mileages reports
Followup report handle CSV exports with authorization and the Mileage report handles Reimbursement CSV exports. Both have placeholder specs only. Let's add coverage to ensure they work as expected and no bugs are introduced. The services that generate the report data have extensive coverage already, so keep this unit test focused on the request, I only tested for the format and the headers.
1 parent 851785c commit caaff39

6 files changed

Lines changed: 108 additions & 14 deletions

File tree

app/controllers/followup_reports_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class FollowupReportsController < ApplicationController
24
after_action :verify_authorized
35

app/controllers/mileage_reports_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require "csv"
24

35
class MileageReportsController < ApplicationController

spec/controllers/followup_reports_controller_spec.rb

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

spec/controllers/mileage_reports_controller_spec.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe "FollowupReports", type: :request do
6+
describe "GET /index" do
7+
context "when the user has access" do
8+
let(:admin) { build(:casa_admin) }
9+
10+
it "returns the CSV report" do
11+
sign_in admin
12+
13+
get followup_reports_path(format: :csv)
14+
15+
expect(response).to have_http_status(:success)
16+
expect(response.header["Content-Type"]).to eq("text/csv")
17+
expect(response.headers["Content-Disposition"]).to(
18+
match("followup-report-#{Time.current.strftime("%Y-%m-%d")}.csv")
19+
)
20+
end
21+
22+
it "adds the correct headers to the csv" do
23+
sign_in admin
24+
25+
get followup_reports_path(format: :csv)
26+
27+
csv_headers = [
28+
"Case Number",
29+
"Volunteer Name(s)",
30+
"Note Creator Name",
31+
"Note"
32+
]
33+
34+
csv_headers.each { |header| expect(response.body).to include(header) }
35+
end
36+
end
37+
38+
context "when the user is not authorized to access" do
39+
it "redirects to root and displays an unauthorized message" do
40+
volunteer = build(:volunteer)
41+
sign_in volunteer
42+
43+
get followup_reports_path(format: :csv)
44+
45+
expect(response).to redirect_to root_path
46+
expect(response.request.flash[:notice]).to eq "Sorry, you are not authorized to perform this action."
47+
end
48+
end
49+
end
50+
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe "MileageReports", type: :request do
6+
describe "GET /index" do
7+
context "when the user has access" do
8+
let(:admin) { build(:casa_admin) }
9+
10+
it "returns the CSV report" do
11+
sign_in admin
12+
13+
get mileage_reports_path(format: :csv)
14+
15+
expect(response).to have_http_status(:success)
16+
expect(response.header["Content-Type"]).to eq("text/csv")
17+
expect(response.headers["Content-Disposition"]).to(
18+
match("mileage-report-#{Time.current.strftime("%Y-%m-%d")}.csv")
19+
)
20+
end
21+
22+
it "adds the correct headers to the csv" do
23+
sign_in admin
24+
25+
get mileage_reports_path(format: :csv)
26+
27+
csv_headers = [
28+
"Contact Types",
29+
"Occurred At",
30+
"Miles Driven",
31+
"Casa Case Number",
32+
"Creator Name",
33+
"Supervisor Name",
34+
"Volunteer Address",
35+
"Reimbursed"
36+
]
37+
38+
csv_headers.each { |header| expect(response.body).to include(header) }
39+
end
40+
end
41+
42+
context "when the user is not authorized to access" do
43+
it "redirects to root and displays an unauthorized message" do
44+
volunteer = build(:volunteer)
45+
sign_in volunteer
46+
47+
get mileage_reports_path(format: :csv)
48+
49+
expect(response).to redirect_to root_path
50+
expect(response.request.flash[:notice]).to eq "Sorry, you are not authorized to perform this action."
51+
end
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)