Skip to content

Commit

Permalink
80453 create a method to upsert IPFs based on 5655 metadata (#16386)
Browse files Browse the repository at this point in the history
* 80453 create a method to upsert IPFs based on 5655 metadata

* move user verification logic out of UserVerification model at reviewer's request
  • Loading branch information
kjsuarez committed Apr 23, 2024
1 parent 7233ff1 commit 7dbcb3e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
33 changes: 33 additions & 0 deletions modules/debts_api/app/models/debts_api/v0/form5655_submission.rb
Expand Up @@ -96,5 +96,38 @@ def register_success
def streamlined?
public_metadata.dig('streamlined', 'value') == true
end

def upsert_in_progress_form
form = InProgressForm.find_or_initialize_by(form_id: '5655', user_uuid:)
form.user_account = user_account_from_uuid(user_uuid)
form.real_user_uuid = user_uuid

form.update!(form_data: ipf_data, metadata: fresh_metadata)
end

def fresh_metadata
{
'return_url' => '/review-and-submit',
'submission' => {
'status' => false,
'error_message' => false,
'id' => false,
'timestamp' => false,
'has_attempted_submit' => false
},
'saved_at' => Time.now.to_i,
'created_at' => Time.now.to_i,
'expiresAt' => (DateTime.now + 60).to_time.to_i,
'lastUpdated' => Time.now.to_i,
'inProgressFormId' => '5655'
}
end

def user_account_from_uuid(user_uuid)
UserVerification.where(idme_uuid: user_uuid)
.or(UserVerification.where(logingov_uuid: user_uuid))
.or(UserVerification.where(backing_idme_uuid: user_uuid))
.last&.user_account
end
end
end
Expand Up @@ -39,6 +39,42 @@
end
end

describe '.upsert_in_progress_form' do
let(:user) { create(:form5655_submission) }
let(:form5655_submission) { create(:debts_api_form5655_submission, user_uuid: 'b2fab2b56af045e1a9e2394347af91ef') }
let(:in_progress_form) { create(:in_progress_5655_form, user_uuid: 'b2fab2b5-6af0-45e1-a9e2-394347af91ef') }

context 'without a related InProgressForm' do
it 'updates the related form' do
in_progress_form.destroy!
form = InProgressForm.find_by(form_id: '5655', user_uuid: form5655_submission.user_uuid)
expect(form).to be_nil

data = '{"its":"me"}'
form5655_submission.ipf_data = data
form5655_submission.upsert_in_progress_form
form = InProgressForm.find_by(form_id: '5655', user_uuid: form5655_submission.user_uuid)
expect(form&.form_data).to eq(data)
end
end

context 'with a related InProgressForm' do
it 'updates the related form' do
data = '{"its":"me"}'
form5655_submission
in_progress_form
form = InProgressForm.find_by(form_id: '5655', user_uuid: form5655_submission.user_uuid)
expect(form).to be_present
expect(form&.form_data).not_to eq(data)

form5655_submission.ipf_data = data
form5655_submission.upsert_in_progress_form
form = InProgressForm.find_by(form_id: '5655', user_uuid: form5655_submission.user_uuid)
expect(form&.form_data).to eq(data)
end
end
end

describe '.submit_to_vba' do
let(:form5655_submission) { create(:debts_api_form5655_submission) }
let(:guy) { create(:form5655_submission) }
Expand Down

0 comments on commit 7dbcb3e

Please sign in to comment.