-
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.
Log whenever Form Upload Flow prefill data is changed
- Loading branch information
1 parent
05b17dc
commit 656f4cb
Showing
4 changed files
with
173 additions
and
0 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
26 changes: 26 additions & 0 deletions
26
modules/simple_forms_api/app/services/simple_forms_api/prefill_data_service.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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module SimpleFormsApi | ||
class PrefillDataService | ||
attr_reader :prefill_data, :form_data, :form_id | ||
|
||
def initialize(prefill_data:, form_data:, form_id:) | ||
@prefill_data = JSON.parse(prefill_data) | ||
@form_data = form_data | ||
@form_id = form_id | ||
end | ||
|
||
def check_for_changes | ||
changed_fields = [] | ||
changed_fields << 'first_name' if prefill_data.dig('full_name', 'first') != form_data.dig('full_name', 'first') | ||
changed_fields << 'last_name' if prefill_data.dig('full_name', 'last') != form_data.dig('full_name', 'last') | ||
changed_fields << 'postal_code' if prefill_data.dig('address', 'postal_code') != form_data['postal_code'] | ||
changed_fields << 'ssn' if prefill_data.dig('veteran', 'ssn') != form_data.dig('id_number', 'ssn') | ||
changed_fields << 'email' if prefill_data['email'] != form_data['email'] | ||
|
||
changed_fields.each do |field| | ||
Rails.logger.info('Simple forms api - Form Upload Flow changed data', { field:, form_id: }) | ||
end | ||
end | ||
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
113 changes: 113 additions & 0 deletions
113
modules/simple_forms_api/spec/services/prefill_data_service_spec.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,113 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require SimpleFormsApi::Engine.root.join('spec', 'spec_helper.rb') | ||
|
||
describe SimpleFormsApi::PrefillDataService do | ||
describe '#check_for_changes' do | ||
let(:form_id) { '21-0779' } | ||
let(:rails_logger) { double } | ||
let(:prefill_data) do | ||
{ | ||
'full_name' => { | ||
'first' => 'fake-first-name', | ||
'last' => 'fake-last-name' | ||
}, | ||
'address' => { | ||
'postal_code' => '12345' | ||
}, | ||
'veteran' => { | ||
'ssn' => 'fake-ssn' | ||
}, | ||
'email' => 'fake-email' | ||
} | ||
end | ||
let(:form_data) do | ||
{ | ||
'full_name' => { | ||
'first' => 'fake-first-name', | ||
'last' => 'fake-last-name' | ||
}, | ||
'postal_code' => '12345', | ||
'id_number' => { | ||
'ssn' => 'fake-ssn' | ||
}, | ||
'email' => 'fake-email' | ||
} | ||
end | ||
let(:prefill_data_service) do | ||
SimpleFormsApi::PrefillDataService.new( | ||
prefill_data: prefill_data.to_json, form_data: modified_form_data, | ||
form_id: | ||
) | ||
end | ||
|
||
before { allow(Rails).to receive(:logger).and_return(rails_logger) } | ||
|
||
context 'first_name does not match' do | ||
let(:modified_form_data) do | ||
form_data.merge({ 'full_name' => { | ||
'first' => 'new-first-name', | ||
'last' => 'fake-last-name' | ||
} }) | ||
end | ||
|
||
it 'logs the first_name change' do | ||
expect(rails_logger).to receive(:info).with(anything, { field: 'first_name', form_id: }) | ||
|
||
prefill_data_service.check_for_changes | ||
end | ||
end | ||
|
||
context 'last_name does not match' do | ||
let(:modified_form_data) do | ||
form_data.merge({ 'full_name' => { | ||
'first' => 'fake-first-name', | ||
'last' => 'new-last-name' | ||
} }) | ||
end | ||
|
||
it 'logs the last_name change' do | ||
expect(rails_logger).to receive(:info).with(anything, { field: 'last_name', form_id: }) | ||
|
||
prefill_data_service.check_for_changes | ||
end | ||
end | ||
|
||
context 'postal_code does not match' do | ||
let(:modified_form_data) do | ||
form_data.merge({ 'postal_code' => '67890' }) | ||
end | ||
|
||
it 'logs the postal_code change' do | ||
expect(rails_logger).to receive(:info).with(anything, { field: 'postal_code', form_id: }) | ||
|
||
prefill_data_service.check_for_changes | ||
end | ||
end | ||
|
||
context 'ssn does not match' do | ||
let(:modified_form_data) do | ||
form_data.merge({ 'id_number' => { 'ssn' => 'new-ssn' } }) | ||
end | ||
|
||
it 'logs the ssn change' do | ||
expect(rails_logger).to receive(:info).with(anything, { field: 'ssn', form_id: }) | ||
|
||
prefill_data_service.check_for_changes | ||
end | ||
end | ||
|
||
context 'email does not match' do | ||
let(:modified_form_data) do | ||
form_data.merge({ 'email' => 'new-email' }) | ||
end | ||
|
||
it 'logs the email change' do | ||
expect(rails_logger).to receive(:info).with(anything, { field: 'email', form_id: }) | ||
|
||
prefill_data_service.check_for_changes | ||
end | ||
end | ||
end | ||
end |