Skip to content

Commit 7640b4c

Browse files
Send 20-10207 emails to point of contact, when necessary (#21575)
* Send 20-10207 emails to point of contact, when necessary * test coverage * progress * test * Add test --------- Co-authored-by: stevenjcumming <134282106+stevenjcumming@users.noreply.github.com>
1 parent 73da1ec commit 7640b4c

File tree

8 files changed

+254
-8
lines changed

8 files changed

+254
-8
lines changed

modules/simple_forms_api/app/models/simple_forms_api/base_form.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ def notification_first_name
2020
def notification_email_address
2121
data.dig('veteran', 'email')
2222
end
23+
24+
def should_send_to_point_of_contact?
25+
false
26+
end
2327
end
2428
end

modules/simple_forms_api/app/models/simple_forms_api/vba_20_10207.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,19 @@ def notification_first_name
7373
end
7474
end
7575

76+
def notification_last_name
77+
if data['preparer_type'] == 'veteran'
78+
data.dig('veteran_full_name', 'last')
79+
elsif data['preparer_type'] == 'non-veteran'
80+
data.dig('non_veteran_full_name', 'last')
81+
else
82+
data.dig('third_party_full_name', 'last')
83+
end
84+
end
85+
7686
def notification_email_address
87+
return data['point_of_contact_email'] if should_send_to_point_of_contact?
88+
7789
if data['preparer_type'] == 'veteran'
7890
data['veteran_email_address']
7991
elsif data['preparer_type'] == 'non-veteran'
@@ -83,6 +95,10 @@ def notification_email_address
8395
end
8496
end
8597

98+
def notification_point_of_contact_name
99+
data['point_of_contact_name']
100+
end
101+
86102
def zip_code_is_us_based
87103
@data.dig('veteran_mailing_address', 'country') == 'USA' ||
88104
@data.dig('non_veteran_mailing_address', 'country') == 'USA'
@@ -133,6 +149,10 @@ def get_attachments
133149
PersistentAttachment.where(guid: attachment_guids).map(&:to_pdf)
134150
end
135151

152+
def should_send_to_point_of_contact?
153+
preparer_is_not_third_party? && living_situation_is_none?
154+
end
155+
136156
private
137157

138158
def attachment_guids
@@ -196,5 +216,13 @@ def non_veteran_phone
196216
data['non_veteran_phone']&.gsub('-', '')&.[](6..9)
197217
]
198218
end
219+
220+
def preparer_is_not_third_party?
221+
%w[third-party-veteran third-party-non-veteran].exclude?(data['preparer_type'])
222+
end
223+
224+
def living_situation_is_none?
225+
data.dig('living_situation', 'NONE')
226+
end
199227
end
200228
end

modules/simple_forms_api/app/services/simple_forms_api/notification/email.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ def initialize(config, notification_type: :confirmation, user: nil, user_account
3030

3131
def send(at: nil)
3232
return unless flipper?
33-
34-
template_id_suffix = TEMPLATE_IDS[form_number][notification_type.to_s]
35-
template_id = Settings.vanotify.services.va_gov.template_id[template_id_suffix]
3633
return unless template_id
3734

3835
scheduled_at = at
@@ -86,6 +83,14 @@ def flipper?
8683
Flipper.enabled?(:"form#{number.gsub('vba_', '')}_confirmation_email")
8784
end
8885

86+
def template_id
87+
template_id_suffix = TEMPLATE_IDS[form_number][notification_type.to_s]
88+
if form.should_send_to_point_of_contact?
89+
template_id_suffix = TEMPLATE_IDS['vba_20_10207']['point_of_contact_error']
90+
end
91+
@_template_id ||= Settings.vanotify.services.va_gov.template_id[template_id_suffix]
92+
end
93+
8994
def enqueue_email(at, template_id)
9095
email_from_form_data = form.notification_email_address
9196

modules/simple_forms_api/app/services/simple_forms_api/notification/personalization.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def to_hash
2323
personalization['lighthouse_updated_at'] = lighthouse_updated_at if lighthouse_updated_at
2424
personalization['confirmation_number'] = confirmation_number if confirmation_number
2525
personalization.merge!(form21_0966_personalization) if form.instance_of? SimpleFormsApi::VBA210966
26+
27+
if form.should_send_to_point_of_contact?
28+
personalization.merge!(
29+
'poc_first_name_last_name' => form.notification_point_of_contact_name,
30+
'last_name' => form.notification_last_name
31+
)
32+
end
2633
end
2734
end
2835
end

modules/simple_forms_api/spec/models/base_form_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@
2323
expect(described_class.new(data).notification_email_address).to eq 'a@b.com'
2424
end
2525
end
26+
27+
describe '#should_send_to_point_of_contact?' do
28+
it 'returns false' do
29+
expect(described_class.new({}).should_send_to_point_of_contact?).to be false
30+
end
31+
end
2632
end

modules/simple_forms_api/spec/models/vba_20_10207_spec.rb

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
require 'rails_helper'
44
require_relative '../support/shared_examples_for_base_form'
55

6+
RSpec.shared_examples 'point_of_contact_email' do
7+
context 'should use point of contact email' do
8+
let(:email) { 'pointy@contact.com' }
9+
10+
before do
11+
data.merge!(
12+
{
13+
'living_situation' => { 'NONE' => true },
14+
'point_of_contact_email' => email
15+
}
16+
)
17+
end
18+
19+
it 'returns the point of contact email' do
20+
expect(described_class.new(data).notification_email_address).to eq email
21+
end
22+
end
23+
end
24+
625
RSpec.describe SimpleFormsApi::VBA2010207 do
726
it_behaves_like 'zip_code_is_us_based', %w[veteran_mailing_address non_veteran_mailing_address]
827

@@ -141,6 +160,56 @@
141160
end
142161
end
143162

163+
describe '#notification_last_name' do
164+
context 'preparer is veteran' do
165+
let(:data) do
166+
{
167+
'preparer_type' => 'veteran',
168+
'veteran_full_name' => {
169+
'first' => 'Veteran',
170+
'last' => 'Eteranvay'
171+
}
172+
}
173+
end
174+
175+
it 'returns the veteran last name' do
176+
expect(described_class.new(data).notification_last_name).to eq 'Eteranvay'
177+
end
178+
end
179+
180+
context 'preparer is non-veteran' do
181+
let(:data) do
182+
{
183+
'preparer_type' => 'non-veteran',
184+
'non_veteran_full_name' => {
185+
'first' => 'Non-Veteran',
186+
'last' => 'Eteranvay'
187+
}
188+
}
189+
end
190+
191+
it 'returns the non-veteran last name' do
192+
expect(described_class.new(data).notification_last_name).to eq 'Eteranvay'
193+
end
194+
end
195+
196+
context 'preparer is third party' do
197+
let(:data) do
198+
{
199+
'preparer_type' => 'third-party',
200+
'third_party_full_name' => {
201+
'first' => 'Third Party',
202+
'last' => 'Eteranvay'
203+
}
204+
}
205+
end
206+
207+
it 'returns the third party last name' do
208+
expect(described_class.new(data).notification_last_name).to eq 'Eteranvay'
209+
end
210+
end
211+
end
212+
144213
describe '#notification_email_address' do
145214
context 'preparer is veteran' do
146215
let(:data) do
@@ -153,6 +222,8 @@
153222
it 'returns the veteran email address' do
154223
expect(described_class.new(data).notification_email_address).to eq 'a@b.com'
155224
end
225+
226+
it_behaves_like 'point_of_contact_email'
156227
end
157228

158229
context 'preparer is non-veteran' do
@@ -166,6 +237,8 @@
166237
it 'returns the non-veteran email address' do
167238
expect(described_class.new(data).notification_email_address).to eq 'a@b.com'
168239
end
240+
241+
it_behaves_like 'point_of_contact_email'
169242
end
170243

171244
context 'preparer is third party' do
@@ -181,4 +254,63 @@
181254
end
182255
end
183256
end
257+
258+
describe '#notification_point_of_contact_name' do
259+
let(:name) { 'Pointy Contact' }
260+
let(:data) do
261+
{ 'point_of_contact_name' => name }
262+
end
263+
264+
it 'returns the point of contact name' do
265+
expect(described_class.new(data).notification_point_of_contact_name).to eq name
266+
end
267+
end
268+
269+
describe '#should_send_to_point_of_contact?' do
270+
let(:data) { {} }
271+
272+
context 'preparer is not third party' do
273+
%w[veteran non-veteran].each do |preparer_type|
274+
before { data['preparer_type'] = preparer_type }
275+
276+
context 'living situation is NONE' do
277+
before { data['living_situation'] = { 'NONE' => true } }
278+
279+
it 'returns true' do
280+
expect(described_class.new(data).should_send_to_point_of_contact?).to be true
281+
end
282+
end
283+
284+
context 'living situation is not NONE' do
285+
before { data['living_situation'] = { 'NONE' => false } }
286+
287+
it 'returns false' do
288+
expect(described_class.new(data).should_send_to_point_of_contact?).to be false
289+
end
290+
end
291+
end
292+
end
293+
294+
context 'preparer is third party' do
295+
%w[third-party-non-veteran third-party-veteran].each do |preparer_type|
296+
before { data['preparer_type'] = preparer_type }
297+
298+
context 'living situation is NONE' do
299+
before { data['living_situation'] = { 'NONE' => true } }
300+
301+
it 'returns false' do
302+
expect(described_class.new(data).should_send_to_point_of_contact?).to be false
303+
end
304+
end
305+
306+
context 'living situation is not NONE' do
307+
before { data['living_situation'] = { 'NONE' => false } }
308+
309+
it 'returns false' do
310+
expect(described_class.new(data).should_send_to_point_of_contact?).to be false
311+
end
312+
end
313+
end
314+
end
315+
end
184316
end

modules/simple_forms_api/spec/services/notification/email_spec.rb

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,16 @@
132132
before do
133133
stub_const(
134134
'SimpleFormsApi::Notification::Email::TEMPLATE_IDS',
135-
{ 'vba_21_10210' => {
136-
'confirmation' => template_id_suffix,
137-
'error' => template_id_suffix,
138-
'received' => template_id_suffix
139-
} }
135+
{
136+
'vba_21_10210' => {
137+
'confirmation' => template_id_suffix,
138+
'error' => template_id_suffix,
139+
'received' => template_id_suffix
140+
},
141+
'vba_20_10207' => {
142+
'point_of_contact_error' => template_id_suffix
143+
}
144+
}
140145
)
141146
allow(Settings).to receive(:vanotify).and_return(vanotify_settings)
142147
allow(vanotify_settings).to receive(:services).and_return(vanotify_services)
@@ -152,6 +157,39 @@
152157

153158
expect(VANotify::EmailJob).to have_received(:perform_async).with(anything, template_id, anything)
154159
end
160+
161+
describe 'form 20-10207 point of contact', if: notification_type == :error do
162+
before { config[:form_number] = 'vba_20_10207' }
163+
164+
context 'data includes point of contact email' do
165+
let(:point_of_contact_email) { 'a@b.com' }
166+
let(:data) do
167+
fixture_path = Rails.root.join(
168+
'modules', 'simple_forms_api', 'spec', 'fixtures', 'form_json', 'vba_20_10207.json'
169+
)
170+
data = JSON.parse(fixture_path.read)
171+
data.merge!(
172+
{
173+
'point_of_contact_email' => point_of_contact_email,
174+
'living_situation' => { 'NONE' => true }
175+
}
176+
)
177+
end
178+
179+
it 'sends the email to the point of contact email' do
180+
allow(VANotify::EmailJob).to receive(:perform_async)
181+
subject = described_class.new(config, notification_type:)
182+
183+
subject.send
184+
185+
expect(VANotify::EmailJob).to have_received(:perform_async).with(
186+
point_of_contact_email,
187+
template_id,
188+
anything
189+
)
190+
end
191+
end
192+
end
155193
end
156194

157195
context 'success' do

modules/simple_forms_api/spec/services/notification/personalization_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@
3131
end
3232
end
3333

34+
context 'should send to point of contact' do
35+
let(:form) do
36+
SimpleFormsApi::VBA2010207.new(
37+
{
38+
'veteran_full_name' => { 'first' => 'John', 'last' => 'Doe' },
39+
'preparer_type' => 'veteran',
40+
'living_situation' => { 'NONE' => true },
41+
'point_of_contact_name' => 'Pointy McContact'
42+
}
43+
)
44+
end
45+
46+
it 'returns a hash with point of contact fields' do
47+
personalization = described_class.new(form:, config:)
48+
49+
expect(personalization.to_hash).to eq(
50+
{
51+
'first_name' => 'John',
52+
'last_name' => 'Doe',
53+
'date_submitted' => date_submitted,
54+
'poc_first_name_last_name' => 'Pointy McContact'
55+
}
56+
)
57+
end
58+
end
59+
3460
context 'other forms' do
3561
let(:form) { SimpleFormsApi::VBA2010206.new({ 'full_name' => { 'first' => 'john' } }) }
3662

0 commit comments

Comments
 (0)