Skip to content

Commit

Permalink
Add rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
achan authored and achan committed Dec 30, 2024
1 parent c8053b2 commit aae3784
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/controllers/v1/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ def location
meta: @meta
end

# GET /v1/institutions?description=nursing&latitude=42.3601&longitude=-71.0589
# GET /v1/gi/institutions/search?description=nursing&latitude=42.3601&longitude=-71.0589
def program
@query ||= normalized_query_params

# Start with filtering by institution programs based on description
institution_programs = InstitutionProgram.joins(:institution)
.where('institution_programs.description ILIKE ?', "%#{@query[:description]}%")
.where(institutions: { version: @version })
.where('institution_programs.description ILIKE ?', "%#{@query[:description]}%")
.where(institutions: { version: @version })

# Now filter by location
location_results = Institution.approved_institutions(@version)
.location_search(@query)
Expand Down
29 changes: 29 additions & 0 deletions spec/controllers/v1/institutions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,33 @@ def check_boolean_facets(facets)
expect(JSON.parse(response.body)['data'].count).to eq(0)
end
end

context 'with program search results' do
before do
create(:version, :production)
create(:institution, :production_version, latitude: 30.1659, longitude: -93.2146) # Example institution
create(:institution_program, institution: Institution.last, description: 'Software Engineering') # Program associated with the institution
end

it 'search returns results matching program description and location' do
get(:program, params: { description: 'Software Engineering', latitude: 30.1659, longitude: -93.2146 })
expect(JSON.parse(response.body)['data'].count).to eq(1) # Expecting one result
expect(response.media_type).to eq('application/json')
expect(response).to match_response_schema('institution_search_results')
end

it 'returns no results for non-matching program description' do
get(:program, params: { description: 'Non-existing Program', latitude: 30.1659, longitude: -93.2146 })
expect(JSON.parse(response.body)['data'].count).to eq(0) # Expecting no results
expect(response.media_type).to eq('application/json')
expect(response).to match_response_schema('institution_search_results')
end

it 'returns no results for non-matching location' do
get(:program, params: { description: 'Software Engineering', latitude: 0.0, longitude: 0.0 })
expect(JSON.parse(response.body)['data'].count).to eq(0) # Expecting no results
expect(response.media_type).to eq('application/json')
expect(response).to match_response_schema('institution_search_results')
end
end
end

0 comments on commit aae3784

Please sign in to comment.