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

source-academy / backend / e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

31 Mar 2025 09:12AM UTC coverage: 19.982% (-73.6%) from 93.607%
e0330f2cf38b2d8af12bffd20f4cac2158d607fc-PR-1236

Pull #1236

github

RichDom2185
Redate migrations to maintain total ordering
Pull Request #1236: Added Exam mode

12 of 57 new or added lines in 8 files covered. (21.05%)

2430 existing lines in 97 files now uncovered.

671 of 3358 relevant lines covered (19.98%)

3.03 hits per line

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

18.18
/lib/cadet/accounts/query.ex
1
defmodule Cadet.Accounts.Query do
2
  @moduledoc """
3
  Generate queries related to the Accounts context
4
  """
5
  import Ecto.Query
6

7
  alias Cadet.Accounts.{User, CourseRegistration}
8
  alias Cadet.Repo
9

10
  def all_students(course_id) do
11
    User
12
    |> in_course(course_id)
UNCOV
13
    |> where([u, cr], cr.role == "student")
×
UNCOV
14
    |> Repo.all()
×
15
  end
16

17
  def username(username) do
18
    User
19
    |> of_username(username)
20
    |> preload(:latest_viewed_course)
9✔
21
  end
22

23
  @spec students_of(CourseRegistration.t()) :: Ecto.Query.t()
24
  def students_of(course_reg = %CourseRegistration{course_id: course_id}) do
25
    # Note that staff role is not check here as we assume that
26
    # group leader is assign to a staff validated by group changeset
27
    CourseRegistration
UNCOV
28
    |> where([cr], cr.course_id == ^course_id)
×
29
    |> join(:inner, [cr], g in assoc(cr, :group))
UNCOV
30
    |> where([cr, g], g.leader_id == ^course_reg.id)
×
31
  end
32

33
  def avenger_of?(avenger, student_id) do
UNCOV
34
    students = students_of(avenger)
×
35

36
    students
37
    |> Repo.get_by(id: student_id)
UNCOV
38
    |> case do
×
UNCOV
39
      nil -> false
×
UNCOV
40
      _ -> true
×
41
    end
42
  end
43

44
  defp of_username(query, username) do
45
    query |> where([a], a.username == ^username)
9✔
46
  end
47

48
  defp in_course(user, course_id) do
49
    user
50
    |> join(:inner, [u], cr in CourseRegistration, on: u.id == cr.user_id)
UNCOV
51
    |> where([_, cr], cr.course_id == ^course_id)
×
52
  end
53
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