Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…fairs/vets-api into restrict-ppiu-traffic
  • Loading branch information
tpharrison committed Apr 24, 2024
2 parents 5a6763e + a267cc8 commit c69bbf1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ features:
actor_type: user
description: Enables/disables refill-related content for Medications on VA.gov
enable_in_development: true
mhv_landing_page_enable_va_gov_health_tools_links:
actor_type: user
description: Enables VA.gov Health Tools links (Appts, SM, Rx, Records) on MHV-on-VA.gov Landing Page
mhv_to_logingov_account_transition:
actor_type: cookie_id
description: Enables/disables MHV to Login.gov account transfer experience (Identity)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'debts_api/v0/financial_status_report_service'
require 'debts_api/v0/fsr_rehydration_service'

module DebtsApi
module V0
Expand All @@ -23,6 +24,27 @@ def download_pdf
)
end

def submissions
submissions = DebtsApi::V0::Form5655Submission.where(user_uuid: current_user.uuid)
render json: { 'submissions' => submissions.map { |sub| { 'id' => sub.id } } }
end

def rehydrate
submission_id = params[:submission_id]

DebtsApi::V0::FsrRehydrationService.attempt_rehydration(user_uuid: current_user.uuid, submission_id:)

render json: { result: 'FSR rehydrated' }
rescue ActiveRecord::RecordNotFound
render json: { error: "Form5655Submission record #{submission_id} not found." }, status: :not_found
rescue DebtsApi::V0::FsrRehydrationService::UserDoesNotOwnsubmission
render json: { error: "User #{current_user.uuid} does not own submission #{submission_id}" },
status: :unauthorized
rescue DebtsApi::V0::FsrRehydrationService::NoInProgressFormDataStored
render json: { error: "Form5655Submission record #{submission_id} missing InProgressForm data",
status: :not_found }
end

private

def render_not_found
Expand Down
3 changes: 3 additions & 0 deletions modules/debts_api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
resources :financial_status_reports, only: %i[create] do
collection do
get :download_pdf
get :submissions
end
end

get 'financial_status_reports/rehydrate_submission/:submission_id', to: 'financial_status_reports#rehydrate'

post 'calculate_total_assets', to: 'financial_status_reports_calculations#total_assets'
post 'calculate_monthly_expenses', to: 'financial_status_reports_calculations#monthly_expenses'
post 'calculate_all_expenses', to: 'financial_status_reports_calculations#all_expenses'
Expand Down
19 changes: 19 additions & 0 deletions modules/debts_api/lib/debts_api/v0/fsr_rehydration_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module DebtsApi
class V0::FsrRehydrationService
include SentryLogging

class UserDoesNotOwnsubmission < StandardError; end
class NoInProgressFormDataStored < StandardError; end

def self.attempt_rehydration(user_uuid:, submission_id:)
submission = DebtsApi::V0::Form5655Submission.find(submission_id)

raise NoInProgressFormDataStored unless submission.ipf_data
raise UserDoesNotOwnsubmission unless submission.user_uuid == user_uuid

submission.upsert_in_progress_form
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,39 @@ def mock_pdf_fill
expect(response.body).to eq(content)
end
end

describe '#rehydrate' do
context 'on a nonexistent submission' do
it 'renders a 404' do
get '/debts_api/v0/financial_status_reports/rehydrate_submission/1'
expect(response).to have_http_status(:not_found)
end
end

context 'on a submission you don\'t own' do
let(:form5655_submission) { create(:debts_api_form5655_submission) }

it 'renders a 404' do
form5655_submission
form5655_submission.update!(user_uuid: 'nottherightguy', ipf_data: '{"its":"me"}')
get "/debts_api/v0/financial_status_reports/rehydrate_submission/#{form5655_submission.id}"
expect(response.code).to eq('401')
body = "{\"error\":\"User #{user.uuid} does not own submission #{form5655_submission.id}\"}"
expect(response.body).to eq(body)
end
end

context 'on a submission you do own' do
let(:form5655_submission) do
create(:debts_api_form5655_submission, user_uuid: 'b2fab2b56af045e1a9e2394347af91ef')
end

it 'rehydrates In Progress Form' do
form5655_submission
form5655_submission.update!(user_uuid: user.uuid, ipf_data: '{"its":"me"}')
get "/debts_api/v0/financial_status_reports/rehydrate_submission/#{form5655_submission.id}"
expect(response.code).to eq('200')
end
end
end
end

0 comments on commit c69bbf1

Please sign in to comment.