Commit 5b655c2eae3862103346621b60cd0bc8fa05e8e8

Authored by Luke Baker
1 parent 823f8d0d

add api test to verify session ids

appearances and their related actions (vote/skip) should have the same session
Showing 1 changed file with 30 additions and 1 deletions   Show diff stats
lib/tasks/test_api.rake
@@ -191,7 +191,8 @@ namespace :test_api do @@ -191,7 +191,8 @@ namespace :test_api do
191 :wins_and_losses_is_even => "Verify that sum of wins and losses is even", 191 :wins_and_losses_is_even => "Verify that sum of wins and losses is even",
192 :wins_and_losses_equals_two_times_vote_count => "Verify that sum of wins and losses equals two times the vote count", 192 :wins_and_losses_equals_two_times_vote_count => "Verify that sum of wins and losses equals two times the vote count",
193 :check_scores_over_above_fifty => "Check that there are some scores above fifty and some below", 193 :check_scores_over_above_fifty => "Check that there are some scores above fifty and some below",
194 - :generated_prompts_on_each_side_are_equal => "Verify that count of generated prompts on each side is equal" 194 + :generated_prompts_on_each_side_are_equal => "Verify that count of generated prompts on each side is equal",
  195 + :appearances_have_same_session_as_answer => "Appearances have the same session of their answer"
195 } 196 }
196 197
197 # dynamically create tasks for each question task 198 # dynamically create tasks for each question task
@@ -207,6 +208,34 @@ namespace :test_api do @@ -207,6 +208,34 @@ namespace :test_api do
207 end 208 end
208 end 209 end
209 210
  211 + def appearances_have_same_session_as_answer(question)
  212 + error_message = ""
  213 + success_message = "All appearances have the same session as their respective answer"
  214 + votes_sql = "SELECT appearances.id, appearances.voter_id, appearances.answerable_id, appearances.answerable_type,
  215 + votes.id AS votes_id, votes.voter_id AS votes_voter_id
  216 + FROM appearances
  217 + LEFT JOIN votes ON (votes.id = appearances.answerable_id)
  218 + WHERE appearances.answerable_type = 'Vote'
  219 + AND (appearances.voter_id <> votes.voter_id OR votes.voter_id IS NULL OR appearances.voter_id IS NULL)
  220 + AND appearances.question_id = #{question.id}"
  221 + bad_records = Vote.connection.select_all votes_sql
  222 + bad_records.each do |record|
  223 + error_message += "Appearance ##{record["id"]} session does not match the session of Vote ##{record["votes_id"]}\n"
  224 + end
  225 + skips_sql = "SELECT appearances.id, appearances.voter_id, appearances.answerable_id, appearances.answerable_type,
  226 + skips.id AS skips_id, skips.skipper_id AS skips_skipper_id
  227 + FROM appearances
  228 + LEFT JOIN skips ON (skips.id = appearances.answerable_id)
  229 + WHERE appearances.answerable_type = 'Skip'
  230 + AND (appearances.voter_id <> skips.skipper_id OR skips.skipper_id IS NULL OR appearances.voter_id IS NULL)
  231 + AND appearances.question_id = #{question.id}"
  232 + bad_records = Skip.connection.select_all skips_sql
  233 + bad_records.each do |record|
  234 + error_message += "Appearance ##{record["id"]} session does not match the session of Skip ##{record["votes_id"]}\n"
  235 + end
  236 + return error_message.blank? ? [success_message, false] : [error_message, true]
  237 + end
  238 +
210 def generated_prompts_on_each_side_are_equal(question) 239 def generated_prompts_on_each_side_are_equal(question)
211 error_message = "" 240 error_message = ""
212 success_message = "Number of generated prompts on left are equal to number generated on right" 241 success_message = "Number of generated prompts on left are equal to number generated on right"