• 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

14.29
/lib/cadet/assessments/submission.ex
1
defmodule Cadet.Assessments.Submission do
2
  @moduledoc false
3
  use Cadet, :model
4

5
  alias Cadet.Accounts.{CourseRegistration, Team}
6
  alias Cadet.Assessments.{Answer, Assessment, SubmissionStatus}
7

8
  @type t :: %__MODULE__{}
9

10
  schema "submissions" do
5✔
11
    field(:xp, :integer, virtual: true)
12
    field(:xp_adjustment, :integer, virtual: true)
13
    field(:xp_bonus, :integer, default: 0)
14
    field(:group_name, :string, virtual: true)
15
    field(:status, SubmissionStatus, default: :attempting)
16
    field(:question_count, :integer, virtual: true)
17
    field(:graded_count, :integer, virtual: true, default: 0)
18
    field(:grading_status, :string, virtual: true)
19
    field(:unsubmitted_at, :utc_datetime_usec)
20
    field(:submitted_at, :utc_datetime_usec)
21
    field(:is_grading_published, :boolean, default: false)
22

23
    belongs_to(:assessment, Assessment)
24
    belongs_to(:student, CourseRegistration)
25
    belongs_to(:team, Team)
26
    belongs_to(:unsubmitted_by, CourseRegistration)
27
    has_many(:answers, Answer, on_delete: :delete_all)
28

29
    timestamps()
30
  end
31

32
  @required_fields ~w(assessment_id status is_grading_published)a
33
  @optional_fields ~w(xp_bonus unsubmitted_by_id unsubmitted_at submitted_at student_id team_id)a
34

35
  def changeset(submission, params) do
36
    submission
37
    |> cast(params, @required_fields ++ @optional_fields)
38
    |> validate_number(
39
      :xp_bonus,
40
      greater_than_or_equal_to: 0
41
    )
42
    |> add_belongs_to_id_from_model([:team, :student, :assessment, :unsubmitted_by], params)
43
    |> validate_xor_relationship
44
    |> validate_required(@required_fields)
45
    |> foreign_key_constraint(:student_id)
46
    |> foreign_key_constraint(:team_id)
47
    |> foreign_key_constraint(:assessment_id)
UNCOV
48
    |> foreign_key_constraint(:unsubmitted_by_id)
×
49
  end
50

51
  defp validate_xor_relationship(changeset) do
UNCOV
52
    case {get_field(changeset, :student_id), get_field(changeset, :team_id)} do
×
53
      {nil, nil} ->
54
        changeset
55
        |> add_error(:student_id, "either student or team_id must be present")
UNCOV
56
        |> add_error(:team_id, "either student_id or team must be present")
×
57

58
      {nil, _} ->
UNCOV
59
        changeset
×
60

61
      {_, nil} ->
UNCOV
62
        changeset
×
63

64
      {_student, _team} ->
65
        changeset
66
        |> add_error(:student_id, "student and team_id cannot be present at the same time")
UNCOV
67
        |> add_error(:team_id, "student_id and team cannot be present at the same time")
×
68
    end
69
  end
70
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