• 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

70.37
/lib/cadet_web/controllers/incentives_controller.ex
1
defmodule CadetWeb.IncentivesController do
2
  use CadetWeb, :controller
3

4
  use PhoenixSwagger
5

6
  alias Cadet.Incentives.{Achievements, Goals}
7

8
  def index_achievements(conn, _) do
UNCOV
9
    course_id = conn.assigns.course_reg.course_id
×
UNCOV
10
    render(conn, "index_achievements.json", achievements: Achievements.get(course_id))
×
11
  end
12

13
  def index_goals(conn, _) do
UNCOV
14
    render(conn, "index_goals_with_progress.json",
×
UNCOV
15
      goals: Goals.get_with_progress(conn.assigns.course_reg)
×
16
    )
17
  end
18

19
  def update_progress(conn, %{"uuid" => uuid, "progress" => progress}) do
UNCOV
20
    course_reg_id = conn.assigns.course_reg.id
×
21

22
    progress
23
    |> json_to_progress(uuid, course_reg_id)
24
    |> Goals.upsert_progress(uuid, course_reg_id)
UNCOV
25
    |> handle_standard_result(conn)
×
26
  end
27

28
  defp json_to_progress(json, uuid, course_reg_id) do
UNCOV
29
    json =
×
30
      json
31
      |> snake_casify_string_keys_recursive()
32

UNCOV
33
    %{
×
34
      count: Map.get(json, "count"),
35
      completed: Map.get(json, "completed"),
36
      goal_uuid: uuid,
37
      course_reg_id: course_reg_id
38
    }
39
  end
40

41
  swagger_path :index_achievements do
1✔
42
    get("/courses/{course_id}/achievements")
43

44
    summary("Gets achievements")
45
    security([%{JWT: []}])
46

47
    response(200, "OK", Schema.array(:Achievement))
48
    response(401, "Unauthorised")
49
  end
50

51
  swagger_path :index_goals do
1✔
52
    get("/courses/{course_id}/self/goals")
53

54
    summary("Gets goals, including user's progress")
55
    security([%{JWT: []}])
56

57
    response(200, "OK", Schema.array(:GoalWithProgress))
58
    response(401, "Unauthorised")
59
  end
60

61
  swagger_path :update_progress do
1✔
62
    post("/courses/{course_id}/self/goals/{uuid}/progress")
63

64
    summary("Inserts or updates own goal progress of specifed goal")
65
    security([%{JWT: []}])
66

67
    parameters do
68
      uuid(:path, :string, "Goal UUID", required: true, format: :uuid)
69

70
      progress(
71
        :body,
72
        Schema.ref(:GoalProgress),
73
        "The goal progress to insert or update",
74
        required: true
75
      )
76
    end
77

78
    response(204, "Success")
79
    response(401, "Unauthorised")
80
  end
81

82
  def swagger_definitions do
83
    %{
1✔
84
      Achievement:
85
        swagger_schema do
1✔
86
          description("An achievement")
87

88
          properties do
1✔
89
            uuid(
90
              :string,
91
              "Achievement UUID",
92
              format: :uuid
93
            )
94

95
            title(
96
              :string,
97
              "Achievement title",
98
              required: true
99
            )
100

101
            xp(
102
              :integer,
103
              "XP earned when achievment is completed"
104
            )
105

106
            isVariableXp(
107
              :boolean,
108
              "If true, XP awarded will depend on the goal progress"
109
            )
110

111
            cardBackground(
112
              :string,
113
              "URL of the achievement's background image"
114
            )
115

116
            release(
117
              :string,
118
              "Open date, in ISO 8601 format"
119
            )
120

121
            deadline(
122
              :string,
123
              "Close date, in ISO 8601 format"
124
            )
125

126
            isTask(
127
              :boolean,
128
              "Whether the achievement is a task",
129
              required: true
130
            )
131

132
            position(
133
              :integer,
134
              "Position of the achievement in the list",
135
              required: true
136
            )
137

138
            view(
139
              ref(:AchievementView),
140
              "View properties",
141
              required: true
142
            )
143

144
            goalUuids(
145
              schema_array(:string, format: :uuid),
146
              "Goal UUIDs"
147
            )
148

149
            prerequisiteUuids(
1✔
150
              schema_array(:string, format: :uuid),
151
              "Prerequisite achievement UUIDs"
152
            )
153
          end
154
        end,
155
      AchievementView:
156
        swagger_schema do
1✔
157
          description("Achievement view properties")
158

159
          properties do
1✔
160
            coverImage(
161
              :string,
162
              "URL of the image for the view"
163
            )
164

165
            description(
166
              :string,
167
              "Achievement description"
168
            )
169

170
            completionText(
1✔
171
              :string,
172
              "Text to show when achievement is completed"
173
            )
174
          end
175
        end,
176
      Goal:
177
        swagger_schema do
1✔
178
          description("Goals, including user's progress")
179

180
          properties do
1✔
181
            uuid(
182
              :string,
183
              "Goal UUID",
184
              format: :uuid
185
            )
186

187
            text(
188
              :string,
189
              "Text to show when goal is completed"
190
            )
191

192
            targetCount(
193
              :integer,
194
              "When the count reaches this number, goal is completed"
195
            )
196

197
            type(
198
              :string,
199
              "Goal type"
200
            )
201

202
            meta(
1✔
203
              :object,
204
              "Goal satisfication information"
205
            )
206
          end
207
        end,
208
      GoalWithProgress:
209
        swagger_schema do
1✔
210
          description("Goals, including user's progress")
211

212
          properties do
1✔
213
            uuid(
214
              :string,
215
              "Goal UUID",
216
              format: :uuid
217
            )
218

219
            completed(
220
              :boolean,
221
              "Whether the goal has been completed by the user",
222
              required: true
223
            )
224

225
            text(
226
              :string,
227
              "Text to show when goal is completed"
228
            )
229

230
            count(
231
              :integer,
232
              "Counter for the progress of the goal",
233
              required: true
234
            )
235

236
            targetCount(
237
              :integer,
238
              "When the count reaches this number, goal is completed",
239
              required: true
240
            )
241

242
            type(
243
              :string,
244
              "Goal type"
245
            )
246

247
            meta(
1✔
248
              :object,
249
              "Goal satisfication information"
250
            )
251
          end
252
        end,
253
      GoalProgress:
254
        swagger_schema do
1✔
255
          description("User's goal progress")
256

257
          properties do
1✔
258
            uuid(
259
              :string,
260
              "Goal UUID",
261
              format: :uuid
262
            )
263

264
            completed(
265
              :boolean,
266
              "Whether the goal has been completed by the user"
267
            )
268

269
            count(
270
              :integer,
271
              "Counter for the progress of the goal"
272
            )
273

274
            userId(
1✔
275
              :integer,
276
              "User the goal progress belongs to"
277
            )
278
          end
279
        end
280
    }
281
  end
282
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