diff --git a/lib/cadet/jobs/autograder/result_store_worker.ex b/lib/cadet/jobs/autograder/result_store_worker.ex index 852253488..d0ce71c65 100644 --- a/lib/cadet/jobs/autograder/result_store_worker.ex +++ b/lib/cadet/jobs/autograder/result_store_worker.ex @@ -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 diff --git a/test/cadet/jobs/autograder/result_store_worker_test.exs b/test/cadet/jobs/autograder/result_store_worker_test.exs index 57961ebef..952e23a2c 100644 --- a/test/cadet/jobs/autograder/result_store_worker_test.exs +++ b/test/cadet/jobs/autograder/result_store_worker_test.exs @@ -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})