-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add model, factories, constants, helpers and vcr cassettes (#20346)
- Loading branch information
1 parent
fe5d9cf
commit 1066e5e
Showing
10 changed files
with
590 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'lighthouse/benefits_documents/constants' | ||
|
||
class EvidenceSubmission < ApplicationRecord | ||
belongs_to :user_account | ||
has_kms_key | ||
has_encrypted :template_metadata, key: :kms_key, **lockbox_options | ||
|
||
# Lighthouse upload statuses: | ||
# IN_PROGRESS: the workflow is currently executing. | ||
# SUCCESS: the workflow has completed all steps successfully. | ||
# FAILED: the workflow could not complete because a step encountered a non-recoverable error. | ||
scope :completed, -> { where(upload_status: BenefitsDocuments::Constants::UPLOAD_STATUS[:SUCCESS]) } | ||
scope :failed, -> { where(upload_status: BenefitsDocuments::Constants::UPLOAD_STATUS[:FAILED]) } | ||
scope :pending, -> { where(upload_status: BenefitsDocuments::Constants::UPLOAD_STATUS[:PENDING]) } | ||
# used for sending failure notification emails | ||
scope :va_notify_email_queued, lambda { | ||
where(upload_status: BenefitsDocuments::Constants::UPLOAD_STATUS[:FAILED]) | ||
.where.not(va_notify_date: nil) | ||
.where.not(va_notify_id: nil) | ||
} | ||
# used for sending failure notification emails | ||
scope :va_notify_email_not_queued, lambda { | ||
where(upload_status: BenefitsDocuments::Constants::UPLOAD_STATUS[:FAILED], va_notify_id: nil, va_notify_date: nil) | ||
} | ||
|
||
def completed? | ||
upload_status == BenefitsDocuments::Constants::UPLOAD_STATUS[:SUCCESS] | ||
end | ||
|
||
def failed? | ||
upload_status == BenefitsDocuments::Constants::UPLOAD_STATUS[:FAILED] | ||
end | ||
|
||
def pending? | ||
upload_status == BenefitsDocuments::Constants::UPLOAD_STATUS[:PENDING] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module BenefitsDocuments | ||
module Constants | ||
UPLOAD_STATUS = { | ||
PENDING: 'IN_PROGRESS', | ||
FAILED: 'FAILED', | ||
SUCCESS: 'SUCCESS' | ||
}.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module BenefitsDocuments | ||
module Utilities | ||
module Helpers | ||
FILENAME_EXTENSION_MATCHER = /\.\w*$/ | ||
OBFUSCATED_CHARACTER_MATCHER = /[a-zA-Z\d]/ | ||
|
||
def self.generate_obscured_file_name(original_filename) | ||
extension = original_filename[FILENAME_EXTENSION_MATCHER] | ||
filename_without_extension = original_filename.gsub(FILENAME_EXTENSION_MATCHER, '') | ||
|
||
if filename_without_extension.length > 5 | ||
# Obfuscate with the letter 'X'; we cannot obfuscate with special characters such as an asterisk, | ||
# as these filenames appear in VA Notify Mailers and their templating engine uses markdown. | ||
# Therefore, special characters can be interpreted as markdown and introduce formatting issues in the mailer | ||
obfuscated_portion = filename_without_extension[3..-3].gsub(OBFUSCATED_CHARACTER_MATCHER, 'X') | ||
filename_without_extension[0..2] + obfuscated_portion + filename_without_extension[-2..] + extension | ||
else | ||
original_filename | ||
end | ||
end | ||
end | ||
end | ||
end |
67 changes: 67 additions & 0 deletions
67
spec/factories/lighthouse/benefits_documents/evidence_submission.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'lighthouse/benefits_documents/constants' | ||
|
||
FactoryBot.define do | ||
factory :bd_evidence_submission, class: 'EvidenceSubmission' do | ||
association :user_account, factory: :user_account | ||
created_at { DateTime.now.utc } | ||
end | ||
|
||
factory :bd_evidence_submission_timeout, class: 'EvidenceSubmission' do | ||
association :user_account, factory: :user_account | ||
created_at { DateTime.new(1985, 10, 26).utc } | ||
end | ||
|
||
factory :bd_evidence_submission_pending, class: 'EvidenceSubmission' do | ||
association :user_account, factory: :user_account | ||
created_at { DateTime.now.utc } | ||
upload_status { BenefitsDocuments::Constants::UPLOAD_STATUS[:PENDING] } | ||
template_metadata_ciphertext do | ||
{ 'personalisation' => { | ||
'first_name' => 'test', | ||
'document_type' => 'L014', | ||
'file_name' => 'testfile.txt', | ||
'obfuscated_file_name' => 'tesXXile.txt', | ||
'date_submitted' => DateTime.now.utc.to_s, | ||
'date_failed' => nil | ||
} }.to_json | ||
end | ||
end | ||
|
||
factory :bd_evidence_submission_failed, class: 'EvidenceSubmission' do | ||
association :user_account, factory: :user_account | ||
created_at { DateTime.now.utc } | ||
upload_status { BenefitsDocuments::Constants::UPLOAD_STATUS[:FAILED] } | ||
job_class { 'Lighthouse::EvidenceSubmissions::DocumentUpload' } | ||
template_metadata_ciphertext do | ||
{ 'personalisation' => { | ||
'first_name' => 'test', | ||
'document_type' => 'L014', | ||
'file_name' => 'test.txt', | ||
'obfuscated_file_name' => 'tesXXile.txt', | ||
'date_submitted' => DateTime.now.utc.to_s, | ||
'date_failed' => DateTime.now.utc.to_s | ||
} }.to_json | ||
end | ||
end | ||
|
||
factory :bd_evidence_submission_failed_va_notify_email_enqueued, class: 'EvidenceSubmission' do | ||
association :user_account, factory: :user_account | ||
created_at { 5.days.ago } | ||
upload_status { BenefitsDocuments::Constants::UPLOAD_STATUS[:FAILED] } | ||
job_class { 'Lighthouse::EvidenceSubmissions::DocumentUpload' } | ||
va_notify_id { 123 } | ||
va_notify_date { DateTime.now.utc } | ||
end | ||
|
||
factory :bd_evidence_submission_failed_va_notify_email_queued, class: 'EvidenceSubmission' do | ||
association :user_account, factory: :user_account | ||
created_at { 5.days.ago } | ||
upload_status { BenefitsDocuments::Constants::UPLOAD_STATUS[:FAILED] } | ||
job_class { 'Lighthouse::EvidenceSubmissions::DocumentUpload' } | ||
va_notify_id { 123 } | ||
va_notify_date { DateTime.now.utc } | ||
va_notify_status { 'success' } | ||
end | ||
end |
103 changes: 103 additions & 0 deletions
103
...lighthouse/benefits_claims/documents/lighthouse_document_upload_status_polling_failed.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.