Skip to content

Commit

Permalink
Fix NoMethodError and ActiveRecord::RecordInvalid issues reported by …
Browse files Browse the repository at this point in the history
…Sentry
  • Loading branch information
mandanakhademi committed Mar 14, 2024
1 parent ec9a3bd commit 901073e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/controllers/token_based_resume_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ class TokenBasedResumeController < ApplicationController
add_flash_types :error

def session_expired
send_email
@application = UnaccompaniedMinor.find_by_reference(session[:app_reference])

if @application && !@application.email.blank?
send_email
else
Rails.logger.info "User hasn't created any account yet and the session has timed out due to inactivity."
end

reset_session
render "token-based-resume/session_expired"
end
Expand Down
39 changes: 39 additions & 0 deletions spec/controllers/token_based_resume_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,45 @@
end
end

describe "User session times out before creating an account" do

given_name = "".freeze
email = nil

uam = UnaccompaniedMinor.new
uam.save!

uuid = "test-uuid".freeze
magic_link = "http://test.host/sponsor-a-child/resume-application?uuid=#{uuid}".freeze

let(:unaccompanied_minor) { instance_double("UnaccompaniedMinor") }
let(:message_delivery) { instance_double("ActionMailer::MessageDelivery") }

before do
allow(SecureRandom).to receive(:uuid).and_return(uuid)
allow(GovNotifyMailer).to receive(:send_save_and_return_email).and_return(message_delivery)
allow(message_delivery).to receive(:deliver_later)
allow(UnaccompaniedMinor).to receive(:find_by_reference).and_return(uam)
end

it "dosn't call the emailer" do
get :session_expired

expect(GovNotifyMailer).not_to have_received(:send_save_and_return_email).with(given_name, magic_link, email)
expect(response).to render_template("token-based-resume/session_expired")
end

it "Rails logger receives a message" do
allow(Rails.logger).to receive(:info)

get :session_expired

expect(Rails.logger).to have_received(:info).with("User hasn't created any account yet and the session has timed out due to inactivity.")
end


end

describe "User tries to resume their application after email sent" do
given_name = "First".freeze
email = "test@example.com".freeze
Expand Down
17 changes: 17 additions & 0 deletions spec/system/token_based_resume_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
require "rails_helper"

RSpec.describe TokenBasedResumeController, type: :system do

describe "User hasn't created an account and has been timed out" do
let(:email) { nil }

it "shows time out page if user refresh time out page" do
new_application = UnaccompaniedMinor.new
new_application.save!

page.set_rack_session(app_reference: new_application.reference)

visit "/sponsor-a-child/session-expired"
visit current_path

expect(page).to have_content("Your session has timed out due to inactivity")
end
end

let(:texter) { instance_double("Notifications::Client") }
let(:application_token) { instance_double("ApplicationToken") }
let(:task_list_content) { "Apply for approval to provide a safe home for a child from Ukraine" }
Expand Down

0 comments on commit 901073e

Please sign in to comment.