From 168ebe7467bcd10d527f5db09e185dfe772af90c Mon Sep 17 00:00:00 2001 From: Holden Hinkle Date: Thu, 16 Jan 2025 10:37:50 -0500 Subject: [PATCH 01/16] make sure active record throws an error if org can't be found --- modules/veteran/app/sidekiq/organizations/queue_updates.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/veteran/app/sidekiq/organizations/queue_updates.rb b/modules/veteran/app/sidekiq/organizations/queue_updates.rb index 4ae64a29732..ba86e7ddf86 100644 --- a/modules/veteran/app/sidekiq/organizations/queue_updates.rb +++ b/modules/veteran/app/sidekiq/organizations/queue_updates.rb @@ -51,7 +51,7 @@ def queue_address_updates(data) def rows_to_process(rows) rows.map do |row| - org = Veteran::Service::Organization.find_by(poa: row[:id]) + org = Veteran::Service::Organization.find_by!(poa: row[:id]) diff = org.diff(row) row.merge(diff.merge({ address_exists: org.location.present? })) if diff.values.any? rescue ActiveRecord::RecordNotFound => e From 14ef50d1c3f59933fb8aef114f7f915288150e66 Mon Sep 17 00:00:00 2001 From: Holden Hinkle Date: Thu, 16 Jan 2025 10:38:17 -0500 Subject: [PATCH 02/16] update some keys --- modules/veteran/app/sidekiq/organizations/update.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 9582a4ecb29..51a4799cecc 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -37,9 +37,8 @@ def process_org_data(org_data) # rubocop:disable Metrics/MethodLength address_validation_api_response = nil if org_data['address_changed'] - api_response = if Flipper.enabled?(:va_v3_contact_information_service) - get_best_address_candidate(org_data) + get_best_address_candidate(org_data['address']) else get_best_address_candidate(org_data['address']) end @@ -73,8 +72,8 @@ def record_can_be_updated?(org_data) def build_validation_address(address) if Flipper.enabled?(:va_v3_contact_information_service) validation_model = VAProfile::Models::V3::ValidationAddress - state_code = address['state']['state_code'] - city = address['city_name'] + state_code = address['state_province']['state_code'] + city = address['city'] else validation_model = VAProfile::Models::ValidationAddress state_code = address['state_province']['code'] From 07d74038a2d4f4d3c1f50096d71901539ebe247a Mon Sep 17 00:00:00 2001 From: Holden Hinkle Date: Thu, 16 Jan 2025 19:18:30 -0500 Subject: [PATCH 03/16] wip --- .../app/sidekiq/organizations/update.rb | 32 ++++++++----------- .../organizations/xlsx_file_processor.rb | 3 +- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 51a4799cecc..858f7b9f4c3 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -31,19 +31,15 @@ def perform(orgs_json) # If the address validation fails or an error occurs during the update, the error is logged and the process # is halted for the current organization. # @param org_data [Hash] The organization data including id and address. - def process_org_data(org_data) # rubocop:disable Metrics/MethodLength + def process_org_data(org_data) return unless record_can_be_updated?(org_data) address_validation_api_response = nil if org_data['address_changed'] - api_response = if Flipper.enabled?(:va_v3_contact_information_service) - get_best_address_candidate(org_data['address']) - else - get_best_address_candidate(org_data['address']) - end + api_response = get_best_address_candidate(org_data['address']) - # don't update the record if there is not a valid address with non-zero lat and long at this point + # Don't update the record if there is not a valid address with non-zero lat and long at this point if api_response.nil? return else @@ -70,23 +66,19 @@ def record_can_be_updated?(org_data) # @param address [Hash] A hash containing the details of the organization's address. # @return [VAProfile::Models::ValidationAddress] A validation address object ready for address validation service. def build_validation_address(address) - if Flipper.enabled?(:va_v3_contact_information_service) - validation_model = VAProfile::Models::V3::ValidationAddress - state_code = address['state_province']['state_code'] - city = address['city'] - else - validation_model = VAProfile::Models::ValidationAddress - state_code = address['state_province']['code'] - city = address['city'] - end + validation_model = if Flipper.enabled?(:va_v3_contact_information_service) + VAProfile::Models::V3::ValidationAddress + else + VAProfile::Models::ValidationAddress + end validation_model.new( address_pou: address['address_pou'], address_line1: address['address_line1'], address_line2: address['address_line2'], address_line3: address['address_line3'], - city: city, - state_code: state_code, + city: address['city'], + state_code: address['state_code']['code'], zip_code: address['zip_code5'], zip_code_suffix: address['zip_code4'], country_code_iso3: address['country_code_iso3'] @@ -137,6 +129,7 @@ def build_address_attributes(org_data, api_response) address = api_response['candidate_addresses'].first['address'] geocode = api_response['candidate_addresses'].first['geocode'] meta = api_response['candidate_addresses'].first['address_meta_data'] + build_address(address, geocode, meta).merge({ raw_address: org_data['address'].to_json }) end end @@ -277,6 +270,9 @@ def get_best_address_candidate(org_address) else original_response end + rescue => e + log_error("In #get_best_address_candidate, address: #{org_address}, error message: #{e.message}") + # puts("In #get_best_address_candidate, address: #{org_address}, error message: #{e.message}") end end end diff --git a/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb b/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb index 5ea35758498..39f0a6562ad 100644 --- a/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb +++ b/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb @@ -138,7 +138,8 @@ def process_row(row, sheet_name, column_map) address_line2: get_value(row, column_map, 'OrganizationAddressLine2'), address_line3: get_value(row, column_map, 'OrganizationAddressLine3'), city: get_value(row, column_map, 'OrganizationCity'), - state_province: { code: get_value(row, column_map, 'OrganizationState') }, + # state_province: { code: get_value(row, column_map, 'OrganizationState') }, + state_code: { code: get_value(row, column_map, 'OrganizationState') }, zip_code5:, zip_code4:, country_code_iso3: 'US' From 5fe2e09eccf2b330d8de81ce872648c01b161ede Mon Sep 17 00:00:00 2001 From: Holden Hinkle Date: Fri, 17 Jan 2025 09:50:28 -0500 Subject: [PATCH 04/16] clean up --- modules/veteran/app/sidekiq/organizations/update.rb | 1 - modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 858f7b9f4c3..c0f87f8b4f5 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -272,7 +272,6 @@ def get_best_address_candidate(org_address) end rescue => e log_error("In #get_best_address_candidate, address: #{org_address}, error message: #{e.message}") - # puts("In #get_best_address_candidate, address: #{org_address}, error message: #{e.message}") end end end diff --git a/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb b/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb index 39f0a6562ad..3ccd65af0b4 100644 --- a/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb +++ b/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb @@ -138,7 +138,6 @@ def process_row(row, sheet_name, column_map) address_line2: get_value(row, column_map, 'OrganizationAddressLine2'), address_line3: get_value(row, column_map, 'OrganizationAddressLine3'), city: get_value(row, column_map, 'OrganizationCity'), - # state_province: { code: get_value(row, column_map, 'OrganizationState') }, state_code: { code: get_value(row, column_map, 'OrganizationState') }, zip_code5:, zip_code4:, From 0804b6500d993ddf6c7096b8a2297f25bf14c34f Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Fri, 17 Jan 2025 10:39:49 -0600 Subject: [PATCH 05/16] [WIP] Fixing tests --- .../spec/sidekiq/organizations/update_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index 559179e5ef0..fe787758592 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -74,7 +74,7 @@ def create_organization address_line2: 'abc', address_line3: 'abc', city: 'abc', - state_province: { + state_code: { code: 'abc' }, zip_code5: 'abc', @@ -97,7 +97,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_province' => { + 'state_code' => { 'name' => 'New York', 'code' => 'NY' }, @@ -212,7 +212,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_province' => { + 'state_code' => { 'name' => 'New York', 'code' => 'NY' }, @@ -253,7 +253,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_province' => { + 'state_code' => { 'name' => 'New York', 'code' => 'NY' }, @@ -294,7 +294,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_province' => { + 'state_code' => { 'name' => 'New York', 'code' => 'NY' }, @@ -335,7 +335,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_province' => { + 'state_code' => { 'name' => 'New York', 'code' => 'NY' }, From 7ead3f4d4c46bb9b137787242f07fb9121ccefba Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Fri, 17 Jan 2025 13:24:06 -0600 Subject: [PATCH 06/16] Finish fixing tests --- .../app/sidekiq/organizations/update.rb | 11 +++++--- .../spec/sidekiq/organizations/update_spec.rb | 26 ++++++++++--------- .../organizations/xlsx_file_processor_spec.rb | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index c0f87f8b4f5..b808f7238a7 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -78,7 +78,7 @@ def build_validation_address(address) address_line2: address['address_line2'], address_line3: address['address_line3'], city: address['city'], - state_code: address['state_code']['code'], + state_code: address['state']['state_code'], zip_code: address['zip_code5'], zip_code_suffix: address['zip_code4'], country_code_iso3: address['country_code_iso3'] @@ -146,8 +146,8 @@ def build_address(address, geocode, meta) address_line2: address['address_line2'], address_line3: address['address_line3'], city: address['city'], - province: address['state_province']['name'], - state_code: address['state_province']['code'], + province: address['state_code']['name'], + state_code: address['state_code']['code'], zip_code: address['zip_code5'], zip_suffix: address['zip_code4'], country_code_iso3: address['country']['iso3_code'], @@ -253,6 +253,11 @@ def retry_validation(org_address) # @param org_address [Hash] the address provided by OGC # @return [Hash, Nil] the response from the address validation service def get_best_address_candidate(org_address) + if org_address.nil? + log_error('In #get_best_address_candidate, org_address is nil') + return nil + end + candidate_address = build_validation_address(org_address) original_response = validate_address(candidate_address) return nil unless address_valid?(original_response) diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index fe787758592..83382f132bf 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -74,8 +74,8 @@ def create_organization address_line2: 'abc', address_line3: 'abc', city: 'abc', - state_code: { - code: 'abc' + state: { + state_code: 'abc' }, zip_code5: 'abc', zip_code4: 'abc', @@ -483,17 +483,19 @@ def create_organization [ { id:, - address_pou: 'abc', - address_line1: 'abc', - address_line2: 'abc', - address_line3: 'abc', - city_name: 'abc', - state: { - state_code: 'abc' + address: { + address_pou: 'abc', + address_line1: 'abc', + address_line2: 'abc', + address_line3: 'abc', + city_name: 'abc', + state: { + state_code: 'abc' + }, + zip_code5: 'abc', + zip_code4: 'abc', + country_code_iso3: 'abc' }, - zip_code5: 'abc', - zip_code4: 'abc', - country_code_iso3: 'abc', email: 'test@example.com', phone_number: '999-999-9999', address_exists:, diff --git a/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb b/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb index afd9ffb4222..8de75008acf 100644 --- a/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb @@ -25,7 +25,7 @@ def check_values(hash) context 'with valid data' do let(:expected_keys) { %i[id address phone_number] } let(:expected_address_keys) do - %i[address_pou address_line1 address_line2 address_line3 city state_province zip_code5 zip_code4 + %i[address_pou address_line1 address_line2 address_line3 city state_code zip_code5 zip_code4 country_code_iso3] end From bb2cf620afc7b66328281e082cb52c6ae7b0a446 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Fri, 17 Jan 2025 14:48:45 -0600 Subject: [PATCH 07/16] [WIP] Add slack notifications --- .../app/sidekiq/organizations/update.rb | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index b808f7238a7..2ccff0ca875 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -15,14 +15,26 @@ class Update include Sidekiq::Job include SentryLogging + attr_accessor :slack_messages, :orgs_data + + def initialize + p 'slack_messages initialized' + @slack_messages = [] + p "slack_messages.size: #{@slack_messages.size}" + end + # Processes each organization's data provided in JSON format. # This method parses the JSON, validates each organization's address, and updates the database records. # @param orgs_json [String] JSON string containing an array of organization data. def perform(orgs_json) - orgs_data = JSON.parse(orgs_json) - orgs_data.each { |org_data| process_org_data(org_data) } + @orgs_data = JSON.parse(orgs_json) + @orgs_data.each { |org_data| process_org_data(org_data) } rescue => e log_error("Error processing job: #{e.message}") + ensure + p "slack_messages.size: #{@slack_messages.size}" + # p "@orgs_data: #{@orgs_data}", "@orgs_data.size: #{@orgs_data.size}" + log_to_slack(@slack_messages.join("\n")) unless @slack_messages.empty? end private @@ -184,7 +196,9 @@ def build_v3_address(address) # Logs an error to Sentry. # @param error [Exception] The error string to be logged. def log_error(error) - log_message_to_sentry("Organizations::Update: #{error}", :error) + message = "Organizations::Update: #{error}" + log_message_to_sentry(message, :error) + @slack_messages << message end # Checks if the latitude and longitude of an address are both set to zero, which are the default values @@ -278,5 +292,12 @@ def get_best_address_candidate(org_address) rescue => e log_error("In #get_best_address_candidate, address: #{org_address}, error message: #{e.message}") end + + def log_to_slack(message) + client = SlackNotify::Client.new(webhook_url: Settings.claims_api.slack.webhook_url, + channel: '#benefits-representation-management-notifications', + username: 'Organizations::Update Bot') + client.notify(message) + end end end From 0a7f7a155d947a355f03a76f4b9f2862e836d7b9 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Fri, 17 Jan 2025 15:38:34 -0600 Subject: [PATCH 08/16] [WIP] Working through slack testing impact --- modules/veteran/spec/sidekiq/organizations/update_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index 83382f132bf..fe0d9c457bc 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -133,6 +133,7 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow_any_instance_of(VAProfile::AddressValidation::Service).to receive(:candidate).and_return(api_response) + allow_any_instance_of(Faraday::Connection).to receive(:post) end context 'when JSON parsing fails' do From 2a5d7fef120f9187e1ca33cf743100e9f40b3c5e Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Tue, 21 Jan 2025 08:57:31 -0600 Subject: [PATCH 09/16] Tests passing --- .../spec/sidekiq/organizations/update_spec.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index fe0d9c457bc..e91494e6453 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -133,13 +133,13 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow_any_instance_of(VAProfile::AddressValidation::Service).to receive(:candidate).and_return(api_response) - allow_any_instance_of(Faraday::Connection).to receive(:post) end context 'when JSON parsing fails' do let(:invalid_json_data) { 'invalid json' } - it 'logs an error to Sentry' do + it 'logs an error to Slack and Sentry' do + expect_any_instance_of(SlackNotify::Client).to receive(:notify) expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( "Organizations::Update: Error processing job: unexpected token at 'invalid json'", :error ) @@ -153,7 +153,8 @@ def create_organization let(:address_exists) { false } let(:address_changed) { true } - it 'logs an error to Sentry' do + it 'logs an error to Slack and Sentry' do + expect_any_instance_of(SlackNotify::Client).to receive(:notify) expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( 'Organizations::Update: Update failed for Org id: not_found: Organization not found.', :error ) @@ -552,7 +553,8 @@ def create_organization context 'when JSON parsing fails' do let(:invalid_json_data) { 'invalid json' } - it 'logs an error to Sentry' do + it 'logs an error to Slack and Sentry' do + expect_any_instance_of(SlackNotify::Client).to receive(:notify) expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( "Organizations::Update: Error processing job: unexpected token at 'invalid json'", :error ) @@ -566,7 +568,8 @@ def create_organization let(:address_exists) { false } let(:address_changed) { true } - it 'logs an error to Sentry' do + it 'logs an error to Slack and Sentry' do + expect_any_instance_of(SlackNotify::Client).to receive(:notify) expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( 'Organizations::Update: Update failed for Org id: not_found: Organization not found.', :error ) From cd896ec94bcdcc32327d3cf2092496c7afc89d65 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Tue, 21 Jan 2025 09:37:11 -0600 Subject: [PATCH 10/16] Log progress every run --- .../veteran/app/sidekiq/organizations/update.rb | 3 ++- .../spec/sidekiq/organizations/update_spec.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 2ccff0ca875..0fa2356da9d 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -33,7 +33,8 @@ def perform(orgs_json) log_error("Error processing job: #{e.message}") ensure p "slack_messages.size: #{@slack_messages.size}" - # p "@orgs_data: #{@orgs_data}", "@orgs_data.size: #{@orgs_data.size}" + @slack_messages.unshift("Orgs processed: #{@orgs_data.size}") if @orgs_data&.any? + @slack_messages.unshift('Organizations::Update') log_to_slack(@slack_messages.join("\n")) unless @slack_messages.empty? end diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index e91494e6453..7701e44b7b4 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -13,6 +13,7 @@ before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(double('VAProfile::AddressValidation::Service', candidate: nil)) # rubocop:disable Layout/LineLength + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end it 'does not call validate_address or VAProfile::AddressValidation::Service.new' do @@ -28,6 +29,7 @@ before do Flipper.enable(:va_v3_contact_information_service) allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(double('VAProfile::V3::AddressValidation::Service', candidate: nil)) # rubocop:disable Layout/LineLength + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end after do @@ -133,13 +135,13 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow_any_instance_of(VAProfile::AddressValidation::Service).to receive(:candidate).and_return(api_response) + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end context 'when JSON parsing fails' do let(:invalid_json_data) { 'invalid json' } - it 'logs an error to Slack and Sentry' do - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + it 'logs an error to Sentry' do expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( "Organizations::Update: Error processing job: unexpected token at 'invalid json'", :error ) @@ -153,8 +155,7 @@ def create_organization let(:address_exists) { false } let(:address_changed) { true } - it 'logs an error to Slack and Sentry' do - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + it 'logs an error to Sentry' do expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( 'Organizations::Update: Update failed for Org id: not_found: Organization not found.', :error ) @@ -544,6 +545,7 @@ def create_organization before do Flipper.enable(:va_v3_contact_information_service) allow_any_instance_of(VAProfile::V3::AddressValidation::Service).to receive(:candidate).and_return(api_response) + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end after do @@ -553,8 +555,7 @@ def create_organization context 'when JSON parsing fails' do let(:invalid_json_data) { 'invalid json' } - it 'logs an error to Slack and Sentry' do - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + it 'logs an error to Sentry' do expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( "Organizations::Update: Error processing job: unexpected token at 'invalid json'", :error ) @@ -568,8 +569,7 @@ def create_organization let(:address_exists) { false } let(:address_changed) { true } - it 'logs an error to Slack and Sentry' do - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + it 'logs an error to Sentry' do expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with( 'Organizations::Update: Update failed for Org id: not_found: Organization not found.', :error ) From e8dce7ad24348a9c7879dce7891ebfef83fbd3ba Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Tue, 21 Jan 2025 09:50:50 -0600 Subject: [PATCH 11/16] Cleanup and disable slack --- modules/veteran/app/sidekiq/organizations/update.rb | 11 ++++------- .../veteran/spec/sidekiq/organizations/update_spec.rb | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 0fa2356da9d..731bf53ae9e 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -18,9 +18,7 @@ class Update attr_accessor :slack_messages, :orgs_data def initialize - p 'slack_messages initialized' @slack_messages = [] - p "slack_messages.size: #{@slack_messages.size}" end # Processes each organization's data provided in JSON format. @@ -32,7 +30,6 @@ def perform(orgs_json) rescue => e log_error("Error processing job: #{e.message}") ensure - p "slack_messages.size: #{@slack_messages.size}" @slack_messages.unshift("Orgs processed: #{@orgs_data.size}") if @orgs_data&.any? @slack_messages.unshift('Organizations::Update') log_to_slack(@slack_messages.join("\n")) unless @slack_messages.empty? @@ -295,10 +292,10 @@ def get_best_address_candidate(org_address) end def log_to_slack(message) - client = SlackNotify::Client.new(webhook_url: Settings.claims_api.slack.webhook_url, - channel: '#benefits-representation-management-notifications', - username: 'Organizations::Update Bot') - client.notify(message) + # client = SlackNotify::Client.new(webhook_url: WE_NEED_A_WEBHOOK_URL), + # channel: '#benefits-representation-management-notifications', + # username: 'Organizations::Update Bot') + # client.notify(message) end end end diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index 7701e44b7b4..f2b85694a67 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -13,7 +13,7 @@ before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(double('VAProfile::AddressValidation::Service', candidate: nil)) # rubocop:disable Layout/LineLength - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + # expect_any_instance_of(SlackNotify::Client).to receive(:notify) end it 'does not call validate_address or VAProfile::AddressValidation::Service.new' do @@ -29,7 +29,7 @@ before do Flipper.enable(:va_v3_contact_information_service) allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(double('VAProfile::V3::AddressValidation::Service', candidate: nil)) # rubocop:disable Layout/LineLength - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + # expect_any_instance_of(SlackNotify::Client).to receive(:notify) end after do @@ -135,7 +135,7 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow_any_instance_of(VAProfile::AddressValidation::Service).to receive(:candidate).and_return(api_response) - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + # expect_any_instance_of(SlackNotify::Client).to receive(:notify) end context 'when JSON parsing fails' do @@ -545,7 +545,7 @@ def create_organization before do Flipper.enable(:va_v3_contact_information_service) allow_any_instance_of(VAProfile::V3::AddressValidation::Service).to receive(:candidate).and_return(api_response) - expect_any_instance_of(SlackNotify::Client).to receive(:notify) + # expect_any_instance_of(SlackNotify::Client).to receive(:notify) end after do From 6d4d71df64f8546d205a053634e024b2431316c0 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Wed, 22 Jan 2025 12:54:05 -0600 Subject: [PATCH 12/16] [WIP] updates --- modules/veteran/app/sidekiq/organizations/update.rb | 6 +++--- .../app/sidekiq/organizations/xlsx_file_processor.rb | 2 +- .../spec/sidekiq/organizations/xlsx_file_processor_spec.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 731bf53ae9e..1c103022313 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -156,8 +156,8 @@ def build_address(address, geocode, meta) address_line2: address['address_line2'], address_line3: address['address_line3'], city: address['city'], - province: address['state_code']['name'], - state_code: address['state_code']['code'], + province: address['state']['state_name'], + state_code: address['state']['state_code'], zip_code: address['zip_code5'], zip_suffix: address['zip_code4'], country_code_iso3: address['country']['iso3_code'], @@ -181,7 +181,7 @@ def build_v3_address(address) state_code: address['state']['state_code'], zip_code: address['zip_code5'], zip_suffix: address['zip_code4'], - country_code_iso3: address['country']['iso3_code'], + country_code_iso3: address['country']['country_code_iso3'], country_name: address['country']['country_name'], county_name: address.dig('county', 'county_name'), county_code: address.dig('county', 'county_code'), diff --git a/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb b/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb index 3ccd65af0b4..374aacc5f87 100644 --- a/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb +++ b/modules/veteran/app/sidekiq/organizations/xlsx_file_processor.rb @@ -138,7 +138,7 @@ def process_row(row, sheet_name, column_map) address_line2: get_value(row, column_map, 'OrganizationAddressLine2'), address_line3: get_value(row, column_map, 'OrganizationAddressLine3'), city: get_value(row, column_map, 'OrganizationCity'), - state_code: { code: get_value(row, column_map, 'OrganizationState') }, + state: { state_code: get_value(row, column_map, 'OrganizationState') }, zip_code5:, zip_code4:, country_code_iso3: 'US' diff --git a/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb b/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb index 8de75008acf..689d1909706 100644 --- a/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/xlsx_file_processor_spec.rb @@ -25,7 +25,7 @@ def check_values(hash) context 'with valid data' do let(:expected_keys) { %i[id address phone_number] } let(:expected_address_keys) do - %i[address_pou address_line1 address_line2 address_line3 city state_code zip_code5 zip_code4 + %i[address_pou address_line1 address_line2 address_line3 city state zip_code5 zip_code4 country_code_iso3] end From 25c7b05ef233f75c2683cc5bd04bade4568311c9 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Wed, 22 Jan 2025 15:15:13 -0600 Subject: [PATCH 13/16] [WIP] Clairfying api responses --- .../app/sidekiq/organizations/update.rb | 11 ++++- .../spec/sidekiq/organizations/update_spec.rb | 40 +++++++++---------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 1c103022313..cfcf0a30ed2 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -25,6 +25,7 @@ def initialize # This method parses the JSON, validates each organization's address, and updates the database records. # @param orgs_json [String] JSON string containing an array of organization data. def perform(orgs_json) + # binding.pry @orgs_data = JSON.parse(orgs_json) @orgs_data.each { |org_data| process_org_data(org_data) } rescue => e @@ -42,6 +43,7 @@ def perform(orgs_json) # is halted for the current organization. # @param org_data [Hash] The organization data including id and address. def process_org_data(org_data) + # binding.pry return unless record_can_be_updated?(org_data) address_validation_api_response = nil @@ -119,6 +121,7 @@ def address_valid?(response) # @param org_data [Hash] Original org_data containing the address and other details. # @param api_response [Hash] The response from the address validation service. def update_org_record(org_data, api_response) + # binding.pry record = Veteran::Service::Organization.find_by(poa: org_data['id']) if record.nil? @@ -133,6 +136,7 @@ def update_org_record(org_data, api_response) # @param org_data [Hash] Original org_data containing the address and other details. # @param api_response [Hash] The response from the address validation service. def build_address_attributes(org_data, api_response) + # binding.pry if Flipper.enabled?(:va_v3_contact_information_service) build_v3_address(api_response['candidate_addresses'].first) else @@ -150,14 +154,15 @@ def build_address_attributes(org_data, api_response) # @param meta [Hash] Metadata about the address from the validation response. # @return [Hash] The attributes to update the record with. def build_address(address, geocode, meta) + # binding.pry { address_type: meta['address_type'], address_line1: address['address_line1'], address_line2: address['address_line2'], address_line3: address['address_line3'], city: address['city'], - province: address['state']['state_name'], - state_code: address['state']['state_code'], + province: address['state_province']['name'], + state_code: address['state_province']['state_code'], zip_code: address['zip_code5'], zip_suffix: address['zip_code4'], country_code_iso3: address['country']['iso3_code'], @@ -171,6 +176,7 @@ def build_address(address, geocode, meta) end def build_v3_address(address) + # binding.pry { address_type: address['address_type'], address_line1: address['address_line1'], @@ -265,6 +271,7 @@ def retry_validation(org_address) # @param org_address [Hash] the address provided by OGC # @return [Hash, Nil] the response from the address validation service def get_best_address_candidate(org_address) + # binding.pry if org_address.nil? log_error('In #get_best_address_candidate, org_address is nil') return nil diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index f2b85694a67..9d7f9b8f709 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -90,7 +90,7 @@ def create_organization } ].to_json end - let(:api_response) do + let(:api_response_v2) do { 'candidate_addresses' => [ { @@ -99,7 +99,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_code' => { + 'state_province' => { 'name' => 'New York', 'code' => 'NY' }, @@ -134,7 +134,7 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) - allow_any_instance_of(VAProfile::AddressValidation::Service).to receive(:candidate).and_return(api_response) + allow_any_instance_of(VAProfile::AddressValidation::Service).to receive(:candidate).and_return(api_response_v2) # expect_any_instance_of(SlackNotify::Client).to receive(:notify) end @@ -206,7 +206,7 @@ def create_organization let(:address_changed) { true } let!(:organization) { create_organization } let(:validation_stub) { instance_double(VAProfile::AddressValidation::Service) } - let(:api_response_with_zero) do + let(:api_response_with_zero_v2) do { 'candidate_addresses' => [ { @@ -247,7 +247,7 @@ def create_organization ] } end - let(:api_response1) do + let(:api_response1_v2) do { 'candidate_addresses' => [ { @@ -375,7 +375,7 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response1) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response1_v2) end it 'does not update the organization address' do @@ -396,7 +396,7 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response_with_zero, + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, api_response2) end @@ -418,8 +418,8 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response_with_zero, - api_response_with_zero, api_response3) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, + api_response_with_zero_v2, api_response3) end it 'updates the organization address' do @@ -440,8 +440,8 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response_with_zero, - api_response_with_zero, api_response_with_zero) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, + api_response_with_zero_v2, api_response_with_zero_v2) end it 'does not update the organization address' do @@ -506,7 +506,7 @@ def create_organization } ].to_json end - let(:api_response) do + let(:api_response_v3) do { 'candidate_addresses' => [ { @@ -544,7 +544,7 @@ def create_organization before do Flipper.enable(:va_v3_contact_information_service) - allow_any_instance_of(VAProfile::V3::AddressValidation::Service).to receive(:candidate).and_return(api_response) + allow_any_instance_of(VAProfile::V3::AddressValidation::Service).to receive(:candidate).and_return(api_response_v3) # expect_any_instance_of(SlackNotify::Client).to receive(:notify) end @@ -612,7 +612,7 @@ def create_organization let(:address_changed) { true } let!(:organization) { create_organization } let(:validation_stub) { instance_double(VAProfile::V3::AddressValidation::Service) } - let(:api_response_with_zero) do + let(:api_response_with_zero_v2) do { 'candidate_addresses' => [ { @@ -756,7 +756,7 @@ def create_organization context 'when the first retry has non-zero coordinates' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response1) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response1) end it 'does not update the organization address' do @@ -776,7 +776,7 @@ def create_organization context 'when the second retry has non-zero coordinates' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response_with_zero, + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, api_response2) end @@ -797,8 +797,8 @@ def create_organization context 'when the third retry has non-zero coordinates' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response_with_zero, - api_response_with_zero, api_response3) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, + api_response_with_zero_v2, api_response3) end it 'updates the organization address' do @@ -818,8 +818,8 @@ def create_organization context 'when the retry coordinates are all zero' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero, api_response_with_zero, - api_response_with_zero, api_response_with_zero) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, + api_response_with_zero_v2, api_response_with_zero_v2) end it 'does not update the organization address' do From 6db0e3b4e6b401402ccd09d89734c3e09b026772 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Wed, 22 Jan 2025 15:46:04 -0600 Subject: [PATCH 14/16] Finish fixing and versioning api responses --- .../spec/sidekiq/organizations/update_spec.rb | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index 9d7f9b8f709..5c139b89c17 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -215,7 +215,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_code' => { + 'state_province' => { 'name' => 'New York', 'code' => 'NY' }, @@ -256,7 +256,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_code' => { + 'state_province' => { 'name' => 'New York', 'code' => 'NY' }, @@ -288,7 +288,7 @@ def create_organization ] } end - let(:api_response2) do + let(:api_response2_v2) do { 'candidate_addresses' => [ { @@ -297,7 +297,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_code' => { + 'state_province' => { 'name' => 'New York', 'code' => 'NY' }, @@ -329,7 +329,7 @@ def create_organization ] } end - let(:api_response3) do + let(:api_response3_v2) do { 'candidate_addresses' => [ { @@ -338,7 +338,7 @@ def create_organization 'name' => 'Kings', 'county_fips_code' => '36047' }, - 'state_code' => { + 'state_province' => { 'name' => 'New York', 'code' => 'NY' }, @@ -375,7 +375,8 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response1_v2) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, + api_response1_v2) end it 'does not update the organization address' do @@ -396,8 +397,9 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, - api_response2) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, + api_response_with_zero_v2, + api_response2_v2) end it 'does not update the organization address' do @@ -418,8 +420,10 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, - api_response_with_zero_v2, api_response3) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, + api_response_with_zero_v2, + api_response_with_zero_v2, + api_response3_v2) end it 'updates the organization address' do @@ -440,8 +444,10 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, - api_response_with_zero_v2, api_response_with_zero_v2) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, + api_response_with_zero_v2, + api_response_with_zero_v2, + api_response_with_zero_v2) end it 'does not update the organization address' do @@ -544,7 +550,8 @@ def create_organization before do Flipper.enable(:va_v3_contact_information_service) - allow_any_instance_of(VAProfile::V3::AddressValidation::Service).to receive(:candidate).and_return(api_response_v3) + address_validation_service = VAProfile::V3::AddressValidation::Service + allow_any_instance_of(address_validation_service).to receive(:candidate).and_return(api_response_v3) # expect_any_instance_of(SlackNotify::Client).to receive(:notify) end @@ -647,7 +654,7 @@ def create_organization ] } end - let(:api_response1) do + let(:api_response1_v3) do { 'candidate_addresses' => [ { @@ -682,7 +689,7 @@ def create_organization ] } end - let(:api_response2) do + let(:api_response2_v3) do { 'candidate_addresses' => [ { @@ -717,7 +724,7 @@ def create_organization ] } end - let(:api_response3) do + let(:api_response3_v3) do { 'candidate_addresses' => [ { @@ -756,7 +763,7 @@ def create_organization context 'when the first retry has non-zero coordinates' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response1) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response1_v3) end it 'does not update the organization address' do @@ -776,8 +783,9 @@ def create_organization context 'when the second retry has non-zero coordinates' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, - api_response2) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, + api_response_with_zero_v2, + api_response2_v3) end it 'does not update the organization address' do @@ -797,8 +805,10 @@ def create_organization context 'when the third retry has non-zero coordinates' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, - api_response_with_zero_v2, api_response3) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, + api_response_with_zero_v2, + api_response_with_zero_v2, + api_response3_v3) end it 'updates the organization address' do @@ -818,8 +828,10 @@ def create_organization context 'when the retry coordinates are all zero' do before do allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(validation_stub) - allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, api_response_with_zero_v2, - api_response_with_zero_v2, api_response_with_zero_v2) + allow(validation_stub).to receive(:candidate).and_return(api_response_with_zero_v2, + api_response_with_zero_v2, + api_response_with_zero_v2, + api_response_with_zero_v2) end it 'does not update the organization address' do From a9f869b69231648b29c50f782ef83085f7c64e98 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Wed, 22 Jan 2025 15:55:41 -0600 Subject: [PATCH 15/16] Remove commented out binding.pry calls --- modules/veteran/app/sidekiq/organizations/update.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index cfcf0a30ed2..4e25e6d9da7 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -25,7 +25,6 @@ def initialize # This method parses the JSON, validates each organization's address, and updates the database records. # @param orgs_json [String] JSON string containing an array of organization data. def perform(orgs_json) - # binding.pry @orgs_data = JSON.parse(orgs_json) @orgs_data.each { |org_data| process_org_data(org_data) } rescue => e @@ -43,7 +42,6 @@ def perform(orgs_json) # is halted for the current organization. # @param org_data [Hash] The organization data including id and address. def process_org_data(org_data) - # binding.pry return unless record_can_be_updated?(org_data) address_validation_api_response = nil @@ -121,7 +119,6 @@ def address_valid?(response) # @param org_data [Hash] Original org_data containing the address and other details. # @param api_response [Hash] The response from the address validation service. def update_org_record(org_data, api_response) - # binding.pry record = Veteran::Service::Organization.find_by(poa: org_data['id']) if record.nil? @@ -136,7 +133,6 @@ def update_org_record(org_data, api_response) # @param org_data [Hash] Original org_data containing the address and other details. # @param api_response [Hash] The response from the address validation service. def build_address_attributes(org_data, api_response) - # binding.pry if Flipper.enabled?(:va_v3_contact_information_service) build_v3_address(api_response['candidate_addresses'].first) else @@ -154,7 +150,6 @@ def build_address_attributes(org_data, api_response) # @param meta [Hash] Metadata about the address from the validation response. # @return [Hash] The attributes to update the record with. def build_address(address, geocode, meta) - # binding.pry { address_type: meta['address_type'], address_line1: address['address_line1'], @@ -176,7 +171,6 @@ def build_address(address, geocode, meta) end def build_v3_address(address) - # binding.pry { address_type: address['address_type'], address_line1: address['address_line1'], @@ -271,7 +265,6 @@ def retry_validation(org_address) # @param org_address [Hash] the address provided by OGC # @return [Hash, Nil] the response from the address validation service def get_best_address_candidate(org_address) - # binding.pry if org_address.nil? log_error('In #get_best_address_candidate, org_address is nil') return nil From b2a1b838c4b634d574ab0d78b8c95ff72255a121 Mon Sep 17 00:00:00 2001 From: Josh Fike Date: Fri, 24 Jan 2025 10:30:51 -0600 Subject: [PATCH 16/16] Restore Slack notify using existing webhook_url --- modules/veteran/app/sidekiq/organizations/update.rb | 8 ++++---- modules/veteran/spec/sidekiq/organizations/update_spec.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/veteran/app/sidekiq/organizations/update.rb b/modules/veteran/app/sidekiq/organizations/update.rb index 4e25e6d9da7..238d5419c67 100644 --- a/modules/veteran/app/sidekiq/organizations/update.rb +++ b/modules/veteran/app/sidekiq/organizations/update.rb @@ -292,10 +292,10 @@ def get_best_address_candidate(org_address) end def log_to_slack(message) - # client = SlackNotify::Client.new(webhook_url: WE_NEED_A_WEBHOOK_URL), - # channel: '#benefits-representation-management-notifications', - # username: 'Organizations::Update Bot') - # client.notify(message) + client = SlackNotify::Client.new(webhook_url: Settings.edu.slack.webhook_url, + channel: '#benefits-representation-management-notifications', + username: 'Organizations::Update Bot') + client.notify(message) end end end diff --git a/modules/veteran/spec/sidekiq/organizations/update_spec.rb b/modules/veteran/spec/sidekiq/organizations/update_spec.rb index 5c139b89c17..e32d4d817c9 100644 --- a/modules/veteran/spec/sidekiq/organizations/update_spec.rb +++ b/modules/veteran/spec/sidekiq/organizations/update_spec.rb @@ -13,7 +13,7 @@ before do Flipper.disable(:va_v3_contact_information_service) allow(VAProfile::AddressValidation::Service).to receive(:new).and_return(double('VAProfile::AddressValidation::Service', candidate: nil)) # rubocop:disable Layout/LineLength - # expect_any_instance_of(SlackNotify::Client).to receive(:notify) + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end it 'does not call validate_address or VAProfile::AddressValidation::Service.new' do @@ -29,7 +29,7 @@ before do Flipper.enable(:va_v3_contact_information_service) allow(VAProfile::V3::AddressValidation::Service).to receive(:new).and_return(double('VAProfile::V3::AddressValidation::Service', candidate: nil)) # rubocop:disable Layout/LineLength - # expect_any_instance_of(SlackNotify::Client).to receive(:notify) + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end after do @@ -135,7 +135,7 @@ def create_organization before do Flipper.disable(:va_v3_contact_information_service) allow_any_instance_of(VAProfile::AddressValidation::Service).to receive(:candidate).and_return(api_response_v2) - # expect_any_instance_of(SlackNotify::Client).to receive(:notify) + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end context 'when JSON parsing fails' do @@ -552,7 +552,7 @@ def create_organization Flipper.enable(:va_v3_contact_information_service) address_validation_service = VAProfile::V3::AddressValidation::Service allow_any_instance_of(address_validation_service).to receive(:candidate).and_return(api_response_v3) - # expect_any_instance_of(SlackNotify::Client).to receive(:notify) + expect_any_instance_of(SlackNotify::Client).to receive(:notify) end after do