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

Begin adding notification_first_name to Simple Forms models #20376

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ def initialize(data)
@data = data
@signature_date = Time.current.in_time_zone('America/Chicago')
end

def notification_first_name
data.dig('veteran_full_name', 'first')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Do you want to use the instance variable @data just to be consistent with the other notification_first_name method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'd rather change the others to be data (lose the @) since it's an attribute anyway. I'll update.

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def metadata
}
end

def notification_first_name
data.dig('full_name', 'first')
end

def zip_code_is_us_based
@data.dig('address', 'country') == 'USA'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def metadata
}
end

def notification_first_name
if @data['preparer_type'] == 'veteran'
@data.dig('veteran_full_name', 'first')
elsif @data['preparer_type'] == 'non-veteran'
@data.dig('non_veteran_full_name', 'first')
else
@data.dig('third_party_full_name', 'first')
end
end

def zip_code_is_us_based
@data.dig('veteran_mailing_address', 'country') == 'USA' ||
@data.dig('non_veteran_mailing_address', 'country') == 'USA'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def metadata
}
end

def notification_first_name
if @data['authorizer_type'] == 'veteran'
@data.dig('veteran_full_name', 'first')
elsif @data['authorizer_type'] == 'nonVeteran'
@data.dig('authorizer_full_name', 'first')
end
end

def zip_code_is_us_based
@data.dig('authorizer_address',
'country') == 'USA' || @data.dig('person_address',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def metadata
}
end

def notification_first_name
if @data['preparer_identification'] == 'SURVIVING_DEPENDENT'
@data.dig('surviving_dependent_full_name', 'first')
else
@data.dig('veteran_full_name', 'first')
end
end

def zip_code_is_us_based
@data.dig('veteran_mailing_address',
'country') == 'USA' || @data.dig('surviving_dependent_mailing_address', 'country') == 'USA'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def metadata
}
end

def notification_first_name
@data.dig('preparer_full_name', 'first')
end

def zip_code_is_us_based
@data.dig('preparer_address', 'country') == 'USA'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def metadata
}
end

def notification_first_name
if @data['claim_ownership'] == 'self' && @data['claimant_type'] == 'veteran'
@data.dig('veteran_full_name', 'first')
elsif @data['claim_ownership'] == 'self' && @data['claimant_type'] == 'non-veteran'
@data.dig('claimant_full_name', 'first')
elsif @data['claim_ownership'] == 'third-party'
@data.dig('witness_full_name', 'first')
end
end

def zip_code_is_us_based
@data.dig('veteran_mailing_address', 'country') == 'USA'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def metadata
}
end

def notification_first_name
@data.dig('veteran', 'full_name', 'first')
end

def zip_code_is_us_based
@data.dig('veteran', 'address', 'country') == 'USA'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def metadata
}
end

def notification_first_name
@data.dig('preparer_name', 'first')
end

def zip_code_is_us_based
@data.dig('preparer_address', 'country') == 'USA'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def metadata
}
end

def notification_first_name
@data.dig('veteran', 'full_name', 'first')
end

def zip_code_is_us_based
@data.dig('veteran', 'address', 'country') == 'USA'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def metadata
}
end

def notification_first_name
data.dig('applicant_full_name', 'first')
end

def veteran_name
first_name = data.dig('veteran_full_name', 'first') || ''
middle_name = data.dig('veteran_full_name', 'middle') || ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'json'

module SimpleFormsApi
# rubocop:disable Metrics/ClassLength
Copy link
Contributor

Choose a reason for hiding this comment

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

@Thrillberg, can you look into getting this file under 400 lines?

May I suggest moving the contents of create_attachment_page to a new model

module SimpleFormsApi
  module VBA4010007
    class Attachment

      attr_reader :file_path, :data

      def initialize(file_path:, data:)
        @file_path = file_path
        @data = @data
      end

      def create
        veteran_sex = get_gender(@data.dig('application', 'veteran', 'gender'))
        # etc etc 

then you can do this in the form model

def create_attachment_page(file_path)
  SimpleFormsApi::VBA4010007::Attachment.new(file_path:, data: @data).create
end

class VBA4010007 < BaseForm
STATS_KEY = 'api.simple_forms_api.40_10007'

Expand Down Expand Up @@ -39,6 +40,16 @@ def metadata
}
end

def notification_first_name
applicant_relationship = @data.dig('application', 'applicant', 'applicant_relationship_to_claimant')

if applicant_relationship == 'Self'
@data.dig('application', 'claimant', 'name', 'first')
else
@data.dig('application', 'applicant', 'name', 'first')
end
end

def zip_code_is_us_based
# TODO: Implement this
true
Expand Down Expand Up @@ -475,4 +486,5 @@ def get_attachments
attachments
end
end
# rubocop:enable Metrics/ClassLength
end
18 changes: 18 additions & 0 deletions modules/simple_forms_api/spec/models/base_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe SimpleFormsApi::BaseForm do
describe '#notification_first_name' do
it 'returns the first name to be used in notifications' do
data = {
'veteran_full_name' => {
'first' => 'Veteran',
'last' => 'Eteranvay'
}
}

expect(described_class.new(data).notification_first_name).to eq 'Veteran'
end
end
end
23 changes: 23 additions & 0 deletions modules/simple_forms_api/spec/models/vba_20_10206_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'
require_relative '../support/shared_examples_for_base_form'

RSpec.describe SimpleFormsApi::VBA2010206 do
it_behaves_like 'zip_code_is_us_based', %w[address]

describe '#notification_first_name' do
let(:data) do
{
'full_name' => {
'first' => 'Veteran',
'last' => 'Eteranvay'
}
}
end

it 'returns the first name to be used in notifications' do
expect(described_class.new(data).notification_first_name).to eq 'Veteran'
end
end
end
50 changes: 50 additions & 0 deletions modules/simple_forms_api/spec/models/vba_20_10207_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,54 @@
end
end
end

describe '#notification_first_name' do
context 'preparer is veteran' do
let(:data) do
{
'preparer_type' => 'veteran',
'veteran_full_name' => {
'first' => 'Veteran',
'last' => 'Eteranvay'
}
}
end

it 'returns the veteran first name' do
expect(described_class.new(data).notification_first_name).to eq 'Veteran'
end
end

context 'preparer is non-veteran' do
let(:data) do
{
'preparer_type' => 'non-veteran',
'non_veteran_full_name' => {
'first' => 'Non-Veteran',
'last' => 'Eteranvay'
}
}
end

it 'returns the non-veteran first name' do
expect(described_class.new(data).notification_first_name).to eq 'Non-Veteran'
end
end

context 'preparer is third party' do
let(:data) do
{
'preparer_type' => 'third-party',
'third_party_full_name' => {
'first' => 'Third Party',
'last' => 'Eteranvay'
}
}
end

it 'returns the third party first name' do
expect(described_class.new(data).notification_first_name).to eq 'Third Party'
end
end
end
end
34 changes: 34 additions & 0 deletions modules/simple_forms_api/spec/models/vba_21_0845_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,38 @@

RSpec.describe SimpleFormsApi::VBA210845 do
it_behaves_like 'zip_code_is_us_based', %w[authorizer_address person_address organization_address]

describe '#notification_first_name' do
context 'preparer is veteran' do
let(:data) do
{
'authorizer_type' => 'veteran',
'veteran_full_name' => {
'first' => 'Veteran',
'last' => 'Eteranvay'
}
}
end

it 'returns the veteran first name' do
expect(described_class.new(data).notification_first_name).to eq 'Veteran'
end
end

context 'preparer is non-veteran' do
let(:data) do
{
'authorizer_type' => 'nonVeteran',
'authorizer_full_name' => {
'first' => 'Authorizer',
'last' => 'Eteranvay'
}
}
end

it 'returns the non-veteran first name' do
expect(described_class.new(data).notification_first_name).to eq 'Authorizer'
end
end
end
end
34 changes: 34 additions & 0 deletions modules/simple_forms_api/spec/models/vba_21_0966_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,38 @@
end
end
end

describe '#notification_first_name' do
context 'preparer is surviving dependent' do
let(:data) do
{
'preparer_identification' => 'SURVIVING_DEPENDENT',
'surviving_dependent_full_name' => {
'first' => 'Surviving',
'last' => 'Dependent'
}
}
end

it 'returns the surviving dependent first name' do
expect(described_class.new(data).notification_first_name).to eq 'Surviving'
end
end

context 'preparer is not the surviving dependent' do
let(:data) do
{
'preparer_identification' => 'VETERAN',
'veteran_full_name' => {
'first' => 'Veteran',
'last' => 'Eteranvay'
}
}
end

it 'returns the veteran first name' do
expect(described_class.new(data).notification_first_name).to eq 'Veteran'
end
end
end
end
23 changes: 23 additions & 0 deletions modules/simple_forms_api/spec/models/vba_21_0972_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'
require_relative '../support/shared_examples_for_base_form'

RSpec.describe SimpleFormsApi::VBA210972 do
it_behaves_like 'zip_code_is_us_based', %w[preparer_address]

describe '#notification_first_name' do
let(:data) do
{
'preparer_full_name' => {
'first' => 'Veteran',
'last' => 'Eteranvay'
}
}
end

it 'returns the first name to be used in notifications' do
expect(described_class.new(data).notification_first_name).to eq 'Veteran'
end
end
end
Loading
Loading