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

Move modify_desired_date logic into appointments service #17134

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move tests
  • Loading branch information
JunTaoLuo committed Jun 15, 2024
commit 1c50a38db158b787b03bc2126e394a79ca72cdfb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@
end
end

describe '#get_clinic_memoized' do
context 'when clinic service throws an error' do
it 'returns nil' do
allow_any_instance_of(VAOS::V2::MobileFacilityService).to receive(:get_clinic_with_cache)
.and_raise(Common::Exceptions::BackendServiceException.new('VAOS_502', {}))

expect(subject.send(:get_clinic_memoized, '123', '3456')).to be_nil
end
end
end

describe '#start_date' do
context 'with an invalid date' do
it 'throws an InvalidFieldValue exception' do
Expand Down
41 changes: 41 additions & 0 deletions modules/vaos/spec/services/v2/appointment_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1197,4 +1197,45 @@
end
end
end

describe '#add_timezone_offset' do
let(:va_booked_request_body) do
FactoryBot.build(:appointment_form_v2, :va_booked).attributes
end
let(:desired_date) { '2022-09-21T00:00:00+00:00'.to_datetime }

context 'with a date and timezone' do
it 'adds the timezone offset to the date' do
date_with_offset = subject.send(:add_timezone_offset, desired_date, 'America/New_York')
expect(date_with_offset.to_s).to eq('2022-09-21T00:00:00-04:00')
end
end

context 'with a date and nil timezone' do
it 'leaves the date as is' do
date_with_offset = subject.send(:add_timezone_offset, desired_date, nil)
expect(date_with_offset.to_s).to eq(desired_date.to_s)
end
end

context 'with a nil date' do
it 'throws a ParameterMissing exception' do
expect do
subject.send(:add_timezone_offset, nil, 'America/New_York')
end.to raise_error(Common::Exceptions::ParameterMissing)
end
end
end

describe '#modify_desired_date' do
let(:va_booked_request_body) do
FactoryBot.build(:appointment_form_v2, :va_booked).attributes
end
context 'with a request body and facility timezone' do
it 'updates the direct scheduled appt desired date with facilities time zone offset' do
subject.send(:modify_desired_date, va_booked_request_body, 'America/Denver')
expect(va_booked_request_body[:extension][:desired_date].to_s).to eq('2022-11-30T00:00:00-07:00')
end
end
end
end