Skip to content

Commit ea5e14a

Browse files
add unit tests for resend invitation and reminder for volunteers
1 parent 52baa44 commit ea5e14a

1 file changed

Lines changed: 108 additions & 2 deletions

File tree

spec/requests/volunteers_spec.rb

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,23 @@
358358
end
359359

360360
describe "PATCH /resend_invitation" do
361-
before { sign_in admin }
361+
it "resends an invitation email as an admin" do
362+
sign_in admin
363+
364+
expect(volunteer.invitation_created_at.present?).to eq(false)
365+
366+
get resend_invitation_volunteer_path(volunteer)
367+
volunteer.reload
368+
369+
expect(volunteer.invitation_created_at.present?).to eq(true)
370+
expect(Devise.mailer.deliveries.count).to eq(1)
371+
expect(Devise.mailer.deliveries.first.subject).to eq(I18n.t("devise.mailer.invitation_instructions.subject"))
372+
expect(response).to redirect_to(edit_volunteer_path(volunteer))
373+
end
374+
375+
it "resends an invitation email as a supervisor" do
376+
sign_in supervisor
362377

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

366380
get resend_invitation_volunteer_path(volunteer)
@@ -373,6 +387,98 @@
373387
end
374388
end
375389

390+
describe "PATCH /reminder" do
391+
describe "as admin" do
392+
it "emails the volunteer" do
393+
organization = create(:casa_org)
394+
admin = create(:casa_admin, casa_org_id: organization.id)
395+
supervisor = build(:supervisor, casa_org: organization)
396+
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)
397+
398+
sign_in admin
399+
400+
patch reminder_volunteer_path(volunteer)
401+
402+
email = ActionMailer::Base.deliveries.last
403+
expect(email).not_to be_nil
404+
expect(email.to).to eq [volunteer.email]
405+
expect(email.subject).to eq("Reminder to input case contacts")
406+
end
407+
408+
it "cc's their supervisor and admin when the 'with_cc` param is present" do
409+
admin = create(:casa_admin, casa_org_id: organization.id)
410+
supervisor = build(:supervisor, casa_org: organization)
411+
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)
412+
413+
sign_in admin
414+
415+
patch reminder_volunteer_path(volunteer), params: {
416+
with_cc: true
417+
}
418+
419+
email = ActionMailer::Base.deliveries.last
420+
expect(email).not_to be_nil
421+
expect(email.to).to eq [volunteer.email]
422+
expect(email.subject).to eq("Reminder to input case contacts")
423+
expect(email.cc).to include(volunteer.supervisor.email)
424+
expect(email.cc).to include(admin.email)
425+
end
426+
end
427+
428+
describe "as supervisor" do
429+
it "emails the volunteer" do
430+
organization = create(:casa_org)
431+
supervisor = build(:supervisor, casa_org: organization)
432+
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)
433+
434+
sign_in supervisor
435+
436+
patch reminder_volunteer_path(volunteer)
437+
438+
email = ActionMailer::Base.deliveries.last
439+
expect(email).not_to be_nil
440+
expect(email.to).to eq [volunteer.email]
441+
expect(email.subject).to eq("Reminder to input case contacts")
442+
end
443+
444+
it "cc's their supervisor when the 'with_cc` param is present" do
445+
organization = create(:casa_org)
446+
supervisor = build(:supervisor, casa_org: organization)
447+
volunteer = create(:volunteer, supervisor: supervisor, casa_org_id: organization.id)
448+
449+
sign_in supervisor
450+
451+
patch reminder_volunteer_path(volunteer), params: {
452+
with_cc: true
453+
}
454+
455+
email = ActionMailer::Base.deliveries.last
456+
expect(email).not_to be_nil
457+
expect(email.to).to eq [volunteer.email]
458+
expect(email.subject).to eq("Reminder to input case contacts")
459+
expect(email.cc).to eq([supervisor.email])
460+
end
461+
end
462+
463+
it "emails the volunteer without a supervisor" do
464+
organization = create(:casa_org)
465+
volunteer_without_supervisor = create(:volunteer)
466+
supervisor = build(:supervisor, casa_org: organization)
467+
468+
sign_in supervisor
469+
470+
patch reminder_volunteer_path(volunteer_without_supervisor), params: {
471+
with_cc: true
472+
}
473+
474+
email = ActionMailer::Base.deliveries.last
475+
expect(email).not_to be_nil
476+
expect(email.to).to eq [volunteer_without_supervisor.email]
477+
expect(email.subject).to eq("Reminder to input case contacts")
478+
expect(email.cc).to be_empty
479+
end
480+
end
481+
376482
describe "POST /send_reactivation_alert" do
377483
before do
378484
sign_in admin

0 commit comments

Comments
 (0)