Skip to content

Commit 4ec434f

Browse files
committed
WIP failing bad spec
1 parent 62186d8 commit 4ec434f

File tree

1 file changed

+77
-9
lines changed

1 file changed

+77
-9
lines changed

spec/requests/case_contacts_spec.rb

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
require "rails_helper"
22
# hi
33
RSpec.describe "/case_contacts", type: :request do
4-
let(:organization) { build(:casa_org) }
4+
let(:organization) { create(:casa_org) }
55
let(:admin) { create(:casa_admin, casa_org: organization) }
66
let(:volunteer) { create(:volunteer, casa_org: organization) }
7+
let(:supervisor) { create(:supervisor, casa_org: organization) }
8+
let(:casa_case) { create(:casa_case, casa_org: organization) }
79

810
before { sign_in admin }
911

@@ -14,7 +16,6 @@
1416
response
1517
end
1618

17-
let!(:casa_case) { create(:casa_case, casa_org: organization) }
1819
let!(:past_contact) { create(:case_contact, casa_case: casa_case, occurred_at: 3.weeks.ago) }
1920
let!(:recent_contact) { create(:case_contact, casa_case: casa_case, occurred_at: 3.days.ago) }
2021
let(:filterrific) { {} }
@@ -30,28 +31,47 @@
3031
context "with filters applied" do
3132
let(:filterrific) { {occurred_starting_at: 1.week.ago} }
3233

33-
it "returns all case contacts" do
34+
it "returns filtered case contacts" do
3435
page = request.parsed_body.to_html
3536
expect(page).to include(recent_contact.creator.display_name)
3637
expect(page).not_to include(past_contact.creator.display_name)
3738
end
3839
end
39-
end
4040

41+
context "with sorting" do
42+
let(:filterrific) { {sorted_by: "occurred_at_desc"} }
43+
44+
it "returns sorted case contacts" do
45+
page = request.parsed_body.to_html
46+
expect(page).to include(recent_contact.creator.display_name)
47+
expect(page).to include(past_contact.creator.display_name)
48+
end
49+
end
50+
end
4151

4252
context "when logged in as a volunteer" do
4353
let(:assigned_case) { create(:casa_case, :with_one_case_assignment, casa_org: organization) }
4454
let(:unassigned_case) { casa_case }
4555
let(:volunteer) { assigned_case.assigned_volunteers.first }
4656
let!(:assigned_case_contact) { create(:case_contact, casa_case: assigned_case, creator: volunteer) }
47-
let!(:unassigned_case_contact) { create(:case_contact, casa_case: unassigned_case, creator: volunteer, duration_minutes: 180) }
57+
let!(:unassigned_case_contact) { create(:case_contact, casa_case: unassigned_case, creator: volunteer) }
4858

4959
before { sign_in volunteer }
5060

5161
it "returns only currently assigned cases" do
5262
page = request.parsed_body.to_html
53-
expect(page).to include("60 minutes")
54-
expect(page).not_to include("3 hours")
63+
binding.pry
64+
expect(page).to include(assigned_case_contact.creator.display_name)
65+
expect(page).not_to include(unassigned_case_contact.creator.display_name)
66+
end
67+
end
68+
69+
context "when logged in as a supervisor" do
70+
before { sign_in supervisor }
71+
72+
it "returns all case contacts" do
73+
page = request.parsed_body.to_html
74+
expect(page).to include(past_contact.creator.display_name, recent_contact.creator.display_name)
5575
end
5676
end
5777
end
@@ -86,6 +106,15 @@
86106
expect(CaseContact.started.last.contact_topic_answers).to be_empty
87107
end
88108
end
109+
110+
context "with draft case ids" do
111+
let(:draft_case_ids) { [casa_case.id] }
112+
113+
it "creates case contact with draft case ids" do
114+
get new_case_contact_path(draft_case_ids: draft_case_ids)
115+
expect(CaseContact.last.draft_case_ids).to eq(draft_case_ids)
116+
end
117+
end
89118
end
90119

91120
describe "GET /edit" do
@@ -103,6 +132,16 @@
103132
request
104133
expect(response).to redirect_to(case_contact_form_path(:details, case_contact_id: case_contact.id))
105134
end
135+
136+
context "when user is not authorized" do
137+
let(:unauthorized_volunteer) { create(:volunteer, casa_org: organization) }
138+
before { sign_in unauthorized_volunteer }
139+
140+
it "redirects to root path" do
141+
request
142+
expect(response).to redirect_to(authenticated_user_root_path)
143+
end
144+
end
106145
end
107146

108147
describe "GET /drafts" do
@@ -112,8 +151,17 @@
112151
response
113152
end
114153

154+
let!(:draft_contact) { create(:case_contact, status: "started") }
155+
let!(:active_contact) { create(:case_contact, status: "active") }
156+
115157
it { is_expected.to have_http_status(:success) }
116158

159+
it "returns only draft contacts" do
160+
page = request.parsed_body.to_html
161+
expect(page).to include(draft_contact.creator.display_name)
162+
expect(page).not_to include(active_contact.creator.display_name)
163+
end
164+
117165
context "when user is volunteer" do
118166
before { sign_in volunteer }
119167

@@ -140,9 +188,19 @@
140188
it "soft deletes the case_contact" do
141189
expect { request }.to change { case_contact.reload.deleted? }.from(false).to(true)
142190
end
191+
192+
context "when user is not authorized" do
193+
let(:unauthorized_volunteer) { create(:volunteer, casa_org: organization) }
194+
before { sign_in unauthorized_volunteer }
195+
196+
it "redirects to root path" do
197+
request
198+
expect(response).to redirect_to(authenticated_user_root_path)
199+
end
200+
end
143201
end
144202

145-
describe "GET /restore" do
203+
describe "POST /restore" do
146204
subject(:request) do
147205
post restore_case_contact_path(case_contact), headers: {HTTP_REFERER: case_contacts_path}
148206

@@ -160,9 +218,19 @@
160218
expect(flash[:notice]).to eq("Contact is successfully restored.")
161219
end
162220

163-
it "soft deletes the case_contact" do
221+
it "restores the case_contact" do
164222
expect { request }.to change { case_contact.reload.deleted? }.from(true).to(false)
165223
end
224+
225+
context "when user is not authorized" do
226+
let(:unauthorized_volunteer) { create(:volunteer, casa_org: organization) }
227+
before { sign_in unauthorized_volunteer }
228+
229+
it "redirects to root path" do
230+
request
231+
expect(response).to redirect_to(authenticated_user_root_path)
232+
end
233+
end
166234
end
167235

168236
xdescribe "GET /leave" do

0 commit comments

Comments
 (0)