Skip to content

Commit

Permalink
fix: ensure test attempt review exception is handled
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Aug 9, 2024
1 parent ccb20dc commit bb3590c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/api/test_attempts_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class TestAttemptsApi < Grape::API
error!({ message: 'Test attempt ID is invalid' }, 404)
else
logger.debug "Request to review test attempt #{params[:id]}"
test.review
begin
test.review
rescue StandardError => e
error!({ message: e.message }, 403)
end
end
present test, with: Entities::TestAttemptEntity
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/test_attempt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def cmi_datamodel=(data)
def review
dm = JSON.parse(self.cmi_datamodel)
if dm['cmi.completion_status'] != 'completed'
raise "Cannot review incomplete attempts!"
raise StandardError, 'Cannot review incomplete attempts!'
end

# when review is requested change the mode to review
Expand Down
2 changes: 1 addition & 1 deletion test/api/test_attempts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_review_attempt

# When attempt is incomplete
get "api/test_attempts/#{attempt.id}/review"
assert_equal 500, last_response.status
assert_equal 403, last_response.status

dm = JSON.parse(attempt.cmi_datamodel)
dm['cmi.completion_status'] = 'completed'
Expand Down

0 comments on commit bb3590c

Please sign in to comment.