From da4c68f073ce4de80f2f980a2eea3f0bef57c9ec Mon Sep 17 00:00:00 2001 From: Corey Ferris Date: Wed, 24 Apr 2024 11:05:05 -0400 Subject: [PATCH] manila timezone info logging (#16468) * manila timezone info logging --- .../services/vaos/v2/appointments_service.rb | 22 +++++++ .../services/v2/appointment_service_spec.rb | 62 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/modules/vaos/app/services/vaos/v2/appointments_service.rb b/modules/vaos/app/services/vaos/v2/appointments_service.rb index 6a3eacbb338..d9bd6d153b3 100644 --- a/modules/vaos/app/services/vaos/v2/appointments_service.rb +++ b/modules/vaos/app/services/vaos/v2/appointments_service.rb @@ -15,6 +15,7 @@ class AppointmentsService < VAOS::SessionService FACILITY_ERROR_MSG = 'Error fetching facility details' AVS_ERROR_MESSAGE = 'Error retrieving AVS link' AVS_APPT_TEST_ID = '192308' + MANILA_PHILIPPINES_FACILITY_ID = '358' AVS_FLIPPER = :va_online_scheduling_after_visit_summary ORACLE_HEALTH_CANCELLATIONS = :va_online_scheduling_enable_OH_cancellations @@ -411,15 +412,36 @@ def convert_appointment_time(appt) if !appt[:start].nil? facility_timezone = get_facility_timezone_memoized(appt[:location_id]) appt[:local_start_time] = convert_utc_to_local_time(appt[:start], facility_timezone) + + if appt[:location_id] == MANILA_PHILIPPINES_FACILITY_ID + log_timezone_info(appt[:location_id], facility_timezone, appt[:start], appt[:local_start_time]) + end + elsif !appt.dig(:requested_periods, 0, :start).nil? appt[:requested_periods].each do |period| facility_timezone = get_facility_timezone_memoized(appt[:location_id]) period[:local_start_time] = convert_utc_to_local_time(period[:start], facility_timezone) + + if appt[:location_id] == MANILA_PHILIPPINES_FACILITY_ID + log_timezone_info(appt[:location_id], facility_timezone, period[:start], period[:local_start_time]) + end end end appt end + def log_timezone_info(appt_location_id, facility_timezone, appt_start_time_utc, appt_start_time_local) + Rails.logger.info( + "Timezone info for Manila Philippines location_id #{appt_location_id}", + { + location_id: appt_location_id, + facility_timezone:, + appt_start_time_utc:, + appt_start_time_local: + }.to_json + ) + end + # Returns a local [DateTime] object converted from UTC using the facility's timezone offset. # We'd like to perform this change only on the appointment responses to offer a consistently # formatted local time to our consumers while not changing how we pass DateTimes to upstream services. diff --git a/modules/vaos/spec/services/v2/appointment_service_spec.rb b/modules/vaos/spec/services/v2/appointment_service_spec.rb index 5ff40013f14..88c2486408c 100644 --- a/modules/vaos/spec/services/v2/appointment_service_spec.rb +++ b/modules/vaos/spec/services/v2/appointment_service_spec.rb @@ -623,6 +623,68 @@ end end + describe '#convert_appointment_time' do + let(:manila_appt) do + { + id: '12345', + location_id: '358', + start: '2024-12-20T00:00:00Z' + } + end + + let(:manila_appt_req) do + { + id: '12345', + location_id: '358', + requested_periods: [{ start: '2024-12-20T00:00:00Z', end: '2024-12-20T11:59:59.999Z' }] + } + end + + context 'when appt location id is 358' do + it 'logs the appt location id, timezone info, utc/local times of appt' do + allow_any_instance_of(VAOS::V2::AppointmentsService) + .to receive(:get_facility_timezone_memoized) + .and_return('Asia/Manila') + allow(Rails.logger).to receive(:info) + + subject.send(:convert_appointment_time, manila_appt) + expect(Rails.logger).to have_received(:info).with('Timezone info for Manila Philippines location_id 358', + { + location_id: '358', + facility_timezone: 'Asia/Manila', + appt_start_time_utc: '2024-12-20T00:00:00Z', + appt_start_time_local: subject.send( + :convert_utc_to_local_time, + manila_appt[:start], + 'Asia/Manila' + ) + }.to_json) + end + + it 'logs the appt location id, timezone info, utc/local times of appt request' do + allow_any_instance_of(VAOS::V2::AppointmentsService) + .to receive(:get_facility_timezone_memoized) + .and_return('Asia/Manila') + allow(Rails.logger).to receive(:info) + + subject.send(:convert_appointment_time, manila_appt_req) + expect(Rails.logger).to have_received(:info).with('Timezone info for Manila Philippines location_id 358', + { + location_id: '358', + facility_timezone: 'Asia/Manila', + appt_start_time_utc: '2024-12-20T00:00:00Z', + appt_start_time_local: subject.send( + :convert_utc_to_local_time, manila_appt_req.dig( + :requested_periods, + 0, + :start + ), 'Asia/Manila' + ) + }.to_json) + end + end + end + describe '#convert_utc_to_local_time' do let(:start_datetime) { '2021-09-02T14:00:00Z'.to_datetime }