Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Proebstel committed Feb 25, 2025
1 parent 44287ed commit 1a8bf33
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 244 deletions.
4 changes: 1 addition & 3 deletions app/models/state_file_archived_intake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def address_challenge_set

private

private

# this is here because we don't want people to get new fake addresses if they refresh the page or return with a new session
def populate_fake_addresses
self.fake_address_1, self.fake_address_2 = fetch_random_addresses
Expand All @@ -65,7 +63,7 @@ def fetch_random_addresses
else
bucket = select_bucket

file_key = Rails.env.production? ? "#{state_file_archived_intake.mailing_state.downcase}_addresses.csv" : 'non_prod_addresses.csv'
file_key = Rails.env.production? ? "#{mailing_state.downcase}_addresses.csv" : 'non_prod_addresses.csv'

file_path = File.join(Rails.root, "tmp", File.basename(file_key))

Expand Down
23 changes: 23 additions & 0 deletions lib/tasks/populate_fake_addresses.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace :state_file do
desc "Populate fake addresses for existing StateFileArchivedIntake records"
task populate_fake_addresses: :environment do
missing_addresses = StateFileArchivedIntake.where(fake_address_1: nil).or(StateFileArchivedIntake.where(fake_address_2: nil))

if missing_addresses.any?
puts "Updating #{missing_addresses.count} records with fake addresses..."

missing_addresses.find_each do |intake|
intake.send(:populate_fake_addresses) # Calls private method
if intake.save
puts "Updated intake ID #{intake.id}"
else
puts "Failed to update intake ID #{intake.id}: #{intake.errors.full_messages.join(', ')}"
end
end

puts "Fake address population complete."
else
puts "No records need updating."
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -47,79 +47,79 @@
expect(result.event_type).to eq event_type
expect(result.state_file_archived_intake).to eq archived_intake
end
end

describe '#check_feature_flag' do
context 'when the feature flag is enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:get_your_pdf).and_return(true)
end
describe '#check_feature_flag' do
context 'when the feature flag is enabled' do
before do
allow(Flipper).to receive(:enabled?).with(:get_your_pdf).and_return(true)
end

it 'does not redirect' do
expect(controller).not_to receive(:redirect_to)
controller.check_feature_flag
end
it 'does not redirect' do
expect(controller).not_to receive(:redirect_to)
controller.check_feature_flag
end
end

context 'when the feature flag is disabled' do
before do
allow(Flipper).to receive(:enabled?).with(:get_your_pdf).and_return(false)
end
context 'when the feature flag is disabled' do
before do
allow(Flipper).to receive(:enabled?).with(:get_your_pdf).and_return(false)
end

it 'redirects to the root path' do
expect(controller).to receive(:redirect_to).with(root_path)
controller.check_feature_flag
end
it 'redirects to the root path' do
expect(controller).to receive(:redirect_to).with(root_path)
controller.check_feature_flag
end
end
end

describe '#is_intake_locked' do
before do
allow(controller).to receive(:current_archived_intake).and_return(archived_intake)
end

describe '#is_intake_locked' do
context 'when the request is nil' do
before do
allow(controller).to receive(:current_archived_intake).and_return(archived_intake)
allow(controller).to receive(:current_archived_intake).and_return(nil)
end

context 'when the request is nil' do
before do
allow(controller).to receive(:current_archived_intake).and_return(nil)
end

it 'redirects to verification error page' do
expect(controller).to receive(:redirect_to).with(state_file_archived_intakes_verification_error_path)
controller.is_request_locked
end
it 'redirects to verification error page' do
expect(controller).to receive(:redirect_to).with(state_file_archived_intakes_verification_error_path)
controller.is_intake_locked
end
end

context 'when the request is locked' do
before do
allow(archived_intake).to receive(:access_locked?).and_return(true)
end
context 'when the request is locked' do
before do
allow(archived_intake).to receive(:access_locked?).and_return(true)
end

it 'redirects to verification error page' do
expect(controller).to receive(:redirect_to).with(state_file_archived_intakes_verification_error_path)
controller.is_request_locked
end
it 'redirects to verification error page' do
expect(controller).to receive(:redirect_to).with(state_file_archived_intakes_verification_error_path)
controller.is_intake_locked
end
end

context 'when the archived intake is permanently locked' do
before do
allow(archived_intake).to receive(:permanently_locked_at).and_return(Time.current)
end
context 'when the archived intake is permanently locked' do
before do
allow(archived_intake).to receive(:permanently_locked_at).and_return(Time.current)
end

it 'redirects to verification error page' do
expect(controller).to receive(:redirect_to).with(state_file_archived_intakes_verification_error_path)
controller.is_request_locked
end
it 'redirects to verification error page' do
expect(controller).to receive(:redirect_to).with(state_file_archived_intakes_verification_error_path)
controller.is_intake_locked
end
end

context 'when the request is valid and not locked' do
before do
allow(archived_intake).to receive(:access_locked?).and_return(false)
allow(archived_intake).to receive(:permanently_locked_at).and_return(nil)
end
context 'when the request is valid and not locked' do
before do
allow(archived_intake).to receive(:access_locked?).and_return(false)
allow(archived_intake).to receive(:permanently_locked_at).and_return(nil)
end

it 'does not redirect' do
expect(controller).not_to receive(:redirect_to)
controller.is_request_locked
end
it 'does not redirect' do
expect(controller).not_to receive(:redirect_to)
controller.is_intake_locked
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

before do
Flipper.enable(:get_your_pdf)
allow(controller).to receive(:current_request).and_return(current_request)
allow(controller).to receive(:current_archived_intake).and_return(archived_intake)
allow(I18n).to receive(:locale).and_return(:en)
session[:email_address] = true
session[:code_verified] = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
let(:intake_ssn) { "123456789" }
let(:hashed_ssn) { SsnHashingService.hash(intake_ssn) }
let(:input_ssn) { "1234" }
let(:archived_intake) {
let(:state_file_archived_intake) {
build(:state_file_archived_intake, hashed_ssn: hashed_ssn)
}
let(:state_file_archived_intake_request) { build(:state_file_archived_intake_request, state_file_archived_intake: archived_intake) }
let(:form) { described_class.new(state_file_archived_intake_request, {ssn: input_ssn}) }

let(:form) { described_class.new(state_file_archived_intake, {ssn: input_ssn}) }

describe "validations" do
context "with an input that does not look like an ssn" do
Expand All @@ -31,17 +31,6 @@
end
end

context "with a valid matching ssn input but no matching intake" do
let(:archived_intake) { nil }
let(:input_ssn) { "123-45-6789" }

it "to not be valid" do
expect(form).to_not be_valid
expect(form.errors).to include :ssn
expect(form.errors[:ssn]).to include I18n.t("state_file.archived_intakes.identification_number.edit.error_message")
end
end

context "with a valid matching ssn input and with a matching intake" do
let(:input_ssn) { "123-45-6789" }

Expand Down
Loading

0 comments on commit 1a8bf33

Please sign in to comment.