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

96358 Fix for out of order attachment ids - IVC CHAMPVA forms #19647

Merged
merged 6 commits into from
Nov 29, 2024

Conversation

michaelclement
Copy link
Contributor

@michaelclement michaelclement commented Nov 27, 2024

Summary

This PR fixes an issue with how attachment metadata is prepared before being sent to Pega for ingestion. Previously, the document types (attachment_id, e.g.: 'Birth certificate') were rolled into a list based solely on the order of the front end configuration.

These values were then matched up with the list of attachments in the cache on the backend. However, if a user uploaded files in any order other than the order in which they encounter them, the alignment between attachment_id and the file itself would be thrown off. This caused files to be mis-categorized.

By reorganizing the attachment_id array to match with the order files were uploaded, metadata gets matched correctly regardless of how the user uploaded their files.

  • Matches supporting docs up to database records and sorts by date created

Related issue(s)

Testing done

  • New code is covered by unit tests

Screenshots

NA

What areas of the site does it impact?

IVC CHAMPVA forms

Acceptance criteria

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No error nor warning in the console.
  • Events are being sent to the appropriate logging solution
  • Documentation has been updated (link to documentation)
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • Feature/bug has a monitor built into Datadog (if applicable)
  • If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected
  • I added a screenshot of the developed feature

Requested Feedback

(OPTIONAL)What should the reviewers know in addition to the above. Is there anything specific you wish the reviewer to assist with. Do you have any concerns with this PR, why?

@va-vfs-bot va-vfs-bot temporarily deployed to fix-upload-order-attachment-id-bug-ivc-forms/main/main November 27, 2024 19:18 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to fix-upload-order-attachment-id-bug-ivc-forms/main/main November 27, 2024 19:36 Inactive
@va-vfs-bot va-vfs-bot temporarily deployed to fix-upload-order-attachment-id-bug-ivc-forms/main/main November 29, 2024 13:00 Inactive
Comment on lines -92 to +107
parsed_form_data['supporting_docs']&.pluck('attachment_id')&.compact.presence ||
parsed_form_data['supporting_docs']&.pluck('claim_id')&.compact.presence || []
cached_uploads = []
parsed_form_data['supporting_docs']&.each do |d|
# Get the database record that corresponds to this file upload:
record = PersistentAttachments::MilitaryRecords.find_by(guid: d['confirmation_code'])
# Push to our array with some extra information so we can sort by date uploaded:
cached_uploads.push({ attachment_id: d['attachment_id'],
created_at: record.created_at,
file_name: record.file.id })
end

# Sort by date created so we have the file's upload order and
# reduce down to just the attachment id strings:
attachment_ids = cached_uploads.sort_by { |h| h[:created_at] }.pluck(:attachment_id)&.compact.presence

# Return either the attachment IDs or `claim_id`s (in the case of form 10-7959a):
attachment_ids || parsed_form_data['supporting_docs']&.pluck('claim_id')&.compact.presence || []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the attachment IDs has always mattered, so this is ensuring we have things in a sane order (date created) rather than the previous arbitrary order.

In future we will probably want to look into a wider refactor. A direct mapping of files to doc types rather than relying on the order of this array would be better, but this is a necessary first step to make sure the MVP works.

Comment on lines +39 to +40
allow(PersistentAttachments::MilitaryRecords).to receive(:find_by)
.and_return(double('Record1', created_at: 1.day.ago, id: 'some_uuid', file: double(id: 'file0')))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock added to account for new logic in supporting_document_ids that attempts to read PersistentAttachments::MilitaryRecords.

@va-vfs-bot va-vfs-bot temporarily deployed to fix-upload-order-attachment-id-bug-ivc-forms/main/main November 29, 2024 15:11 Inactive
reiting
reiting previously approved these changes Nov 29, 2024
@michaelclement michaelclement marked this pull request as ready for review November 29, 2024 15:26
@michaelclement michaelclement requested review from a team as code owners November 29, 2024 15:26
acrollet
acrollet previously approved these changes Nov 29, 2024
Copy link
Contributor

@acrollet acrollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work! just one question in a comment

cached_uploads = []
parsed_form_data['supporting_docs']&.each do |d|
# Get the database record that corresponds to this file upload:
record = PersistentAttachments::MilitaryRecords.find_by(guid: d['confirmation_code'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC what would happen if this query failed? Any possibility of a silent failure? I don't want to hold this PR up but it may be worth a follow-on to investigate and make it more defensive if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the query returns nil on l95, we'll get an error when we try to pull the created_at and file.id on lines 98 & 99. This will bubble back up to the user as a 500, so they'll get an error screen and the submission won't go through.

I can definitely make a follow up to probe this a little more - thanks for looking this over!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @michaelclement! maybe the follow-up could be to make a quick couple of request specs that confirm an error is returned when the query returns nil or throws.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a good idea - I'm going to put a couple more tests into this PR while it's top of mind. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acrollet Tests added in this commit - please let me know if there's anything else you think I should take a look at!

cloudmagic80
cloudmagic80 previously approved these changes Nov 29, 2024
rjohnson2011
rjohnson2011 previously approved these changes Nov 29, 2024
Copy link

Backend-review-group approval confirmed.

@michaelclement michaelclement marked this pull request as draft November 29, 2024 16:46
@michaelclement michaelclement marked this pull request as ready for review November 29, 2024 16:57
@michaelclement michaelclement merged commit bbdab6b into master Nov 29, 2024
37 checks passed
@michaelclement michaelclement deleted the fix-upload-order-attachment-id-bug-ivc-forms branch November 29, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants