Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cadet/updater/CS1101S.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Cadet.Updater.CS1101S do
def clone do
Logger.info("Cloning CS1101S: Started")

if repo_cloned? do
if repo_cloned?() do
Logger.info("CS1101S is already cloned.")
else
git("clone", [@remote_repo, @local_name])
Expand Down
1 change: 1 addition & 0 deletions lib/cadet_web/controllers/assessments_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ defmodule CadetWeb.AssessmentsController do
id(:integer, "The question id", required: true)
type(:string, "The question type (mcq/programming)", required: true)
content(:string, "The question content", required: true)
comment(:string, "Comment given by group leader. Might be null.")

choices(
Schema.new do
Expand Down
8 changes: 5 additions & 3 deletions lib/cadet_web/views/assessments_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule CadetWeb.AssessmentsView do
}) do
components = [
build_question(%{question: question}),
build_answer_by_question_type(%{question: question}),
build_answer_fields_by_question_type(%{question: question}),
build_solution_if_ungraded_by_type(%{question: question, assessment: assessment})
]

Expand Down Expand Up @@ -105,7 +105,9 @@ defmodule CadetWeb.AssessmentsView do
end
end

defp build_answer_by_question_type(%{question: %{answer: answer, type: question_type}}) do
defp build_answer_fields_by_question_type(%{
question: %{answer: answer, type: question_type}
}) do
# No need to check if answer exists since empty answer would be a
# `%Answer{..., answer: nil}` and nil["anything"] = nil

Expand All @@ -115,7 +117,7 @@ defmodule CadetWeb.AssessmentsView do
:mcq -> & &1.answer["choice_id"]
end

transform_map_for_view(answer, %{answer: answer_getter})
transform_map_for_view(answer, %{answer: answer_getter, comment: :comment})
end

def build_choice(%{choice: choice}) do
Expand Down
28 changes: 28 additions & 0 deletions test/cadet_web/controllers/assessments_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ defmodule CadetWeb.AssessmentsControllerTest do
|> Enum.map(&Map.delete(&1, "answer"))
|> Enum.map(&Map.delete(&1, "solution"))
|> Enum.map(&Map.delete(&1, "library"))
|> Enum.map(&Map.delete(&1, "comment"))

assert expected_questions == resp_questions
end
Expand Down Expand Up @@ -399,6 +400,33 @@ defmodule CadetWeb.AssessmentsControllerTest do
end
end

test "it renders comment", %{
conn: conn,
users: %{student: student},
assessments: assessments
} do
for {_type,
%{
assessment: assessment,
mcq_answers: [mcq_answers | _],
programming_answers: [programming_answers | _]
}} <- assessments do
# Programming questions should come first due to seeding order
expected_comments =
Enum.map(programming_answers ++ mcq_answers, &%{"comment" => &1.comment})

resp_comments =
conn
|> sign_in(student)
|> get(build_url(assessment.id))
|> json_response(200)
|> Map.get("questions", [])
|> Enum.map(&Map.take(&1, ["comment"]))

assert expected_comments == resp_comments
end
end

test "it does not permit access to not yet open assessments", %{
conn: conn,
users: %{student: student},
Expand Down
3 changes: 2 additions & 1 deletion test/factories/assessments/answer_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ defmodule Cadet.Assessments.AnswerFactory do

def answer_factory do
%Answer{
answer: %{}
answer: %{},
comment: Faker.Lorem.Shakespeare.En.romeo_and_juliet()
}
end

Expand Down