|
358 | 358 | end |
359 | 359 |
|
360 | 360 | 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 |
362 | 377 |
|
363 | | - it "resends an invitation email" do |
364 | 378 | expect(volunteer.invitation_created_at.present?).to eq(false) |
365 | 379 |
|
366 | 380 | get resend_invitation_volunteer_path(volunteer) |
|
373 | 387 | end |
374 | 388 | end |
375 | 389 |
|
| 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 | + |
376 | 482 | describe "POST /send_reactivation_alert" do |
377 | 483 | before do |
378 | 484 | sign_in admin |
|
0 commit comments