diff --git a/app/forms/reminders/email_verification_form.rb b/app/forms/reminders/email_verification_form.rb index 9fa29889a3..1fa86eaaef 100644 --- a/app/forms/reminders/email_verification_form.rb +++ b/app/forms/reminders/email_verification_form.rb @@ -25,6 +25,8 @@ def save! journey_class: journey.to_s ) + reminder.update!(deleted_at: nil) + ReminderMailer.reminder_set(reminder).deliver_now end @@ -34,7 +36,9 @@ def set_reminder_from_claim private def itt_subject - journey_session.answers.eligible_itt_subject + if journey_session.answers.respond_to?(:eligible_itt_subject) + journey_session.answers.eligible_itt_subject + end end def next_academic_year diff --git a/app/forms/reminders/personal_details_form.rb b/app/forms/reminders/personal_details_form.rb index f6dd71a987..d5b70d29d2 100644 --- a/app/forms/reminders/personal_details_form.rb +++ b/app/forms/reminders/personal_details_form.rb @@ -53,6 +53,8 @@ def set_reminder_from_claim journey_class: journey.to_s ) + reminder.update!(deleted_at: nil) + ReminderMailer.reminder_set(reminder).deliver_now else false diff --git a/spec/forms/reminders/email_verification_form_spec.rb b/spec/forms/reminders/email_verification_form_spec.rb new file mode 100644 index 0000000000..1d773408c5 --- /dev/null +++ b/spec/forms/reminders/email_verification_form_spec.rb @@ -0,0 +1,56 @@ +require "rails_helper" + +RSpec.describe Reminders::EmailVerificationForm do + let!(:journey_configuration) do + create(:journey_configuration, :further_education_payments) + end + + let(:journey) { Journeys::FurtherEducationPayments } + let(:journey_session) do + create( + :further_education_payments_session, + answers: { + reminder_full_name: "John Doe", + reminder_email_address: "john.doe@example.com" + } + ) + end + + subject do + described_class.new( + journey_session:, + journey:, + params: ActionController::Parameters.new, + session: {} + ) + end + + describe "#save!" do + let(:fake_passing_validator) { OpenStruct.new(valid?: true) } + + before do + allow(OneTimePassword::Validator).to receive(:new).and_return(fake_passing_validator) + end + + context "when reminder previously soft deleted" do + let!(:reminder) do + create( + :reminder, + :soft_deleted, + full_name: "John Doe", + email_address: "john.doe@example.com", + email_verified: true, + itt_subject: nil, + itt_academic_year: journey_configuration.current_academic_year.succ, + journey_class: journey.to_s + ) + end + + it "becomes undeleted" do + expect { + subject.save! + }.to change { reminder.reload.deleted_at }.to(nil) + end + end + end +end diff --git a/spec/forms/reminders/personal_details_form_spec.rb b/spec/forms/reminders/personal_details_form_spec.rb new file mode 100644 index 0000000000..f3da958ac6 --- /dev/null +++ b/spec/forms/reminders/personal_details_form_spec.rb @@ -0,0 +1,43 @@ +require "rails_helper" + +RSpec.describe Reminders::PersonalDetailsForm do + let!(:journey_configuration) do + create(:journey_configuration, :further_education_payments) + end + + let(:journey) { Journeys::FurtherEducationPayments } + let(:journey_session) { create(:further_education_payments_session) } + let(:claim) { create(:claim, :submitted) } + + subject do + described_class.new( + journey_session:, + journey:, + params: ActionController::Parameters.new, + session: {"submitted_claim_id" => claim.id} + ) + end + + describe "#set_reminder_from_claim" do + context "when reminder previously soft deleted" do + let!(:reminder) do + create( + :reminder, + :soft_deleted, + full_name: claim.full_name, + email_address: claim.email_address, + email_verified: true, + itt_subject: claim.eligible_itt_subject, + itt_academic_year: journey_configuration.current_academic_year.succ, + journey_class: journey.to_s + ) + end + + it "becomes undeleted" do + expect { + subject.set_reminder_from_claim + }.to change { reminder.reload.deleted_at }.to(nil) + end + end + end +end