Skip to content

Commit

Permalink
add a test and some docs...
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Nov 21, 2023
1 parent 2ebabff commit f79233b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/controllers/api/v1/snapshots/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ class SearchController < SnapshotsController
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Layout/LineLength
api :GET, '/api/cases/:case_id/snapshots/:snapshot_id/search?q=:q',
'Mimic a Solr query by looking up query/doc data from a specific snapshot, using the q parameter as the query'
param :case_id, :number,
desc: 'The ID of the requested case.', required: true
param :snapshot_id, :number,
desc: 'The ID of the snapshot for the case.', required: true
param :q, String,
desc: 'The query that you are looking up', required: true
def index
@q = params[:q]
@q = search_params[:q]
query = if '*:*' == @q
@snapshot.snapshot_queries.first.query

Expand Down Expand Up @@ -57,9 +66,17 @@ def index
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Layout/LineLength

private

def search_params
# Check if the 'q' parameter exists
raise ActionController::ParameterMissing, "Missing 'q' parameter" unless params.key?(:q)

params
end

def set_snapshot
@snapshot = @case.snapshots
.where(id: params[:snapshot_id])
Expand Down
11 changes: 11 additions & 0 deletions test/controllers/api/v1/snapshots/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ class SearchControllerTest < ActionController::TestCase
assert_equal data['responseHeader']['params'], solr_params.stringify_keys.transform_values(&:to_s)
end
end

describe 'handles edge cases' do
let(:acase) { cases(:snapshot_case) }
let(:snapshot) { snapshots(:a_snapshot) }

test 'replies with message when no parameters' do
assert_raises(ActionController::ParameterMissing) do
get :index, params: { case_id: acase.id, snapshot_id: snapshot.id }
end
end
end
end
end
end
Expand Down

0 comments on commit f79233b

Please sign in to comment.