• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

source-academy / backend / 18dc689a4df4836fc6967bf0f74dc252964bd175-PR-1180

08 Sep 2024 06:14PM UTC coverage: 79.088% (-15.3%) from 94.372%
18dc689a4df4836fc6967bf0f74dc252964bd175-PR-1180

Pull #1180

github

josh1248
Change appropriate routes into admin scope
Pull Request #1180: Transfer groundControl (and admin panel) from staff to admin route

7 of 12 new or added lines in 1 file covered. (58.33%)

499 existing lines in 25 files now uncovered.

2602 of 3290 relevant lines covered (79.09%)

1023.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/cadet_web/admin_views/admin_assessments_view.ex
1
defmodule CadetWeb.AdminAssessmentsView do
2
  use CadetWeb, :view
3
  use Timex
4
  import CadetWeb.AssessmentsHelpers
5
  import Ecto.Query
6
  alias Cadet.Assessments.{Question, SubmissionVotes}
7
  alias Cadet.Repo
8

9
  def render("index.json", %{assessments: assessments}) do
UNCOV
10
    render_many(assessments, CadetWeb.AdminAssessmentsView, "overview.json", as: :assessment)
×
11
  end
12

13
  def render("overview.json", %{assessment: assessment}) do
UNCOV
14
    transform_map_for_view(assessment, %{
×
15
      id: :id,
16
      courseId: :course_id,
17
      title: :title,
18
      shortSummary: :summary_short,
UNCOV
19
      openAt: &format_datetime(&1.open_at),
×
UNCOV
20
      closeAt: &format_datetime(&1.close_at),
×
UNCOV
21
      type: & &1.config.type,
×
UNCOV
22
      isManuallyGraded: & &1.config.is_manually_graded,
×
23
      story: :story,
24
      number: :number,
25
      reading: :reading,
UNCOV
26
      status: &(&1.user_status || "not_attempted"),
×
27
      maxXp: :max_xp,
UNCOV
28
      xp: &(&1.xp || 0),
×
29
      coverImage: :cover_picture,
UNCOV
30
      private: &password_protected?(&1.password),
×
31
      isPublished: :is_published,
32
      questionCount: :question_count,
UNCOV
33
      gradedCount: &(&1.graded_count || 0),
×
UNCOV
34
      earlySubmissionXp: & &1.config.early_submission_xp,
×
35
      maxTeamSize: :max_team_size,
36
      hasVotingFeatures: :has_voting_features,
37
      hasTokenCounter: :has_token_counter,
UNCOV
38
      isVotingPublished: &is_voting_assigned(&1.id)
×
39
    })
40
  end
41

42
  def render("show.json", %{assessment: assessment}) do
43
    transform_map_for_view(
×
44
      assessment,
45
      %{
46
        id: :id,
47
        courseId: :course_id,
48
        title: :title,
49
        type: & &1.config.type,
×
50
        story: :story,
51
        number: :number,
52
        reading: :reading,
53
        longSummary: :summary_long,
54
        hasTokenCounter: :has_token_counter,
55
        missionPDF: &Cadet.Assessments.Upload.url({&1.mission_pdf, &1}),
×
56
        questions:
57
          &Enum.map(&1.questions, fn question ->
×
58
            map =
×
59
              build_question_with_answer_and_solution_if_ungraded(%{
60
                question: question
61
              })
62

63
            map
×
64
          end)
65
      }
66
    )
67
  end
68

69
  def render("leaderboard.json", %{leaderboard: leaderboard}) do
UNCOV
70
    render_many(leaderboard, CadetWeb.AdminAssessmentsView, "contestEntry.json", as: :contestEntry)
×
71
  end
72

73
  def render("contestEntry.json", %{contestEntry: contestEntry}) do
UNCOV
74
    transform_map_for_view(
×
75
      contestEntry,
76
      %{
77
        student_name: :student_name,
UNCOV
78
        answer: & &1.answer["code"],
×
79
        final_score: "final_score"
80
      }
81
    )
82
  end
83

UNCOV
84
  defp password_protected?(nil), do: false
×
85

86
  defp password_protected?(_), do: true
×
87

88
  defp is_voting_assigned(assessment_id) do
UNCOV
89
    voting_assigned_question_ids =
×
90
      SubmissionVotes
UNCOV
91
      |> select([v], v.question_id)
×
92
      |> Repo.all()
93

94
    Question
95
    |> where(type: :voting)
96
    |> where(assessment_id: ^assessment_id)
UNCOV
97
    |> where([q], q.id in ^voting_assigned_question_ids)
×
UNCOV
98
    |> Repo.exists?()
×
99
  end
100
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc