Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Sep 4, 2024
1 parent 92004d1 commit 84afd7d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 56 deletions.
52 changes: 26 additions & 26 deletions modules/vaos/spec/requests/vaos/v2/appointments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -724,24 +724,25 @@ def stub_clinics
end

it 'updates the service name, physical location, friendly name, and location' do
appointment = { clinic: 'Test Clinic', location_id: 1 }

stub_facilities
allow_any_instance_of(VAOS::V2::MobileFacilityService).to receive(:get_clinic)
.and_return(service_name: 'Service Name', physical_location: 'Physical Location')
allow_any_instance_of(VAOS::V2::MobileFacilityService).to receive(:get_facility).and_return('Location')
allow_any_instance_of(described_class).to receive(:appointment).and_return(appointment)
allow(Rails.logger).to receive(:info).at_least(:once)
VCR.use_cassette('vaos/v2/appointments/get_appointment_200',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)

get '/vaos/v2/appointments/70060', headers: inflection_header
get '/vaos/v2/appointments/70060', headers: inflection_header

data = json_body_for(response)
expect(data['serviceName']).to eq('Service Name')
expect(data['physicalLocation']).to eq('Physical Location')
expect(data['friendlyName']).to eq('Service Name')
expect(data['location']).to eq('Location')
expect(Rails.logger).to have_received(:info).with(
'VAOS::V2::AppointmentsController appointment creation time: unknown'
)
data = json_body_for(response)['attributes']
expect(data['serviceName']).to eq('Service Name')
expect(data['physicalLocation']).to eq('Physical Location')
expect(data['friendlyName']).to eq('Service Name')
expect(data['location']).to eq(expected_facility)
expect(Rails.logger).to have_received(:info).with(
'VAOS::V2::AppointmentsController appointment creation time: 2021-12-13T14:03:02Z',
{ created: '2021-12-13T14:03:02Z' }.to_json
)
end
end
end

Expand Down Expand Up @@ -772,6 +773,7 @@ def stub_clinics

it 'returns a status code of 200 and the cancelled appointment with the updated status' do
stub_facilities
stub_clinics
VCR.use_cassette('vaos/v2/appointments/cancel_appointments_200', match_requests_on: %i[method path query]) do
put '/vaos/v2/appointments/70060', params: { status: 'cancelled' }, headers: inflection_header
expect(response).to have_http_status(:success)
Expand All @@ -786,22 +788,20 @@ def stub_clinics
end

context 'when clinic and location_id are present' do
let(:updated_appointment) { { clinic: 'Test Clinic', location_id: 1 } }

it 'updates the service name, physical location, friendly name, and location' do
allow_any_instance_of(VAOS::V2::MobileFacilityService).to receive(:get_clinic)
.and_return(service_name: 'Service Name', physical_location: 'Physical Location')
allow_any_instance_of(VAOS::V2::MobileFacilityService).to receive(:get_facility)
.and_return('Location')
allow_any_instance_of(described_class).to receive(:updated_appointment).and_return(updated_appointment)

put '/vaos/v2/appointments/70060', params: { status: 'cancelled' }, headers: inflection_header
stub_facilities
VCR.use_cassette('vaos/v2/appointments/cancel_appointments_200',
match_requests_on: %i[method path query]) do
put '/vaos/v2/appointments/70060', params: { status: 'cancelled' }, headers: inflection_header

data = json_body_for(response)
expect(data['serviceName']).to eq('Service Name')
expect(data['physicalLocation']).to eq('Physical Location')
expect(data['friendlyName']).to eq('Service Name')
expect(data['location']).to eq('Location')
data = json_body_for(response)['attributes']
expect(data['serviceName']).to eq('Service Name')
expect(data['physicalLocation']).to eq('Physical Location')
expect(data['friendlyName']).to eq('Service Name')
expect(data['location']).to eq(expected_facility)
end
end
end

Expand Down
75 changes: 51 additions & 24 deletions modules/vaos/spec/services/v2/appointment_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@
match_requests_on: %i[method path query]) do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facility_200',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
end
end
end
end
Expand All @@ -106,19 +109,28 @@
match_requests_on: %i[method path query]) do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facility_200',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
end
end
end
end

it 'returns the created appointment-va-proposed-clinic' do
VCR.use_cassette('vaos/v2/appointments/post_appointments_va_proposed_clinic_200',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_proposed_clinic_request_body)
expect(response[:id]).to eq('70065')
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facility_200',
match_requests_on: %i[method path query]) do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_proposed_clinic_request_body)
expect(response[:id]).to eq('70065')
end
end
end
end
end
Expand Down Expand Up @@ -186,11 +198,14 @@
match_requests_on: %i[method path query]) do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facility_200',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
allow(Rails.logger).to receive(:info).at_least(:once)
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
end
end
end
end
Expand All @@ -200,19 +215,28 @@
match_requests_on: %i[method path query]) do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facility_200',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_booked_request_body)
expect(response[:id]).to be_a(String)
expect(response[:local_start_time])
.to eq(DateTime.parse('2022-11-30T13:45:00-07:00'))
end
end
end
end

it 'returns the created appointment-va-proposed-clinic' do
VCR.use_cassette('vaos/v2/appointments/post_appointments_va_proposed_clinic_200_vpg',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_proposed_clinic_request_body)
expect(response[:id]).to eq('70065')
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facility_200',
match_requests_on: %i[method path query]) do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
response = subject.post_appointment(va_proposed_clinic_request_body)
expect(response[:id]).to eq('70065')
end
end
end
end
end
Expand Down Expand Up @@ -788,8 +812,11 @@
match_requests_on: %i[method path query]) do
VCR.use_cassette('vaos/v2/mobile_facility_service/get_facility_200',
match_requests_on: %i[method path query]) do
response = subject.update_appointment('70060', 'cancelled')
expect(response.status).to eq('cancelled')
VCR.use_cassette('vaos/v2/mobile_facility_service/get_clinic_200',
match_requests_on: %i[method path query]) do
response = subject.update_appointment('70060', 'cancelled')
expect(response.status).to eq('cancelled')
end
end
end
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 84afd7d

Please sign in to comment.