Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 108 additions & 2 deletions spec/requests/volunteers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,23 @@
end

describe "PATCH /resend_invitation" do
before { sign_in admin }
it "resends an invitation email as an admin" do
sign_in admin

expect(volunteer.invitation_created_at.present?).to eq(false)

get resend_invitation_volunteer_path(volunteer)
volunteer.reload

expect(volunteer.invitation_created_at.present?).to eq(true)
expect(Devise.mailer.deliveries.count).to eq(1)
expect(Devise.mailer.deliveries.first.subject).to eq(I18n.t("devise.mailer.invitation_instructions.subject"))
expect(response).to redirect_to(edit_volunteer_path(volunteer))
end

it "resends an invitation email as a supervisor" do
sign_in supervisor

it "resends an invitation email" do
expect(volunteer.invitation_created_at.present?).to eq(false)

get resend_invitation_volunteer_path(volunteer)
Expand All @@ -373,6 +387,98 @@
end
end

describe "PATCH /reminder" do
describe "as admin" do
it "emails the volunteer" do
organization = create(:casa_org)
admin = create(:casa_admin, casa_org_id: organization.id)
supervisor = build(:supervisor, casa_org: organization)
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)

sign_in admin

patch reminder_volunteer_path(volunteer)

email = ActionMailer::Base.deliveries.last
expect(email).not_to be_nil
expect(email.to).to eq [volunteer.email]
expect(email.subject).to eq("Reminder to input case contacts")
end

it "cc's their supervisor and admin when the 'with_cc` param is present" do
admin = create(:casa_admin, casa_org_id: organization.id)
supervisor = build(:supervisor, casa_org: organization)
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)

sign_in admin

patch reminder_volunteer_path(volunteer), params: {
with_cc: true
}

email = ActionMailer::Base.deliveries.last
expect(email).not_to be_nil
expect(email.to).to eq [volunteer.email]
expect(email.subject).to eq("Reminder to input case contacts")
expect(email.cc).to include(volunteer.supervisor.email)
expect(email.cc).to include(admin.email)
end
end

describe "as supervisor" do
it "emails the volunteer" do
organization = create(:casa_org)
supervisor = build(:supervisor, casa_org: organization)
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)

sign_in supervisor

patch reminder_volunteer_path(volunteer)

email = ActionMailer::Base.deliveries.last
expect(email).not_to be_nil
expect(email.to).to eq [volunteer.email]
expect(email.subject).to eq("Reminder to input case contacts")
end

it "cc's their supervisor when the 'with_cc` param is present" do
organization = create(:casa_org)
supervisor = build(:supervisor, casa_org: organization)
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)

sign_in supervisor

patch reminder_volunteer_path(volunteer), params: {
with_cc: true
}

email = ActionMailer::Base.deliveries.last
expect(email).not_to be_nil
expect(email.to).to eq [volunteer.email]
expect(email.subject).to eq("Reminder to input case contacts")
expect(email.cc).to eq([supervisor.email])
end
end

it "emails the volunteer without a supervisor" do
organization = create(:casa_org)
volunteer_without_supervisor = create(:volunteer)
supervisor = build(:supervisor, casa_org: organization)

sign_in supervisor

patch reminder_volunteer_path(volunteer_without_supervisor), params: {
with_cc: true
}

email = ActionMailer::Base.deliveries.last
expect(email).not_to be_nil
expect(email.to).to eq [volunteer_without_supervisor.email]
expect(email.subject).to eq("Reminder to input case contacts")
expect(email.cc).to be_empty
end
end

describe "POST /send_reactivation_alert" do
before do
sign_in admin
Expand Down
32 changes: 17 additions & 15 deletions spec/system/volunteers/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,15 @@

fill_in "Email", with: "newemail@example.com"
click_on "Submit"
volunteer.reload

expect(page).to have_text "Volunteer was successfully updated. Confirmation Email Sent."
expect(page).to have_field("Email", with: old_email)
expect(volunteer.reload.unconfirmed_email).to eq("newemail@example.com")

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first).to be_a(Mail::Message)
expect(ActionMailer::Base.deliveries.first.body.encoded)
.to match("Click here to confirm your email")

expect(page).to have_text "Volunteer was successfully updated. Confirmation Email Sent."
expect(page).to have_field("Email", with: old_email)
expect(volunteer.unconfirmed_email).to eq("newemail@example.com")
end

it "succesfully displays the new email once the user confirms" do
Expand Down Expand Up @@ -233,7 +232,7 @@
it "shows the admin the option to assign an unassigned volunteer to a different active supervisor" do
organization = create(:casa_org)
volunteer = create(:volunteer, casa_org: organization)
deactivated_supervisor = create(:supervisor, active: false, casa_org: organization, display_name: "Inactive Supervisor")
deactivated_supervisor = build(:supervisor, active: false, casa_org: organization, display_name: "Inactive Supervisor")
active_supervisor = create(:supervisor, active: true, casa_org: organization, display_name: "Active Supervisor")
admin = create(:casa_admin, casa_org: organization)

Expand Down Expand Up @@ -295,8 +294,8 @@
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org_id: organization.id)
casa_case_1 = create(:casa_case, casa_org: organization, case_number: "CINA1")
casa_case_2 = create(:casa_case, casa_org: organization, case_number: "CINA2")
case_assignment_1 = create(:case_assignment, volunteer: volunteer, casa_case: casa_case_1)
case_assignment_2 = create(:case_assignment, volunteer: volunteer, casa_case: casa_case_2)
case_assignment_1 = build(:case_assignment, volunteer: volunteer, casa_case: casa_case_1)
case_assignment_2 = build(:case_assignment, volunteer: volunteer, casa_case: casa_case_2)

case_assignment_1.active = false
case_assignment_2.active = false
Expand Down Expand Up @@ -481,6 +480,8 @@
uncheck "with_cc"
click_on "Send Reminder"

expect(page).to have_content("Reminder sent to volunteer")

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first.cc).to be_empty
end
Expand All @@ -496,6 +497,8 @@
check "with_cc"
click_on "Send Reminder"

expect(page).to have_content("Reminder sent to volunteer")

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first.cc).to include(volunteer.supervisor.email)
end
Expand All @@ -511,6 +514,8 @@
check "with_cc"
click_on "Send Reminder"

expect(page).to have_content("Reminder sent to volunteer")

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first.cc).to be_empty
end
Expand All @@ -530,6 +535,8 @@

click_on "Send Reminder"

expect(page).to have_content("Reminder sent to volunteer")

expect(ActionMailer::Base.deliveries.count).to eq(1)
end

Expand All @@ -543,6 +550,8 @@
check "with_cc"
click_on "Send Reminder"

expect(page).to have_content("Reminder sent to volunteer")

expect(ActionMailer::Base.deliveries.count).to eq(1)
expect(ActionMailer::Base.deliveries.first.cc).to include(volunteer.supervisor.email)
expect(ActionMailer::Base.deliveries.first.cc).to include(admin.email)
Expand Down Expand Up @@ -608,9 +617,6 @@
organization = create(:casa_org)
admin = create(:casa_admin, casa_org_id: organization.id)
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org_id: organization.id)
volunteer.notes.create(creator: admin, content: "Note_1")
volunteer.notes.create(creator: admin, content: "Note_2")
volunteer.notes.create(creator: admin, content: "Note_3")

sign_in admin
visit edit_volunteer_path(volunteer)
Expand Down Expand Up @@ -653,12 +659,8 @@
context "logged in as a supervisor" do
it "can save notes about a volunteer" do
organization = create(:casa_org)
admin = create(:casa_admin, casa_org_id: organization.id)
volunteer = create(:volunteer, :with_assigned_supervisor, casa_org_id: organization.id)
supervisor = volunteer.supervisor
volunteer.notes.create(creator: admin, content: "Note_1")
volunteer.notes.create(creator: admin, content: "Note_2")
volunteer.notes.create(creator: admin, content: "Note_3")

sign_in supervisor
visit edit_volunteer_path(volunteer)
Expand Down
2 changes: 1 addition & 1 deletion spec/system/volunteers/notes/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe "volunteers/notes/edit", type: :system do
let(:organization) { create(:casa_org) }
let(:admin) { create(:casa_admin, casa_org_id: organization.id) }
let(:admin) { build(:casa_admin, casa_org_id: organization.id) }
let(:volunteer) { create(:volunteer, :with_assigned_supervisor, casa_org_id: organization.id) }
let(:note) { volunteer.notes.create(creator: admin, content: "Good job.") }

Expand Down
Loading