From 0234cb7844a23c47f72d3f3d37e2f38bf60609be Mon Sep 17 00:00:00 2001 From: Joshua Backfield <114932557+jbackfieldVA@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:46:39 -0400 Subject: [PATCH] 97 Added database table and endpoint for average number of days for completion (#16313) * 97 Added database table and endpoint for average number of days for claim completion. * 97 Added SPEC file for unittest coverage and also linted everything. * 97 Updated CODEOWNERS file. * 97 Missed the spec at the end of the spec file in CODEOWNERS. * 97 Updated test name to be reflective of what we are expecting. --------- Co-authored-by: Rebecca Tolmach <10993987+rmtolmach@users.noreply.github.com> Co-authored-by: bmatos312 <142250984+bmatos312@users.noreply.github.com> --- .github/CODEOWNERS | 3 ++ ...ge_days_for_claim_completion_controller.rb | 15 +++++++ .../average_days_for_claim_completion.rb | 4 ++ config/routes.rb | 2 + ...ys_for_claim_completion_controller_spec.rb | 39 +++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 app/controllers/v0/average_days_for_claim_completion_controller.rb create mode 100644 app/models/average_days_for_claim_completion.rb create mode 100644 spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 165e62a6273..fde32a93c71 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -46,6 +46,7 @@ app/controllers/v0/appeals_controller.rb @department-of-veterans-affairs/benefit app/controllers/v0/appointments_controller.rb @department-of-veterans-affairs/vfs-vaos @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/controllers/v0/apps_controller.rb @department-of-veterans-affairs/lighthouse-pivot app/controllers/v0/ask_va @department-of-veterans-affairs/ask-va-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +app/controllers/v0/average_days_for_claim_completion_controller.rb @department-of-veterans-affairs/benefits-microservices @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/controllers/v0/backend_statuses_controller.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/controllers/v0/benefits_claims_controller.rb @department-of-veterans-affairs/benefits-management-tools-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/controllers/v0/benefits_documents_controller.rb @department-of-veterans-affairs/benefits-management-tools-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @@ -194,6 +195,7 @@ app/models/async_transaction/base.rb @department-of-veterans-affairs/vfs-authent app/models/async_transaction/va_profile @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/backend-review-group app/models/async_transaction/vet360 @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/backend-review-group app/models/attachment.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +app/models/average_days_for_claim_completion.rb @department-of-veterans-affairs/benefits-microservices @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/backend_status.rb @department-of-veterans-affairs/backend-review-group app/models/bank_name.rb @department-of-veterans-affairs/vfs-authenticated-experience-backend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group app/models/base_facility.rb @department-of-veterans-affairs/vfs-facilities-frontend @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @@ -995,6 +997,7 @@ spec/controllers/sign_in @department-of-veterans-affairs/octo-identity spec/controllers/v0/account_controls_controller_spec.rb @department-of-veterans-affairs/octo-identity spec/controllers/v0/apps_controller_spec.rb @department-of-veterans-affairs/lighthouse-pivot spec/controllers/v0/ask_va @department-of-veterans-affairs/ask-va-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group +spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb @department-of-veterans-affairs/benefits-microservices @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/controllers/v0/benefits_claims_controller_spec.rb @department-of-veterans-affairs/benefits-management-tools-be @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/controllers/v0/benefits_reference_data_controller_spec.rb @department-of-veterans-affairs/Benefits-Team-1 @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group spec/controllers/v0/burial_claims_controller_spec.rb @department-of-veterans-affairs/mbs-core-team @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group diff --git a/app/controllers/v0/average_days_for_claim_completion_controller.rb b/app/controllers/v0/average_days_for_claim_completion_controller.rb new file mode 100644 index 00000000000..9c3ef7de693 --- /dev/null +++ b/app/controllers/v0/average_days_for_claim_completion_controller.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module V0 + class AverageDaysForClaimCompletionController < ApplicationController + service_tag 'average-days-to-completion' + skip_before_action :authenticate, only: :index + + def index + rtn = AverageDaysForClaimCompletion.order('created_at DESC').first + render json: { + average_days: rtn.present? ? rtn.average_days : -1.0 + } + end + end +end diff --git a/app/models/average_days_for_claim_completion.rb b/app/models/average_days_for_claim_completion.rb new file mode 100644 index 00000000000..78bb6d78a42 --- /dev/null +++ b/app/models/average_days_for_claim_completion.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class AverageDaysForClaimCompletion < ApplicationRecord +end diff --git a/config/routes.rb b/config/routes.rb index 4d4044aa73d..cc8807d889f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -149,6 +149,8 @@ get 'claim_letters', to: 'claim_letters#index' get 'claim_letters/:document_id', to: 'claim_letters#show' + get 'average_days_for_claim_completion', to: 'average_days_for_claim_completion#index' + get 'virtual_agent_claim_letters', to: 'virtual_agent_claim_letters#index' get 'virtual_agent_claim_letters/:document_id', to: 'virtual_agent_claim_letters#show' diff --git a/spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb b/spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb new file mode 100644 index 00000000000..47a56a8450b --- /dev/null +++ b/spec/controllers/v0/average_days_for_claim_completion_controller_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe V0::AverageDaysForClaimCompletionController, type: :controller do + context 'when querying with nothing in db' do + it 'returns -1 for value' do + get :index + expect(response).to have_http_status(:ok) + expect(JSON.parse(response.body)['average_days']).to eq(-1.0) + end + end + + context 'when querying with record in db' do + before do + AverageDaysForClaimCompletion.create(average_days: 100) + end + + it 'returns the value' do + get :index + expect(response).to have_http_status(:ok) + expect(JSON.parse(response.body)['average_days']).to eq(100.0) + end + end + + context 'when querying with multiple records in db' do + before do + AverageDaysForClaimCompletion.create(average_days: 100) + AverageDaysForClaimCompletion.create(average_days: 200) + AverageDaysForClaimCompletion.create(average_days: 300) + end + + it 'returns the most recently inserted value' do + get :index + expect(response).to have_http_status(:ok) + expect(JSON.parse(response.body)['average_days']).to eq(300.0) + end + end +end