Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing flaky test - APPEALS-57724 #23345

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/models/organizations/business_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def change_history_rows
sql = Arel.sql(change_history_sql_filter_array.join(" "))
sanitized_filters = ActiveRecord::Base.sanitize_sql_array([sql])
sc_type_clauses = ActiveRecord::Base.sanitize_sql_array([sc_type_filter])
current_timestamp = ActiveRecord::Base.connection.quote(Time.zone.now)

change_history_sql_block = <<-SQL
WITH versions_agg AS NOT MATERIALIZED (
Expand Down Expand Up @@ -326,7 +327,7 @@ def change_history_rows
tasks.appeal_type, tasks.appeal_id, request_issues.nonrating_issue_category, request_issues.nonrating_issue_description,
request_issues.decision_date, decision_issues.disposition, tasks.assigned_at, request_issues.unidentified_issue_text,
request_decision_issues.decision_issue_id, request_issues.closed_at AS request_issue_closed_at,
tv.object_changes_array AS task_versions, (CURRENT_TIMESTAMP::date - tasks.assigned_at::date) AS days_waiting,
tv.object_changes_array AS task_versions, (#{current_timestamp}::date - tasks.assigned_at::date) AS days_waiting,
COALESCE(intakes.veteran_file_number, higher_level_reviews.veteran_file_number) AS veteran_file_number,
COALESCE(
NULLIF(CONCAT(unrecognized_party_details.name, ' ', unrecognized_party_details.last_name), ' '),
Expand Down Expand Up @@ -436,7 +437,7 @@ def change_history_rows
tasks.appeal_type, tasks.appeal_id, request_issues.nonrating_issue_category, request_issues.nonrating_issue_description,
request_issues.decision_date, decision_issues.disposition, tasks.assigned_at, request_issues.unidentified_issue_text,
request_decision_issues.decision_issue_id, request_issues.closed_at AS request_issue_closed_at,
tv.object_changes_array AS task_versions, (CURRENT_TIMESTAMP::date - tasks.assigned_at::date) AS days_waiting,
tv.object_changes_array AS task_versions, (#{current_timestamp}::date - tasks.assigned_at::date) AS days_waiting,
COALESCE(intakes.veteran_file_number, supplemental_claims.veteran_file_number) AS veteran_file_number,
COALESCE(
NULLIF(CONCAT(unrecognized_party_details.name, ' ', unrecognized_party_details.last_name), ' '),
Expand Down Expand Up @@ -651,19 +652,20 @@ def issue_types_filter
end

def days_waiting_filter
current_timestamp = ActiveRecord::Base.connection.quote(Time.zone.now)
if query_params[:days_waiting].present?
number_of_days = query_params[:days_waiting][:number_of_days]
operator = query_params[:days_waiting][:operator]
case operator
when ">", "<", "="
<<-SQL
AND (CURRENT_TIMESTAMP::date - tasks.assigned_at::date)::integer #{operator} '#{number_of_days.to_i}'
AND (#{current_timestamp}::date - tasks.assigned_at::date)::integer #{operator} '#{number_of_days.to_i}'
SQL
when "between"
end_days = query_params[:days_waiting][:end_days]
<<-SQL
AND (CURRENT_TIMESTAMP::date - tasks.assigned_at::date)::integer BETWEEN '#{number_of_days.to_i}' AND '#{end_days.to_i}'
AND (CURRENT_TIMESTAMP::date - tasks.assigned_at::date)::integer BETWEEN '#{number_of_days.to_i}' AND '#{end_days.to_i}'
AND (#{current_timestamp}::date - tasks.assigned_at::date)::integer BETWEEN '#{number_of_days.to_i}' AND '#{end_days.to_i}'
AND (#{current_timestamp}::date - tasks.assigned_at::date)::integer BETWEEN '#{number_of_days.to_i}' AND '#{end_days.to_i}'
SQL
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,19 @@ def verify_form_pre_population
click_dropdown(name: "appealHearingLocation", index: 0)
click_dropdown(name: "hearingDate", index: 1)
click_dropdown(name: "optionalHearingTime0", index: 0)
click_button(text: "Schedule")
safe_click("#button-Schedule")

expect(page).to have_content("You have successfully assigned")
end

step "navigate to the hearings form" do
appeal = Appeal.last
User.authenticate!(user: vso_user)
visit "queue/appeals/#{appeal.uuid}"
expect(page).to have_content("Video")
expect(page).to have_link(COPY::VSO_CONVERT_TO_VIRTUAL_TEXT)
click_link(COPY::VSO_CONVERT_TO_VIRTUAL_TEXT)
expect(page).to have_content("Convert to Virtual Hearing")
expect(page).to have_content(COPY::CONVERT_HEARING_TYPE_SUBTITLE_3)
expect(page).to have_current_path("/hearings/#{appeal.hearings.first.uuid}/details")
end
end
Expand All @@ -297,7 +300,7 @@ def verify_form_pre_population
click_dropdown(name: "appealHearingLocation", index: 0)
click_dropdown(name: "hearingDate", index: 0)
click_dropdown(name: "optionalHearingTime0", index: 0)
click_button(text: "Schedule")
safe_click("#button-Schedule")
end

step "vso user" do
Expand Down
4 changes: 3 additions & 1 deletion spec/feature/intake/issue_modification_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@
User.authenticate!(roles: ["System Admin", "Certify Appeal", "Mail Intake", "Admin Intake"])
end

let(:freeze_time) { Time.utc(2024, 5, 15, 19, 0, 5) }

before do
vha_org.add_user(current_user)
Timecop.freeze
Timecop.freeze(freeze_time)
end

after do
Expand Down
18 changes: 11 additions & 7 deletions spec/services/claim_change_history/claim_history_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ def create_last_addition_and_verify_events(original_events, current_events)
context "equal to number of days" do
let(:filters) { { days_waiting: { number_of_days: 5, operator: "=" } } }

it "should only return events for tasks that match the days waiting filter", skip: "Flakey test" do
it "should only return events for tasks that match the days waiting filter" do
subject
expect(service_instance.events.map(&:event_type)).to contain_exactly(*expected_hlr_event_types)
end
Expand Down Expand Up @@ -1053,12 +1053,16 @@ def create_last_addition_and_verify_events(original_events, current_events)

it "should only return the last event for each task" do
subject
expected_event_types = [
:completed,
:in_progress,
:request_approved
]
expect(service_instance.events.map(&:event_type)).to contain_exactly(*expected_event_types)
result_event_types = service_instance.events.map(&:event_type)
# Check that :completed and :request_approved are present since those were forced to the end in the setup
expect(result_event_types).to include(:completed, :request_approved)

# Check that either :in_progress or :added_issue is present since they are the exact same timestamp
# and it's not always deterministic
expect(result_event_types).to include(:in_progress).or include(:added_issue)

# Ensure there are exactly 3 events, one for each task
expect(result_event_types.size).to eq(3)
end
end

Expand Down
Loading