From 119824bf01e941a8800459ea5f8f9b5964588233 Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:11:35 +0800 Subject: [PATCH 01/11] Implement returning of assessment alongside submission answers --- lib/cadet/assessments/assessments.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 6bb932160..0de1f5e90 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -1345,7 +1345,7 @@ defmodule Cadet.Assessments do end @spec get_answers_in_submission(integer() | String.t()) :: - {:ok, [Answer.t()]} | {:error, {:bad_request, String.t()}} + {:ok, %{answers: [Answer.t()], assessment: Assessment.t()}} | {:error, {:bad_request, String.t()}} def get_answers_in_submission(id) when is_ecto_id(id) do answer_query = Answer @@ -1379,10 +1379,12 @@ defmodule Cadet.Assessments do end end) + assessment_id = Submission |> where(id: ^id) |> select([s], s.assessment_id) |> Repo.one() + assessment = Assessment |> where(id: ^assessment_id) |> Repo.one() if answers == [] do {:error, {:bad_request, "Submission is not found."}} else - {:ok, answers} + {:ok, {answers, assessment}} end end From 243d49cff53d1f8ea1bdc92dd3f17e7293115ae8 Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:12:20 +0800 Subject: [PATCH 02/11] Update controller to accept returning of assessment --- lib/cadet_web/admin_controllers/admin_grading_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cadet_web/admin_controllers/admin_grading_controller.ex b/lib/cadet_web/admin_controllers/admin_grading_controller.ex index caa9771a1..24b915371 100644 --- a/lib/cadet_web/admin_controllers/admin_grading_controller.ex +++ b/lib/cadet_web/admin_controllers/admin_grading_controller.ex @@ -24,8 +24,8 @@ defmodule CadetWeb.AdminGradingController do def show(conn, %{"submissionid" => submission_id}) when is_ecto_id(submission_id) do case Assessments.get_answers_in_submission(submission_id) do - {:ok, answers} -> - render(conn, "show.json", answers: answers) + {:ok, {answers, assessment}} -> + render(conn, "show.json", answers: answers, assessment: assessment) {:error, {status, message}} -> conn From c76c68a49b6e921ac1a6b487443522a9f7b0deca Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:25:39 +0800 Subject: [PATCH 03/11] Update view to include assessment alongside submission answers --- .../admin_views/admin_grading_view.ex | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/cadet_web/admin_views/admin_grading_view.ex b/lib/cadet_web/admin_views/admin_grading_view.ex index 128bfb59d..772484200 100644 --- a/lib/cadet_web/admin_views/admin_grading_view.ex +++ b/lib/cadet_web/admin_views/admin_grading_view.ex @@ -3,8 +3,24 @@ defmodule CadetWeb.AdminGradingView do import CadetWeb.AssessmentsHelpers - def render("show.json", %{answers: answers}) do - render_many(answers, CadetWeb.AdminGradingView, "grading_info.json", as: :answer) + def render("show.json", %{answers: answers, assessment: assessment}) do + %{ + assessment: render_one(assessment, CadetWeb.AdminGradingView, "assessment.json", as: :assessment), + answers: render_many(answers, CadetWeb.AdminGradingView, "grading_info.json", as: :answer) + } + end + + def render("assessment.json", %{assessment: assessment}) do + %{ + id: assessment.id, + title: assessment.title, + summary_short: assessment.summary_short, + summary_long: assessment.summary_long, + cover_picture: assessment.cover_picture, + number: assessment.number, + story: assessment.story, + reading: assessment.reading, + } end def render("gradingsummaries.json", %{ From bc1cd3dcb8805548c47afb4cbd7acc0dad345a1c Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:52:01 +0800 Subject: [PATCH 04/11] Format changes --- lib/cadet/assessments/assessments.ex | 4 +++- lib/cadet_web/admin_views/admin_grading_view.ex | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 0de1f5e90..3b0245bde 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -1345,7 +1345,8 @@ defmodule Cadet.Assessments do end @spec get_answers_in_submission(integer() | String.t()) :: - {:ok, %{answers: [Answer.t()], assessment: Assessment.t()}} | {:error, {:bad_request, String.t()}} + {:ok, %{answers: [Answer.t()], assessment: Assessment.t()}} + | {:error, {:bad_request, String.t()}} def get_answers_in_submission(id) when is_ecto_id(id) do answer_query = Answer @@ -1381,6 +1382,7 @@ defmodule Cadet.Assessments do assessment_id = Submission |> where(id: ^id) |> select([s], s.assessment_id) |> Repo.one() assessment = Assessment |> where(id: ^assessment_id) |> Repo.one() + if answers == [] do {:error, {:bad_request, "Submission is not found."}} else diff --git a/lib/cadet_web/admin_views/admin_grading_view.ex b/lib/cadet_web/admin_views/admin_grading_view.ex index 772484200..cc8c3b229 100644 --- a/lib/cadet_web/admin_views/admin_grading_view.ex +++ b/lib/cadet_web/admin_views/admin_grading_view.ex @@ -5,7 +5,8 @@ defmodule CadetWeb.AdminGradingView do def render("show.json", %{answers: answers, assessment: assessment}) do %{ - assessment: render_one(assessment, CadetWeb.AdminGradingView, "assessment.json", as: :assessment), + assessment: + render_one(assessment, CadetWeb.AdminGradingView, "assessment.json", as: :assessment), answers: render_many(answers, CadetWeb.AdminGradingView, "grading_info.json", as: :answer) } end @@ -19,7 +20,7 @@ defmodule CadetWeb.AdminGradingView do cover_picture: assessment.cover_picture, number: assessment.number, story: assessment.story, - reading: assessment.reading, + reading: assessment.reading } end From ce9523f293f1bbd79ac9c14bf546c85fe0e4448b Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:32:54 +0800 Subject: [PATCH 05/11] Fix get_answers_in_submission to account for nonexistent submission --- lib/cadet/assessments/assessments.ex | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 3b0245bde..7a17275f8 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -1380,12 +1380,11 @@ defmodule Cadet.Assessments do end end) - assessment_id = Submission |> where(id: ^id) |> select([s], s.assessment_id) |> Repo.one() - assessment = Assessment |> where(id: ^assessment_id) |> Repo.one() - if answers == [] do {:error, {:bad_request, "Submission is not found."}} else + assessment_id = Submission |> where(id: ^id) |> select([s], s.assessment_id) |> Repo.one() + assessment = Assessment |> where(id: ^assessment_id) |> Repo.one() {:ok, {answers, assessment}} end end From 61b175f9f45d307313a9325da15301a3c8887ffe Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Fri, 2 Feb 2024 23:35:07 +0800 Subject: [PATCH 06/11] Update tests to expect assessment with answers --- .../admin_grading_controller_test.exs | 685 +++++++++--------- 1 file changed, 356 insertions(+), 329 deletions(-) diff --git a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs index 2c08e27d7..9bff86176 100644 --- a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs @@ -219,7 +219,8 @@ defmodule CadetWeb.AdminGradingControllerTest do course: course, grader: grader, submissions: submissions, - answers: answers + answers: answers, + mission: assessment } = seed_db(conn) submission = List.first(submissions) @@ -227,172 +228,185 @@ defmodule CadetWeb.AdminGradingControllerTest do conn = get(conn, build_url(course.id, submission.id)) expected = - answers - |> Enum.filter(&(&1.submission.id == submission.id)) - |> Enum.sort_by(& &1.question.display_order) - |> Enum.map( - &case &1.question.type do - :programming -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "postpend" => &1.question.question.postpend, - "testcases" => - Enum.map( - &1.question.question.public, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "public"}, - do: {Atom.to_string(k), v} - end - ) ++ - Enum.map( - &1.question.question.opaque, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "opaque"}, - do: {Atom.to_string(k), v} - end - ) ++ - Enum.map( - &1.question.question.secret, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "secret"}, - do: {Atom.to_string(k), v} - end - ), - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols + %{ + "assessment" => %{ + "id" => assessment.id, + "title" => assessment.title, + "summary_short" => assessment.summary_short, + "summary_long" => assessment.summary_long, + "cover_picture" => assessment.cover_picture, + "number" => assessment.number, + "story" => assessment.story, + "reading" => assessment.reading + }, + "answers" => + answers + |> Enum.filter(&(&1.submission.id == submission.id)) + |> Enum.sort_by(& &1.question.display_order) + |> Enum.map( + &case &1.question.type do + :programming -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "postpend" => &1.question.question.postpend, + "testcases" => + Enum.map( + &1.question.question.public, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "public"}, + do: {Atom.to_string(k), v} + end + ) ++ + Enum.map( + &1.question.question.opaque, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "opaque"}, + do: {Atom.to_string(k), v} + end + ) ++ + Enum.map( + &1.question.question.secret, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "secret"}, + do: {Atom.to_string(k), v} + end + ), + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols + }, + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant + }, + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "answer" => &1.answer.code, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "answer" => &1.answer.code, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results - }, - "solution" => &1.question.question.solution, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments - }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } - } - - :mcq -> - %{ - "question" => %{ - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols + "solution" => &1.question.question.solution, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id + }, + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "answer" => &1.answer.choice_id, - "choices" => - for choice <- &1.question.question.choices do - %{ - "content" => choice.content, - "hint" => choice.hint, - "id" => choice.choice_id - } - end, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results - }, - "solution" => "", - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments - }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } - } - - :voting -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + } + } + + :mcq -> + %{ + "question" => %{ + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols + }, + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant + }, + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "answer" => &1.answer.choice_id, + "choices" => + for choice <- &1.question.question.choices do + %{ + "content" => choice.content, + "hint" => choice.hint, + "id" => choice.choice_id + } + end, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results, - "answer" => nil, - "contestEntries" => [], - "contestLeaderboard" => [] - }, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments - }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - }, - "solution" => "" - } - end - ) + "solution" => "", + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id + }, + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + } + } + + :voting -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols + }, + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant + }, + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results, + "answer" => nil, + "contestEntries" => [], + "contestLeaderboard" => [] + }, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id + }, + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + }, + "solution" => "" + } + end + ) + } assert expected == json_response(conn, 200) end @@ -866,180 +880,193 @@ defmodule CadetWeb.AdminGradingControllerTest do course: course, grader: grader, submissions: submissions, - answers: answers + answers: answers, + mission: assessment } = seed_db(conn) submission = List.first(submissions) - conn = get(conn, build_url(course.id, submission.id)) expected = - answers - |> Enum.filter(&(&1.submission.id == submission.id)) - |> Enum.sort_by(& &1.question.display_order) - |> Enum.map( - &case &1.question.type do - :programming -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "postpend" => &1.question.question.postpend, - "testcases" => - Enum.map( - &1.question.question.public, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "public"}, - do: {Atom.to_string(k), v} - end - ) ++ - Enum.map( - &1.question.question.opaque, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "opaque"}, - do: {Atom.to_string(k), v} - end - ) ++ - Enum.map( - &1.question.question.secret, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "secret"}, - do: {Atom.to_string(k), v} - end - ), - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols + %{ + "assessment" => %{ + "id" => assessment.id, + "title" => assessment.title, + "summary_short" => assessment.summary_short, + "summary_long" => assessment.summary_long, + "cover_picture" => assessment.cover_picture, + "number" => assessment.number, + "story" => assessment.story, + "reading" => assessment.reading + }, + "answers" => + answers + |> Enum.filter(&(&1.submission.id == submission.id)) + |> Enum.sort_by(& &1.question.display_order) + |> Enum.map( + &case &1.question.type do + :programming -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "postpend" => &1.question.question.postpend, + "testcases" => + Enum.map( + &1.question.question.public, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "public"}, + do: {Atom.to_string(k), v} + end + ) ++ + Enum.map( + &1.question.question.opaque, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "opaque"}, + do: {Atom.to_string(k), v} + end + ) ++ + Enum.map( + &1.question.question.secret, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "secret"}, + do: {Atom.to_string(k), v} + end + ), + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols + }, + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant + }, + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "answer" => &1.answer.code, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "answer" => &1.answer.code, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results - }, - "solution" => &1.question.question.solution, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments - }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } - } - - :mcq -> - %{ - "question" => %{ - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols + "solution" => &1.question.question.solution, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id + }, + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "content" => &1.question.question.content, - "answer" => &1.answer.choice_id, - "maxXp" => &1.question.max_xp, - "choices" => - for choice <- &1.question.question.choices do - %{ - "content" => choice.content, - "hint" => choice.hint, - "id" => choice.choice_id - } - end, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results - }, - "solution" => "", - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments - }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } - } - - :voting -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + } + } + + :mcq -> + %{ + "question" => %{ + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols + }, + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant + }, + "content" => &1.question.question.content, + "answer" => &1.answer.choice_id, + "maxXp" => &1.question.max_xp, + "choices" => + for choice <- &1.question.question.choices do + %{ + "content" => choice.content, + "hint" => choice.hint, + "id" => choice.choice_id + } + end, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results, - "answer" => nil, - "contestEntries" => [], - "contestLeaderboard" => [] - }, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments - }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - }, - "solution" => "" - } - end - ) + "solution" => "", + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id + }, + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + } + } + + :voting -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols + }, + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant + }, + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results, + "answer" => nil, + "contestEntries" => [], + "contestLeaderboard" => [] + }, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id + }, + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + }, + "solution" => "" + } + end + ) + } assert expected == json_response(conn, 200) end From 527e7204e4269623cad3921654f2cfe6a9d865f1 Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Sat, 3 Feb 2024 00:31:14 +0800 Subject: [PATCH 07/11] Fix format --- .../admin_grading_controller_test.exs | 650 +++++++++--------- 1 file changed, 324 insertions(+), 326 deletions(-) diff --git a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs index 9bff86176..72f29a5da 100644 --- a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs @@ -227,186 +227,185 @@ defmodule CadetWeb.AdminGradingControllerTest do conn = get(conn, build_url(course.id, submission.id)) - expected = - %{ - "assessment" => %{ - "id" => assessment.id, - "title" => assessment.title, - "summary_short" => assessment.summary_short, - "summary_long" => assessment.summary_long, - "cover_picture" => assessment.cover_picture, - "number" => assessment.number, - "story" => assessment.story, - "reading" => assessment.reading - }, - "answers" => - answers - |> Enum.filter(&(&1.submission.id == submission.id)) - |> Enum.sort_by(& &1.question.display_order) - |> Enum.map( - &case &1.question.type do - :programming -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "postpend" => &1.question.question.postpend, - "testcases" => + expected = %{ + "assessment" => %{ + "id" => assessment.id, + "title" => assessment.title, + "summary_short" => assessment.summary_short, + "summary_long" => assessment.summary_long, + "cover_picture" => assessment.cover_picture, + "number" => assessment.number, + "story" => assessment.story, + "reading" => assessment.reading + }, + "answers" => + answers + |> Enum.filter(&(&1.submission.id == submission.id)) + |> Enum.sort_by(& &1.question.display_order) + |> Enum.map( + &case &1.question.type do + :programming -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "postpend" => &1.question.question.postpend, + "testcases" => + Enum.map( + &1.question.question.public, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "public"}, + do: {Atom.to_string(k), v} + end + ) ++ Enum.map( - &1.question.question.public, + &1.question.question.opaque, fn testcase -> for {k, v} <- testcase, - into: %{"type" => "public"}, + into: %{"type" => "opaque"}, do: {Atom.to_string(k), v} end ) ++ - Enum.map( - &1.question.question.opaque, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "opaque"}, - do: {Atom.to_string(k), v} - end - ) ++ - Enum.map( - &1.question.question.secret, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "secret"}, - do: {Atom.to_string(k), v} - end - ), - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols - }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant + Enum.map( + &1.question.question.secret, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "secret"}, + do: {Atom.to_string(k), v} + end + ), + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "answer" => &1.answer.code, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant }, - "solution" => &1.question.question.solution, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "answer" => &1.answer.code, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results + }, + "solution" => &1.question.question.solution, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id } - - :mcq -> - %{ - "question" => %{ - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols - }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant + } + + :mcq -> + %{ + "question" => %{ + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "answer" => &1.answer.choice_id, - "choices" => - for choice <- &1.question.question.choices do - %{ - "content" => choice.content, - "hint" => choice.hint, - "id" => choice.choice_id - } - end, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant }, - "solution" => "", - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "answer" => &1.answer.choice_id, + "choices" => + for choice <- &1.question.question.choices do + %{ + "content" => choice.content, + "hint" => choice.hint, + "id" => choice.choice_id + } + end, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results + }, + "solution" => "", + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id } - - :voting -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols - }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results, - "answer" => nil, - "contestEntries" => [], - "contestLeaderboard" => [] - }, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id + } + + :voting -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results, + "answer" => nil, + "contestEntries" => [], + "contestLeaderboard" => [] + }, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id }, - "solution" => "" - } - end - ) - } + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + }, + "solution" => "" + } + end + ) + } assert expected == json_response(conn, 200) end @@ -887,186 +886,185 @@ defmodule CadetWeb.AdminGradingControllerTest do submission = List.first(submissions) conn = get(conn, build_url(course.id, submission.id)) - expected = - %{ - "assessment" => %{ - "id" => assessment.id, - "title" => assessment.title, - "summary_short" => assessment.summary_short, - "summary_long" => assessment.summary_long, - "cover_picture" => assessment.cover_picture, - "number" => assessment.number, - "story" => assessment.story, - "reading" => assessment.reading - }, - "answers" => - answers - |> Enum.filter(&(&1.submission.id == submission.id)) - |> Enum.sort_by(& &1.question.display_order) - |> Enum.map( - &case &1.question.type do - :programming -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "postpend" => &1.question.question.postpend, - "testcases" => + expected = %{ + "assessment" => %{ + "id" => assessment.id, + "title" => assessment.title, + "summary_short" => assessment.summary_short, + "summary_long" => assessment.summary_long, + "cover_picture" => assessment.cover_picture, + "number" => assessment.number, + "story" => assessment.story, + "reading" => assessment.reading + }, + "answers" => + answers + |> Enum.filter(&(&1.submission.id == submission.id)) + |> Enum.sort_by(& &1.question.display_order) + |> Enum.map( + &case &1.question.type do + :programming -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "postpend" => &1.question.question.postpend, + "testcases" => + Enum.map( + &1.question.question.public, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "public"}, + do: {Atom.to_string(k), v} + end + ) ++ Enum.map( - &1.question.question.public, + &1.question.question.opaque, fn testcase -> for {k, v} <- testcase, - into: %{"type" => "public"}, + into: %{"type" => "opaque"}, do: {Atom.to_string(k), v} end ) ++ - Enum.map( - &1.question.question.opaque, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "opaque"}, - do: {Atom.to_string(k), v} - end - ) ++ - Enum.map( - &1.question.question.secret, - fn testcase -> - for {k, v} <- testcase, - into: %{"type" => "secret"}, - do: {Atom.to_string(k), v} - end - ), - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols - }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant + Enum.map( + &1.question.question.secret, + fn testcase -> + for {k, v} <- testcase, + into: %{"type" => "secret"}, + do: {Atom.to_string(k), v} + end + ), + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "answer" => &1.answer.code, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant }, - "solution" => &1.question.question.solution, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "answer" => &1.answer.code, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results + }, + "solution" => &1.question.question.solution, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id } - - :mcq -> - %{ - "question" => %{ - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols - }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant + } + + :mcq -> + %{ + "question" => %{ + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols }, - "content" => &1.question.question.content, - "answer" => &1.answer.choice_id, - "maxXp" => &1.question.max_xp, - "choices" => - for choice <- &1.question.question.choices do - %{ - "content" => choice.content, - "hint" => choice.hint, - "id" => choice.choice_id - } - end, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant }, - "solution" => "", - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id - }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments + "content" => &1.question.question.content, + "answer" => &1.answer.choice_id, + "maxXp" => &1.question.max_xp, + "choices" => + for choice <- &1.question.question.choices do + %{ + "content" => choice.content, + "hint" => choice.hint, + "id" => choice.choice_id + } + end, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results + }, + "solution" => "", + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id - } + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id } - - :voting -> - %{ - "question" => %{ - "prepend" => &1.question.question.prepend, - "solutionTemplate" => &1.question.question.template, - "type" => "#{&1.question.type}", - "blocking" => &1.question.blocking, - "id" => &1.question.id, - "library" => %{ - "chapter" => &1.question.library.chapter, - "globals" => &1.question.library.globals, - "external" => %{ - "name" => "#{&1.question.library.external.name}", - "symbols" => &1.question.library.external.symbols - }, - "execTimeMs" => &1.question.library.exec_time_ms, - "variant" => &1.question.library.variant - }, - "maxXp" => &1.question.max_xp, - "content" => &1.question.question.content, - "autogradingStatus" => Atom.to_string(&1.autograding_status), - "autogradingResults" => &1.autograding_results, - "answer" => nil, - "contestEntries" => [], - "contestLeaderboard" => [] - }, - "grade" => %{ - "xp" => &1.xp, - "xpAdjustment" => &1.xp_adjustment, - "grader" => %{ - "name" => grader.user.name, - "id" => grader.id + } + + :voting -> + %{ + "question" => %{ + "prepend" => &1.question.question.prepend, + "solutionTemplate" => &1.question.question.template, + "type" => "#{&1.question.type}", + "blocking" => &1.question.blocking, + "id" => &1.question.id, + "library" => %{ + "chapter" => &1.question.library.chapter, + "globals" => &1.question.library.globals, + "external" => %{ + "name" => "#{&1.question.library.external.name}", + "symbols" => &1.question.library.external.symbols }, - "gradedAt" => format_datetime(&1.updated_at), - "comments" => &1.comments + "execTimeMs" => &1.question.library.exec_time_ms, + "variant" => &1.question.library.variant }, - "student" => %{ - "name" => &1.submission.student.user.name, - "username" => &1.submission.student.user.username, - "id" => &1.submission.student.id + "maxXp" => &1.question.max_xp, + "content" => &1.question.question.content, + "autogradingStatus" => Atom.to_string(&1.autograding_status), + "autogradingResults" => &1.autograding_results, + "answer" => nil, + "contestEntries" => [], + "contestLeaderboard" => [] + }, + "grade" => %{ + "xp" => &1.xp, + "xpAdjustment" => &1.xp_adjustment, + "grader" => %{ + "name" => grader.user.name, + "id" => grader.id }, - "solution" => "" - } - end - ) - } + "gradedAt" => format_datetime(&1.updated_at), + "comments" => &1.comments + }, + "student" => %{ + "name" => &1.submission.student.user.name, + "username" => &1.submission.student.user.username, + "id" => &1.submission.student.id + }, + "solution" => "" + } + end + ) + } assert expected == json_response(conn, 200) end From 80265af9deb05d940189585c49cce6365a146577 Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:57:12 +0800 Subject: [PATCH 08/11] fix: change return type for get_answers_in_submission --- lib/cadet/assessments/assessments.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index 7a17275f8..55b413fe5 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -1345,7 +1345,7 @@ defmodule Cadet.Assessments do end @spec get_answers_in_submission(integer() | String.t()) :: - {:ok, %{answers: [Answer.t()], assessment: Assessment.t()}} + {:ok, {[Answer.t()], Assessment.t()}} | {:error, {:bad_request, String.t()}} def get_answers_in_submission(id) when is_ecto_id(id) do answer_query = From a742fd1435375beb755a4dde30318733c6a8e551 Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:17:21 +0800 Subject: [PATCH 09/11] Update JSON response to camel case --- lib/cadet_web/admin_views/admin_grading_view.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cadet_web/admin_views/admin_grading_view.ex b/lib/cadet_web/admin_views/admin_grading_view.ex index cc8c3b229..c9418ef9a 100644 --- a/lib/cadet_web/admin_views/admin_grading_view.ex +++ b/lib/cadet_web/admin_views/admin_grading_view.ex @@ -15,9 +15,9 @@ defmodule CadetWeb.AdminGradingView do %{ id: assessment.id, title: assessment.title, - summary_short: assessment.summary_short, - summary_long: assessment.summary_long, - cover_picture: assessment.cover_picture, + summaryShort: assessment.summary_short, + summaryLong: assessment.summary_long, + coverPicture: assessment.cover_picture, number: assessment.number, story: assessment.story, reading: assessment.reading From 54591aac370b42db2c2a60fdb4fceddd65b0f2d5 Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Wed, 7 Feb 2024 16:02:21 +0800 Subject: [PATCH 10/11] Update grading controller test --- .../admin_controllers/admin_grading_controller_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs index 72f29a5da..663155347 100644 --- a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs @@ -890,9 +890,9 @@ defmodule CadetWeb.AdminGradingControllerTest do "assessment" => %{ "id" => assessment.id, "title" => assessment.title, - "summary_short" => assessment.summary_short, - "summary_long" => assessment.summary_long, - "cover_picture" => assessment.cover_picture, + "summaryShort" => assessment.summary_short, + "summaryLong" => assessment.summary_long, + "coverPicture" => assessment.cover_picture, "number" => assessment.number, "story" => assessment.story, "reading" => assessment.reading From 4576b4e5a4ce6e3e066e98e56b1d146a5d400caf Mon Sep 17 00:00:00 2001 From: GabrielCWT <77312579+GabrielCWT@users.noreply.github.com> Date: Wed, 7 Feb 2024 16:05:32 +0800 Subject: [PATCH 11/11] Update grading controller test for staff --- .../admin_controllers/admin_grading_controller_test.exs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs index 663155347..607541052 100644 --- a/test/cadet_web/admin_controllers/admin_grading_controller_test.exs +++ b/test/cadet_web/admin_controllers/admin_grading_controller_test.exs @@ -231,9 +231,9 @@ defmodule CadetWeb.AdminGradingControllerTest do "assessment" => %{ "id" => assessment.id, "title" => assessment.title, - "summary_short" => assessment.summary_short, - "summary_long" => assessment.summary_long, - "cover_picture" => assessment.cover_picture, + "summaryShort" => assessment.summary_short, + "summaryLong" => assessment.summary_long, + "coverPicture" => assessment.cover_picture, "number" => assessment.number, "story" => assessment.story, "reading" => assessment.reading