diff --git a/spec/controllers/hearings/schedule_periods_controller_spec.rb b/spec/controllers/hearings/schedule_periods_controller_spec.rb index 491eb9a57cf..7d7101798a8 100644 --- a/spec/controllers/hearings/schedule_periods_controller_spec.rb +++ b/spec/controllers/hearings/schedule_periods_controller_spec.rb @@ -5,6 +5,12 @@ let!(:ro_schedule_period) { create(:ro_schedule_period) } let!(:judge_stuart) { create(:user, :with_vacols_judge_record, full_name: "Stuart Huels", css_id: "BVAHUELS") } let!(:judge_doris) { create(:user, :with_vacols_judge_record, full_name: "Doris Lamphere", css_id: "BVALAMPHERE") } + before(:all) do + # clean up is required as Hearing day ID is hard coded in the spreadsheet file. + # if for some reason the database's table pk is not reset then it will cause test failure. + + clean_up_hearing_days + end shared_context "hearing_days" do let!(:hearing_days) do @@ -121,7 +127,7 @@ context "judge assignment" do include_context "hearing_days" - it "stages hearing days for judge assignment", skip: "flake" do + it "stages hearing days for judge assignment" do base64_header = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," post :create, params: { schedule_period: { @@ -230,4 +236,9 @@ expect(response.status).to eq 200 end end + + def clean_up_hearing_days + HearingDay.delete_all + ActiveRecord::Base.connection.reset_pk_sequence!(HearingDay.table_name) + end end diff --git a/spec/feature/certification/certification_stats_spec.rb b/spec/feature/certification/certification_stats_spec.rb deleted file mode 100644 index 3195646a690..00000000000 --- a/spec/feature/certification/certification_stats_spec.rb +++ /dev/null @@ -1,186 +0,0 @@ -# frozen_string_literal: true - -RSpec.feature "Certification Stats Dashboard", :postgres, skip: "deprecated" do - before do - Timecop.freeze(Time.utc(2015, 1, 1, 17, 55, 0, rand(1000))) - - Certification.create( - nod_matching_at: 5.hours.ago, - form9_matching_at: 5.hours.ago, - soc_matching_at: 5.hours.ago, - ssocs_required: false, - ssocs_matching_at: nil, - form8_started_at: 5.hours.ago, - created_at: 5.hours.ago, - completed_at: 4.hours.ago - ) - - Certification.create( - nod_matching_at: 4.hours.ago, - form9_matching_at: 5.hours.ago, - soc_matching_at: 5.hours.ago, - ssocs_required: true, - ssocs_matching_at: 4.hours.ago, - form8_started_at: 4.hours.ago, - created_at: 5.hours.ago, - completed_at: nil - ) - - Certification.create( - nod_matching_at: 4.hours.ago, - form9_matching_at: 5.hours.ago, - soc_matching_at: 5.hours.ago, - ssocs_required: true, - ssocs_matching_at: 5.hours.ago, - form8_started_at: 4.hours.ago, - created_at: 5.hours.ago, - completed_at: 3.hours.ago - ) - - Certification.create( - nod_matching_at: 45.minutes.ago, - form9_matching_at: 45.minutes.ago, - soc_matching_at: 45.minutes.ago, - ssocs_required: true, - ssocs_matching_at: 45.minutes.ago, - form8_started_at: 45.minutes.ago, - created_at: 45.minutes.ago, - completed_at: 30.minutes.ago - ) - CertificationStats.calculate_all! - - # Necessary role to view certification_stats page - User.authenticate!(roles: ["System Admin"]) - end - - let(:leftarrow) { "d3.select(window).dispatch('keydown', { detail: { keyCode: 37 } })" } - let(:rightarrow) { "d3.select(window).dispatch('keydown', { detail: { keyCode: 39 } })" } - - scenario "Switching tab intervals" do - visit "/certification/stats" - expect(page).to have_content("Activity for 12:00–12:59 EST (so far)") - expect(page).to have_content("Certifications Started\n1") - expect(page).to have_content("Certifications Completed\n1") - expect(page).to have_content("Overall\n100 %") - expect(page).to have_content("Missing Document\n?? %") - expect(page).to have_content("Overall (median)\n15.00 min") - expect(page).to have_content("Missing Document (median)\n??") - expect(page).to have_content("Any Document\n0 %") - - click_on "Daily" - expect(page).to have_content("Activity for January 1 (so far)") - expect(page).to have_content("Certifications Started\n4") - expect(page).to have_content("Certifications Completed\n3") - expect(page).to have_content("Overall\n75 %") - expect(page).to have_content("Missing Document\n50 %") - expect(page).to have_content("Overall (median)\n1.00 hours") - expect(page).to have_content("Missing Document (median)\n2.00 hours") - expect(page).to have_content("Any Document\n50 %") - expect(page).to have_content("NOD\n50 %") - expect(page).to have_content("SOC\n0 %") - expect(page).to have_content("SSOC\n33 %") - expect(page).to have_content("Form 9\n0 %") - end - - # The stats tests don't play well with Selenium Chrome - # The mouseover effect with the stat bars is erratic - # TODO: Augment stats to disable mouseover for the tests - scenario "Check missing documents" do - Certification.create( - nod_matching_at: 45.minutes.ago, - form9_matching_at: 45.minutes.ago, - soc_matching_at: 45.minutes.ago, - ssocs_required: true, - ssocs_matching_at: 43.minutes.ago, - form8_started_at: nil, - created_at: 45.minutes.ago, - completed_at: nil - ) - - Certification.create( - nod_matching_at: 45.minutes.ago, - form9_matching_at: 45.minutes.ago, - soc_matching_at: nil, - ssocs_required: true, - ssocs_matching_at: 45.minutes.ago, - form8_started_at: nil, - created_at: 45.minutes.ago, - completed_at: nil - ) - CertificationStats.calculate_all! - - visit "/certification/stats/daily" - - # Turn mousever events off on the Stats dashboard to not confuse Chrome - page.execute_script("window.Dashboard.mouseoverEvents = false;") - - expect(page).to have_content("Activity for January 1 (so far)") - expect(page).to have_content("Certifications Started\n6") - expect(page).to have_content("Certifications Completed\n3") - expect(page).to have_content("Overall\n50 %") - expect(page).to have_content("Missing Document\n25 %") - expect(page).to have_content("Overall (median)\n1.00 hours") - expect(page).to have_content("Missing Document (median)\n2.00 hours") - - expect(page).to have_content("Any Document\n67 %") - expect(page).to have_content("NOD\n33 %") - expect(page).to have_content("SOC\n17 %") - expect(page).to have_content("SSOC\n40 %") - expect(page).to have_content("Form 9\n0 %") - end - - scenario "Toggle median to 95th percentile and navigate to past periods", - skip: "Seeing weird Time/Day related test failure" do - visit "/certification/stats" - - # Turn mouseover events off on the Stats dashboard to not confuse Chrome - page.execute_script("window.Dashboard.mouseoverEvents = false;") - - click_on "Daily" - - find("#time-to-certify-toggle").click - - expect(page).to have_content("Overall (95th percentile)") - expect(page).to have_content("December 17") - - # Scroll once more to see December 16 have no stats - page.driver.execute_script(leftarrow) - expect(page).to have_content("December 16") - expect(page).to have_content("Overall (95th percentile)") - - find("#time-to-certify-toggle").click - - # Scroll to the most recent time interval - page.driver.execute_script(rightarrow) - expect(page).to have_content("Overall (median)") - end - - scenario "Unauthorized user access" do - # Unauthenticated access - User.unauthenticate! - visit "/certification/stats" - expect(page.has_no_content?("Activity for")).to eq(true) - expect(page.has_no_content?("Certification Rate")).to eq(true) - expect(page.has_no_content?("Time to Certify")).to eq(true) - expect(page.has_no_content?("Missing Documents")).to eq(true) - - # Authenticated access with System Admin CSS role - User.tester!(roles: ["System Admin"]) - visit "/certification/stats" - expect(page.has_no_content?("Activity for")).to eq(true) - expect(page.has_no_content?("Certification Rate")).to eq(true) - expect(page.has_no_content?("Time to Certify")).to eq(true) - expect(page.has_no_content?("Missing Documents")).to eq(true) - - # Authenticated access without System Admin role - User.authenticate! - visit "/certification/stats" - expect(page.has_no_content?("Activity for")).to eq(true) - expect(page.has_no_content?("Certification Rate")).to eq(true) - expect(page.has_no_content?("Time to Certify")).to eq(true) - expect(page.has_no_content?("Missing Documents")).to eq(true) - - expect(page).to have_content("You aren't authorized to use this part of Caseflow yet.") - expect(page).to have_content("Unauthorized") - end -end diff --git a/spec/feature/dispatch/dispatch_stats_spec.rb b/spec/feature/dispatch/dispatch_stats_spec.rb deleted file mode 100644 index 9d309459471..00000000000 --- a/spec/feature/dispatch/dispatch_stats_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -RSpec.feature "Dispatch Stats Dashboard", :postgres, skip: "deprecated" do - before do - Timecop.freeze(Time.utc(2015, 1, 1, 17, 55, 0, rand(1000))) - end - - context ".show#daily" do - before do - Rails.cache.clear - DispatchStats.calculate_all! - end - it "switches between the tabs" do - User.authenticate!(roles: ["Manage Claim Establishment"]) - visit "/dispatch/stats" - expect(page).to have_content("Establish Claim Tasks Identified") - expect(page).to have_content("Establish Claim Task Activity") - expect(page).to have_content("Establish Claim Task Completion Rate") - expect(page).to have_content("Time to Claim Establishment") - expect(page).to have_content("Establish Claim Tasks Canceled") - - click_on "Daily" - expect(page).to have_content("Establish Claim Tasks Identified") - end - end - - context ".show" do - before do - Generators::EstablishClaim.create(started_at: 30.minutes.ago, completed_at: 15.minutes.ago, completion_status: 0) - Generators::EstablishClaim.create(started_at: 30.minutes.ago) - Rails.cache.clear - DispatchStats.calculate_all! - end - it "loads the correct stats" do - User.authenticate!(roles: ["Manage Claim Establishment"]) - visit "/dispatch/stats" - expect(page).to have_content("All\n2") - end - end - - scenario "Users without manager permissions cannot view page" do - User.authenticate! - visit "/dispatch/stats" - expect(page).to have_content("Drat!\nYou aren't authorized to use this part of Caseflow yet.") - end -end diff --git a/spec/models/certification_stats_spec.rb b/spec/models/certification_stats_spec.rb deleted file mode 100644 index 5f93d178d7e..00000000000 --- a/spec/models/certification_stats_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -describe CertificationStats, :postgres do - before do - Timecop.freeze(Time.utc(2016, 2, 17, 20, 59, 0)) - Rails.cache.clear - end - - let(:monthly_stats) { Rails.cache.read("CertificationStats-2016-2") } - let(:weekly_stats) { Rails.cache.read("CertificationStats-2016-w07") } - let(:daily_stats) { Rails.cache.read("CertificationStats-2016-2-17") } - let(:hourly_stats) { Rails.cache.read("CertificationStats-2016-2-17-15") } - let(:prev_weekly_stats) { Rails.cache.read("CertificationStats-2016-w06") } - - context ".calculate_all!" do - it "calculates and saves all calculated certification_stats" do - Certification.create(completed_at: 40.days.ago) - Certification.create(completed_at: 7.days.ago) - Certification.create(completed_at: 2.days.ago) - Certification.create(completed_at: 4.hours.ago) - Certification.create(completed_at: 30.minutes.ago) - - CertificationStats.calculate_all! - - expect(monthly_stats[:certifications_completed]).to eq(4) - expect(weekly_stats[:certifications_completed]).to eq(3) - expect(daily_stats[:certifications_completed]).to eq(2) - expect(hourly_stats[:certifications_completed]).to eq(1) - expect(prev_weekly_stats[:certifications_completed]).to eq(1) - end - - it "overwrites incomplete periods" do - Certification.create(completed_at: 30.minutes.ago) - CertificationStats.calculate_all! - Certification.create(completed_at: 1.minute.ago) - CertificationStats.calculate_all! - - expect(hourly_stats[:certifications_completed]).to eq(2) - end - - it "does not recalculate complete periods" do - Certification.create(completed_at: 7.days.ago) - CertificationStats.calculate_all! - Certification.create(completed_at: 7.days.ago) - CertificationStats.calculate_all! - - expect(prev_weekly_stats[:certifications_completed]).to eq(1) - end - end -end diff --git a/spec/models/dispatch_stats_spec.rb b/spec/models/dispatch_stats_spec.rb deleted file mode 100644 index 6456d1a3b01..00000000000 --- a/spec/models/dispatch_stats_spec.rb +++ /dev/null @@ -1,102 +0,0 @@ -# frozen_string_literal: true - -describe DispatchStats, :postgres do - before do - Timecop.freeze(Time.utc(2016, 2, 17, 20, 59, 0)) - Rails.cache.clear - end - - let(:monthly_stats) { Rails.cache.read("DispatchStats-2016-2") } - let(:weekly_stats) { Rails.cache.read("DispatchStats-2016-w07") } - let(:daily_stats) { Rails.cache.read("DispatchStats-2016-2-17") } - let(:hourly_stats) { Rails.cache.read("DispatchStats-2016-2-17-15") } - let(:prev_weekly_stats) { Rails.cache.read("DispatchStats-2016-w06") } - - context ".throttled_calculate_all!" do - subject { DispatchStats.throttled_calculate_all! } - context "when not previously calculated" do - it "calculates stats" do - expect(DispatchStats).to receive(:calculate_all!) - subject - expect(Rails.cache.read("DispatchStats-last-calculated-timestamp")).to eq(Time.now.to_i) - end - end - - context "when last calculated more than 61 minutes ago" do - before { Rails.cache.write("DispatchStats-last-calculated-timestamp", 61.minutes.ago.to_i) } - - it "calculates stats" do - expect(DispatchStats).to receive(:calculate_all!) - subject - expect(Rails.cache.read("DispatchStats-last-calculated-timestamp")).to eq(Time.now.to_i) - end - end - - context "when last calculated less than 60 minutes ago" do - before { Rails.cache.write("DispatchStats-last-calculated-timestamp", 59.minutes.ago.to_i) } - - it "doesn't recalculate stats" do - expect(DispatchStats).to_not receive(:calculate_all!) - subject - end - end - end - - context ".calculate_all!" do - it "calculates and saves all completed dispatch_stats" do - Generators::EstablishClaim.create(completed_at: 40.days.ago) - Generators::EstablishClaim.create(completed_at: 7.days.ago) - Generators::EstablishClaim.create(completed_at: 2.days.ago) - Generators::EstablishClaim.create(completed_at: 4.hours.ago) - Generators::EstablishClaim.create(completed_at: 30.minutes.ago) - - DispatchStats.calculate_all! - - expect(monthly_stats[:establish_claim_completed]).to eq(4) - expect(weekly_stats[:establish_claim_completed]).to eq(3) - expect(daily_stats[:establish_claim_completed]).to eq(2) - expect(hourly_stats[:establish_claim_completed]).to eq(1) - expect(prev_weekly_stats[:establish_claim_completed]).to eq(1) - end - - it "calculates and saves all started dispatch_stats" do - Generators::EstablishClaim.create(started_at: 40.days.ago) - Generators::EstablishClaim.create(started_at: 7.days.ago) - Generators::EstablishClaim.create(started_at: 2.days.ago) - Generators::EstablishClaim.create(started_at: 4.hours.ago) - Generators::EstablishClaim.create(started_at: 30.minutes.ago) - - DispatchStats.calculate_all! - - expect(monthly_stats[:establish_claim_started]).to eq(4) - expect(weekly_stats[:establish_claim_started]).to eq(3) - expect(daily_stats[:establish_claim_started]).to eq(2) - expect(hourly_stats[:establish_claim_started]).to eq(1) - expect(prev_weekly_stats[:establish_claim_started]).to eq(1) - end - - it "calculates and saves all canceled dispatch_stats" do - Generators::EstablishClaim.create(completed_at: 30.minutes.ago, completion_status: 1) - - DispatchStats.calculate_all! - - expect(monthly_stats[:establish_claim_canceled]).to eq(1) - expect(weekly_stats[:establish_claim_canceled]).to eq(1) - expect(daily_stats[:establish_claim_canceled]).to eq(1) - expect(hourly_stats[:establish_claim_canceled]).to eq(1) - expect(prev_weekly_stats[:establish_claim_canceled]).to eq(0) - end - - it "filters remands and partial grants from full grants" do - remand = Generators::EstablishClaim.create(completed_at: 7.days.ago) - full_grant = Generators::EstablishClaim.create(completed_at: 7.days.ago) - ClaimEstablishment.create(task_id: remand.id, decision_type: 3) - ClaimEstablishment.create(task_id: full_grant.id, decision_type: 1) - - DispatchStats.calculate_all! - - expect(monthly_stats[:establish_claim_full_grant_completed]).to eq(1) - expect(monthly_stats[:establish_claim_partial_grant_remand_completed]).to eq(1) - end - end -end