|
62 | 62 | end |
63 | 63 |
|
64 | 64 | let(:systems_service) { instance_double(VAOS::V2::SystemsService) } |
| 65 | + let(:eligibility_service) { instance_double(VAOS::V2::Unified::EligibilityService) } |
65 | 66 |
|
66 | 67 | before do |
67 | 68 | allow(user).to receive(:vet360_contact_info).and_return(vet360_contact_info) |
|
75 | 76 | allow(FacilitiesApi::V2::Lighthouse::Client).to receive(:new).and_return(lighthouse_client) |
76 | 77 | allow(Eps::ProviderService).to receive(:new).and_return(eps_provider_service) |
77 | 78 | allow(VAOS::V2::SystemsService).to receive(:new).with(user).and_return(systems_service) |
| 79 | + allow(VAOS::V2::Unified::EligibilityService).to receive(:new).with(user).and_return(eligibility_service) |
| 80 | + allow(eligibility_service).to receive(:check_eligibility).and_return({ direct_eligible: true }) |
78 | 81 |
|
79 | 82 | allow(lighthouse_client).to receive(:get_facilities).and_return([lighthouse_facility]) |
80 | 83 | allow(eps_provider_service).to receive(:search_by_location).and_return([eps_provider_hash]) |
|
199 | 202 | expect(results.first.provider_type).to eq('va') |
200 | 203 | end |
201 | 204 |
|
202 | | - it 'requests clinics for each Lighthouse facility (filter_supported_facilities is not yet applied)' do |
| 205 | + it 'includes all Lighthouse facilities when category_of_care does not map to a VAOS service (no eligibility filter)' do |
203 | 206 | non_matching_facility = double( |
204 | 207 | 'Facility', |
205 | 208 | id: 'vha_984', unique_id: '984', name: 'Other VA', |
|
217 | 220 | expect(va_providers.size).to eq(2) |
218 | 221 | expect(va_providers.map(&:location_id).sort).to eq(%w[983 984]) |
219 | 222 | expect(systems_service).to have_received(:get_facility_clinics).twice |
| 223 | + expect(eligibility_service).not_to have_received(:check_eligibility) |
| 224 | + end |
| 225 | + |
| 226 | + it 'excludes VA facilities that fail direct-scheduling eligibility when category maps to VAOS' do |
| 227 | + non_matching_facility = double( |
| 228 | + 'Facility', |
| 229 | + id: 'vha_984', unique_id: '984', name: 'Other VA', |
| 230 | + address: nil, phone: nil, lat: 28.12, long: -80.65, |
| 231 | + facility_type: 'va_health_facility', |
| 232 | + services: { 'health' => [{ 'serviceId' => 'audiology' }] } |
| 233 | + ) |
| 234 | + allow(lighthouse_client).to receive(:get_facilities).and_return( |
| 235 | + [lighthouse_facility, non_matching_facility] |
| 236 | + ) |
| 237 | + audio_referral = double('Referral', category_of_care: 'audiology', provider_npi: '91560381x') |
| 238 | + |
| 239 | + allow(eligibility_service).to receive(:check_eligibility) do |va_provider, category_of_care_arg| |
| 240 | + expect(category_of_care_arg).to eq('audiology') |
| 241 | + { |
| 242 | + facility_id: va_provider.location_id, |
| 243 | + vaos_service_type: 'audiology', |
| 244 | + direct_eligible: va_provider.location_id == '983' |
| 245 | + } |
| 246 | + end |
| 247 | + |
| 248 | + results = service.search(referral: audio_referral) |
| 249 | + |
| 250 | + va_providers = results.select { |p| p.provider_type == 'va' } |
| 251 | + expect(va_providers.map(&:location_id)).to eq(['983']) |
| 252 | + expect(systems_service).to have_received(:get_facility_clinics).once |
220 | 253 | end |
221 | 254 |
|
222 | 255 | it 'returns no VA providers when get_facility_clinics returns no clinics' do |
|
0 commit comments