Skip to content

Commit

Permalink
reminders now supports reverse soft delete
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Dec 6, 2024
1 parent 93b8087 commit 4b09496
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/forms/reminders/email_verification_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def save!
journey_class: journey.to_s
)

reminder.update!(deleted_at: nil)

ReminderMailer.reminder_set(reminder).deliver_now
end

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/forms/reminders/personal_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions spec/forms/reminders/email_verification_form_spec.rb
Original file line number Diff line number Diff line change
@@ -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: "[email protected]"
}
)
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: "[email protected]",
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
43 changes: 43 additions & 0 deletions spec/forms/reminders/personal_details_form_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b09496

Please sign in to comment.