Skip to content

Commit 7b66604

Browse files
authored
99558: Migrate burial form profile logic to module (#20877)
* 99558: Migrate burial form profile logic to module * 99558: Fix form profile spec
1 parent ff707e9 commit 7b66604

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed

app/models/form_profile.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def self.prefill_enabled_forms
182182
#
183183
def self.prepend_module(form_class, form_id)
184184
namespaces = {
185-
'21P-527EZ' => 'Pensions'
185+
'21P-527EZ' => 'Pensions',
186+
'21P-530EZ' => 'Burials'
186187
}
187188

188189
namespace = namespaces[form_id]

config/features.yml

+3
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,9 @@ features:
18801880
burial_browser_monitoring_enabled:
18811881
actor_type: user
18821882
description: Burial Datadog RUM monitoring
1883+
burial_form_profile_module_enabled:
1884+
actor_type: user
1885+
description: Use the module version of the FormProfile
18831886
pension_form_enabled:
18841887
actor_type: user
18851888
description: Enable the pension form
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
require 'iso_country_codes'
4+
5+
module Burials
6+
# extends app/models/form_profile.rb, which handles form prefill
7+
class FormProfiles::VA21p530ez < FormProfile
8+
##
9+
# Returns metadata related to the form profile
10+
#
11+
# @return [Hash]
12+
def metadata
13+
{
14+
version: 0,
15+
prefill: true,
16+
returnUrl: '/claimant-information'
17+
}
18+
end
19+
20+
##
21+
# Prefills the form data with identity and contact information
22+
#
23+
# This method initializes identity and contact information, converts the country code
24+
# to ISO2 format if present, and maps data according to form-specific mappings
25+
#
26+
# @return [Hash]
27+
def prefill
28+
@identity_information = initialize_identity_information
29+
@contact_information = initialize_contact_information
30+
if @contact_information&.address&.country.present?
31+
@contact_information.address.country = convert_to_iso2(@contact_information.address.country)
32+
end
33+
34+
mappings = self.class.mappings_for_form(form_id)
35+
36+
form_data = generate_prefill(mappings) if FormProfile.prefill_enabled_forms.include?(form_id)
37+
38+
{ form_data:, metadata: }
39+
end
40+
41+
private
42+
43+
##
44+
# Converts a country code to ISO2 format
45+
#
46+
# @param country_code [String]
47+
# @return [String]
48+
def convert_to_iso2(country_code)
49+
code = IsoCountryCodes.find(country_code)
50+
code.alpha3
51+
end
52+
end
53+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe Burials::FormProfiles::VA21p530ez, type: :model do
6+
subject { described_class.new(form_id: form_id, user: user) }
7+
8+
let(:user) { build(:user, :loa3) }
9+
let(:form_id) { '21P-530EZ' }
10+
let(:address) { instance_double(Address, country: 'USA') }
11+
12+
before do
13+
allow(FormProfile).to receive(:prefill_enabled_forms).and_return([form_id])
14+
end
15+
16+
describe '#metadata' do
17+
it 'returns correct metadata' do
18+
expect(subject.metadata).to eq(
19+
version: 0,
20+
prefill: true,
21+
returnUrl: '/claimant-information'
22+
)
23+
24+
subject.metadata
25+
end
26+
end
27+
28+
describe '#prefill' do
29+
it 'initializes identity and contact information' do
30+
expect(subject.prefill).to match({
31+
form_data: {
32+
'claimantFullName' =>
33+
{ 'first' => 'Abraham', 'last' => 'Lincoln', 'suffix' => 'Jr.' },
34+
'claimantAddress' =>
35+
{ 'street' => '140 Rock Creek Rd', 'city' => 'Washington', 'state' => 'DC',
36+
'country' => 'USA', 'postalCode' => '20011' },
37+
'claimantPhone' => '3035551234',
38+
'claimantEmail' => kind_of(String)
39+
},
40+
metadata: { version: 0, prefill: true, returnUrl: '/claimant-information' }
41+
})
42+
end
43+
end
44+
end

spec/models/form_profile_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,8 @@ def expect_prefilled(form_id)
20302030
before do
20312031
allow_any_instance_of(FormProfiles::VA21p530ez)
20322032
.to receive(:initialize_contact_information).and_return(FormContactInformation.new)
2033+
allow_any_instance_of(Burials::FormProfiles::VA21p530ez)
2034+
.to receive(:initialize_contact_information).and_return(FormContactInformation.new)
20332035
end
20342036

20352037
it "doesn't throw an exception" do

0 commit comments

Comments
 (0)