Skip to content

Commit

Permalink
Fix flaky tests and warnings and add TimeCop testing (#4577)
Browse files Browse the repository at this point in the history
  • Loading branch information
embarnard committed Jun 20, 2024
1 parent 0082cab commit bd72e05
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 47 deletions.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def before_withdrawal_date_deadline?
helper_method :before_withdrawal_date_deadline?

def post_deadline_withdrawal_date
# after the tax deadline we automatically set the bank withdrawal date to be the current day
if params[:us_state] == 'ny'
app_time.in_time_zone('America/New_York')
else
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ development:
# Do not set this db to the same as development or production.
test:
<<: *local_default
database: vita-min_test<%= ENV['TEST_ENV_NUMBER'] %>
database: vita-min_test<%= ENV['TEST_ENV_NUMBER'] == '1' ? '' : ENV['TEST_ENV_NUMBER'] %>
pool: 10

production:
Expand Down
141 changes: 141 additions & 0 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,48 @@ def index
end
end

describe "#open_for_state_file_intake?" do
context "before state file open intake" do
let(:fake_time) { Rails.configuration.state_file_start_of_open_intake - 1.minute }

it "returns false" do
Timecop.freeze(fake_time) do
expect(subject.open_for_state_file_intake?).to eq false
end
end
end

context "after state file open intake and before end of new intakes" do
let(:fake_time) { Rails.configuration.state_file_start_of_open_intake + 1.minute }

it "returns true" do
Timecop.freeze(fake_time) do
expect(subject.open_for_state_file_intake?).to eq true
end
end
end

context "after end of new intakes and before end of in-progress intakes" do
let(:fake_time) { Rails.configuration.state_file_end_of_in_progress_intakes - 1.minute }

it "returns true" do
Timecop.freeze(fake_time) do
expect(subject.open_for_state_file_intake?).to eq true
end
end
end

context "after end of in-progress intakes" do
let(:fake_time) { Rails.configuration.state_file_end_of_in_progress_intakes + 1.minute }

it "returns false" do
Timecop.freeze(fake_time) do
expect(subject.open_for_state_file_intake?).to eq false
end
end
end
end

describe "#withdrawal_date_deadline" do
let(:state) { "ny" }
before { @params = { us_state: state } }
Expand All @@ -1429,6 +1471,105 @@ def index
end
end

describe "#before_withdrawal_date_deadline?" do
let(:state) { "ny" }
before { @params = { us_state: state } }

context "ny intake" do
context "before withdrawal deadline for ny" do
let(:fake_time) { Rails.configuration.state_file_withdrawal_date_deadline_ny - 1.minute }

it "returns true" do
get :index, params: @params

Timecop.freeze(fake_time) do
expect(subject.before_withdrawal_date_deadline?).to eq true
end
end
end

context "after withdrawal deadline for ny" do
let(:fake_time) { Rails.configuration.state_file_withdrawal_date_deadline_ny + 1.minute }

it "returns false" do
get :index, params: @params

Timecop.freeze(fake_time) do
expect(subject.before_withdrawal_date_deadline?).to eq false
end
end
end

context "before withdrawal deadline for az" do
let(:fake_time) { Rails.configuration.state_file_end_of_new_intakes - 1.minute }

it "returns false" do
get :index, params: @params

Timecop.freeze(fake_time) do
expect(subject.before_withdrawal_date_deadline?).to eq false
end
end
end
end

context "az intake" do
let(:state) { "az" }
context "before withdrawal deadline for az" do
let(:fake_time) { Rails.configuration.state_file_end_of_new_intakes - 1.minute }

it "returns true" do
get :index, params: @params

Timecop.freeze(fake_time) do
expect(subject.before_withdrawal_date_deadline?).to eq true
end
end
end

context "after withdrawal deadline for az" do
let(:fake_time) { Rails.configuration.state_file_end_of_new_intakes + 1.minute }


it "returns false" do
get :index, params: @params

Timecop.freeze(fake_time) do
expect(subject.before_withdrawal_date_deadline?).to eq false
end
end
end
end
end

describe "#post_deadline_withdrawal_date" do
let(:state) { "ny" }
before { @params = { us_state: state } }
let(:fake_time) { Time.find_zone('America/Los_Angeles').parse('2001-01-01 00:00:00') }

context "ny app" do
it "returns the current time in EST timezone" do
get :index, params: @params

Timecop.freeze(fake_time) do
expect(subject.post_deadline_withdrawal_date).to eq DateTime.parse('2001-01-01 3:00 EST')
end
end
end

context "az app" do
let(:state) { "az" }

it "returns the current time in MST timezone" do
get :index, params: @params

Timecop.freeze(fake_time) do
expect(subject.post_deadline_withdrawal_date).to eq DateTime.parse('2001-01-01 1:00 MST')
end
end
end
end

context "when receiving invalid requests from robots" do
before do
allow(DatadogApi).to receive(:increment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
it "throws an error" do
expect {
post :update, params: params
}.to raise_error
}.to raise_error(NoMethodError)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/vita_providers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
get :show, params: { id: provider.id.to_s, zip: "94609" }

expect(assigns(:zip)).to eq "94609"
expect(assigns(:distance)).to eq 179.95539713817547
expect(assigns(:distance)).to be_within(0.000000001).of(179.95539713817547)
end

it "sends provider_page_view event to mixpanel" do
Expand Down
20 changes: 0 additions & 20 deletions spec/models/df_data_import_error_spec.rb

This file was deleted.

24 changes: 0 additions & 24 deletions spec/models/recaptcha_score_spec.rb

This file was deleted.

6 changes: 6 additions & 0 deletions spec/tasks/send_post_deadline_reminder_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
Rake.application.rake_require "tasks/state_file"
end

around do |example|
Timecop.freeze(DateTime.parse("2-12-2024")) do
example.run
end
end

context 'Sends the notification to all state-filing' do
let!(:az_intake) { create :state_file_az_intake, email_address: 'test@example.com', email_address_verified_at: 1.minute.ago, created_at: 25.hours.ago }
let!(:ny_intake) { create :state_file_ny_intake, email_address: 'test+01@example.com', email_address_verified_at: 1.minute.ago, created_at: 25.hours.ago }
Expand Down
8 changes: 8 additions & 0 deletions spec/tasks/send_pre_deadline_reminder_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
require 'rails_helper'

describe 'state_file:pre_deadline_reminder' do
include_context "rake"

before(:all) do
Rake.application.rake_require "tasks/state_file"
end

around do |example|
Timecop.freeze(DateTime.parse("2-12-2024")) do
example.run
end
end

context 'Sends the notification to all state-filing' do
let!(:az_intake) { create :state_file_az_intake, email_address: 'test@example.com', email_address_verified_at: 1.minute.ago, created_at: 25.hours.ago }
let!(:ny_intake) { create :state_file_ny_intake, email_address: 'test+01@example.com', email_address_verified_at: 1.minute.ago, created_at: 25.hours.ago }
Expand Down

0 comments on commit bd72e05

Please sign in to comment.