Skip to content

Commit

Permalink
fix: Fix autopublish grading by auto grader (#1188)
Browse files Browse the repository at this point in the history
* fix: Fix autopublish grading by auto grader

* feat: Implement tests for autopublishing
  • Loading branch information
GabrielCWT authored Sep 20, 2024
1 parent 85a3c1e commit 6d33c09
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/cadet/jobs/autograder/result_store_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ defmodule Cadet.Autograder.ResultStoreWorker do
assessment = Repo.get(Assessment, submission.assessment_id)
assessment_config = Repo.get_by(AssessmentConfig, id: assessment.config_id)
is_grading_auto_published = assessment_config.is_grading_auto_published
is_manually_graded = assessment_config.is_manually_graded

if Assessments.is_fully_autograded?(submission_id) and is_grading_auto_published do
if Assessments.is_fully_autograded?(submission_id) and is_grading_auto_published and
not is_manually_graded do
Assessments.publish_grading(submission_id)
end

Expand Down
50 changes: 49 additions & 1 deletion test/cadet/jobs/autograder/result_store_worker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,55 @@ defmodule Cadet.Autograder.ResultStoreWorkerTest do
end

describe "#perform, valid answer_id" do
test "before manual grading and grading auto published", %{answer: answer, results: results} do
test "before manual grading, grading auto published and manual grading required", %{
answer: answer,
results: results
} do
for result <- results do
ResultStoreWorker.perform(%{answer_id: answer.id, result: result})

answer =
Answer
|> join(:inner, [a], q in assoc(a, :question))
|> preload([_, q], question: q)
|> Repo.get(answer.id)

errors_string_keys =
Enum.map(result.result, fn err ->
Enum.reduce(err, %{}, fn {k, v}, acc ->
Map.put(acc, "#{k}", v)
end)
end)

if result.max_score == 0 do
assert answer.xp == 0
else
assert answer.xp ==
Integer.floor_div(
answer.question.max_xp * result.score,
result.max_score
)
end

submission = Repo.get(Submission, answer.submission_id)

assert submission.is_grading_published == false
assert answer.autograding_status == result.status
assert answer.autograding_results == errors_string_keys
end
end

test "before manual grading, grading auto published and manual grading not required", %{
results: results
} do
assessment_config =
insert(:assessment_config, %{is_grading_auto_published: true, is_manually_graded: false})

assessment = insert(:assessment, %{config: assessment_config})
question = insert(:question, %{assessment: assessment})
submission = insert(:submission, %{status: :submitted, assessment: assessment})
answer = insert(:answer, %{question: question, submission: submission})

for result <- results do
ResultStoreWorker.perform(%{answer_id: answer.id, result: result})

Expand Down

0 comments on commit 6d33c09

Please sign in to comment.