Skip to content

Commit

Permalink
add test for the ratings format that confirms int values not floats...
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Jan 22, 2024
1 parent ee27bc5 commit ca67fb3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/views/api/v1/export/ratings/_rre_query.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ end
grouped_ratings = {}

query.ratings.fully_rated.each do |r|
int_rating = r.rating.to_i # rre and rankquest both are int based
# rubocop:disable Style/IfUnlessModifier
unless grouped_ratings.key?(r.rating)
grouped_ratings[r.rating] = []
unless grouped_ratings.key?(int_rating)
grouped_ratings[int_rating] = []
end
# rubocop:enable Style/IfUnlessModifier
grouped_ratings[r.rating] << r.doc_id
grouped_ratings[int_rating] << r.doc_id
end

json.relevant_documents do
Expand Down
15 changes: 13 additions & 2 deletions test/controllers/api/v1/export/ratings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RatingsControllerTest < ActionController::TestCase
end

describe 'Exporting a case in RRE json format' do
let(:the_case) { cases(:one) }
let(:the_case) { cases(:queries_case) }

test 'returns case info' do
get :show, params: { case_id: the_case.id, file_format: 'rre' }
Expand All @@ -49,13 +49,24 @@ class RatingsControllerTest < ActionController::TestCase
assert_response :ok

body = response.parsed_body

puts response.body

assert_equal body['id_field'], 'id'
assert_equal body['index'], the_case.tries.latest.index_name_from_search_url
assert_equal body['queries'].size, the_case.queries.size
assert_equal body['queries'][0]['placeholders']['$query'], the_case.queries[0].query_text
assert_equal body['queries'][2]['placeholders']['$query'], the_case.queries[2].query_text
assert_nil body['queries'][2]['relevant_documents']
assert_not_nil body['queries'][2]['relevant_documents']
puts body['queries'][2]['relevant_documents']

expected_relevant_docs = {
"1": ["docb"],
"3": ["doca"]
}


assert_equal expected_relevant_docs, body['queries'][2]['relevant_documents'].deep_symbolize_keys
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/teams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
valid:
name: valid team
owner: :doug
cases: shared_through_owned_team
cases: shared_through_owned_team, queries_case
members: doug

shared:
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/tries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ for_case_queries_case:
case: :queries_case
query_params: 'q=#$query##'
try_number: 1
field_spec: id:id title:title
search_endpoint: :for_case_queries_case

0 comments on commit ca67fb3

Please sign in to comment.