Skip to content

Commit

Permalink
Debugging static query case setup (o19s#889)
Browse files Browse the repository at this point in the history
* add a test and some docs...
* make sure we don't get double imports of a static csv file1
  • Loading branch information
epugh authored Nov 22, 2023
1 parent 2ebabff commit d80f04e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/controllers/wizardModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ angular.module('QuepidApp')

$scope.isStaticCollapsed = true;
$scope.addedStaticQueries = false;
$scope.listOfStaticQueries = [];
$scope.showSearchApiJavaScriptEditor = true;
$scope.staticContent = {
content: null,
Expand Down Expand Up @@ -728,8 +729,7 @@ angular.module('QuepidApp')
function createSnapshot() {
$scope.staticContent.import.loading = true;
$scope.isStaticCollapsed = false;

$scope.listOfStaticQueries = [];

angular.forEach($scope.staticContent.result, function(doc) {
if (!$scope.listOfStaticQueries.includes(doc['Query Text'])){
$scope.listOfStaticQueries.push(doc['Query Text']);
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/services/settingsSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ angular.module('QuepidApp')
titleField: '',
additionalFields: [],
numberOfRows: 10,
searchEngine: 'static'
searchEngine: 'static',
proxyRequests: true
// no searchUrl or urlFormat because it's code generated!
},
searchapi: {
Expand Down
3 changes: 1 addition & 2 deletions app/assets/templates/views/wizardModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ <h2>CSV</h2>
<div class="content import-content">
<pre>{{ staticContent.content }}</pre>
</div>

<button class="btn btn-primary" ng-click="createSnapshot()"> Import</button>
<button class="btn btn-primary" ng-click="createSnapshot()" ng-disabled="listOfStaticQueries.length > 0"> Import</button>
</div>
</div>
</div>
Expand Down
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
1 change: 1 addition & 0 deletions config/initializers/apipie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
config.app_name = 'Quepid'
config.api_base_url = '/api'
config.doc_base_url = '/apipie'
config.validate = :explicitly
# where is your API defined?
config.api_controllers_matcher = Rails.root.join('app/controllers/api/**/*.rb').to_s
config.namespaced_resources = true
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 d80f04e

Please sign in to comment.