@@ -159,6 +159,166 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do
159
159
end
160
160
end
161
161
162
+ describe "GET /:assessment_id/popularVoteLeaderboard, unauthenticated" do
163
+ test "unauthorized" , % { conn: conn , courses: % { course1: course1 } } do
164
+ config = insert ( :assessment_config , % { course: course1 } )
165
+ assessment = insert ( :assessment , % { course: course1 , config: config } )
166
+
167
+ conn
168
+ |> get ( build_popular_leaderboard_url ( course1 . id , assessment . id ) )
169
+ |> response ( 401 )
170
+ end
171
+ end
172
+
173
+ describe "GET /:assessment_id/popularVoteLeaderboard, student only" do
174
+ @ tag authenticate: :student
175
+ test "Forbidden" , % { conn: conn } do
176
+ test_cr = conn . assigns . test_cr
177
+ course = test_cr . course
178
+ config = insert ( :assessment_config , % { course: course } )
179
+ assessment = insert ( :assessment , % { course: course , config: config } )
180
+
181
+ conn
182
+ |> get ( build_popular_leaderboard_url ( course . id , assessment . id ) )
183
+ |> response ( 403 )
184
+ end
185
+ end
186
+
187
+ describe "GET /:assessment_id/popularVoteLeaderboard" do
188
+ @ tag authenticate: :staff
189
+ test "successful" , % { conn: conn } do
190
+ test_cr = conn . assigns . test_cr
191
+ course = test_cr . course
192
+
193
+ config = insert ( :assessment_config , % { course: course } )
194
+ contest_assessment = insert ( :assessment , % { course: course , config: config } )
195
+ contest_students = insert_list ( 5 , :course_registration , % { course: course , role: :student } )
196
+ contest_question = insert ( :programming_question , % { assessment: contest_assessment } )
197
+
198
+ contest_submissions =
199
+ contest_students
200
+ |> Enum . map ( & insert ( :submission , % { assessment: contest_assessment , student: & 1 } ) )
201
+
202
+ contest_answer =
203
+ contest_submissions
204
+ |> Enum . map (
205
+ & insert ( :answer , % {
206
+ question: contest_question ,
207
+ submission: & 1 ,
208
+ popular_score: 10.0 ,
209
+ answer: build ( :programming_answer )
210
+ } )
211
+ )
212
+
213
+ voting_assessment = insert ( :assessment , % { course: course , config: config } )
214
+
215
+ insert (
216
+ :voting_question ,
217
+ % {
218
+ question: build ( :voting_question_content , contest_number: contest_assessment . number ) ,
219
+ assessment: voting_assessment
220
+ }
221
+ )
222
+
223
+ expected =
224
+ contest_answer
225
+ |> Enum . map (
226
+ & % {
227
+ "answer" => & 1 . answer . code ,
228
+ "student_name" => & 1 . submission . student . user . name ,
229
+ "final_score" => & 1 . popular_score
230
+ }
231
+ )
232
+
233
+ resp =
234
+ conn
235
+ |> get ( build_popular_leaderboard_url ( course . id , voting_assessment . id ) )
236
+ |> json_response ( 200 )
237
+
238
+ assert expected == resp
239
+ end
240
+ end
241
+
242
+ describe "GET /:assessment_id/scoreLeaderboard, unauthenticated" do
243
+ test "unauthorized" , % { conn: conn , courses: % { course1: course1 } } do
244
+ config = insert ( :assessment_config , % { course: course1 } )
245
+ assessment = insert ( :assessment , % { course: course1 , config: config } )
246
+
247
+ conn
248
+ |> get ( build_popular_leaderboard_url ( course1 . id , assessment . id ) )
249
+ |> response ( 401 )
250
+ end
251
+ end
252
+
253
+ describe "GET /:assessment_id/scoreLeaderboard, student only" do
254
+ @ tag authenticate: :student
255
+ test "Forbidden" , % { conn: conn } do
256
+ test_cr = conn . assigns . test_cr
257
+ course = test_cr . course
258
+ config = insert ( :assessment_config , % { course: course } )
259
+ assessment = insert ( :assessment , % { course: course , config: config } )
260
+
261
+ conn
262
+ |> get ( build_popular_leaderboard_url ( course . id , assessment . id ) )
263
+ |> response ( 403 )
264
+ end
265
+ end
266
+
267
+ describe "GET /:assessment_id/scoreLeaderboard" do
268
+ @ tag authenticate: :staff
269
+ test "successful" , % { conn: conn } do
270
+ test_cr = conn . assigns . test_cr
271
+ course = test_cr . course
272
+
273
+ config = insert ( :assessment_config , % { course: course } )
274
+ contest_assessment = insert ( :assessment , % { course: course , config: config } )
275
+ contest_students = insert_list ( 5 , :course_registration , % { course: course , role: :student } )
276
+ contest_question = insert ( :programming_question , % { assessment: contest_assessment } )
277
+
278
+ contest_submissions =
279
+ contest_students
280
+ |> Enum . map ( & insert ( :submission , % { assessment: contest_assessment , student: & 1 } ) )
281
+
282
+ contest_answer =
283
+ contest_submissions
284
+ |> Enum . map (
285
+ & insert ( :answer , % {
286
+ question: contest_question ,
287
+ submission: & 1 ,
288
+ relative_score: 10.0 ,
289
+ answer: build ( :programming_answer )
290
+ } )
291
+ )
292
+
293
+ voting_assessment = insert ( :assessment , % { course: course , config: config } )
294
+
295
+ insert (
296
+ :voting_question ,
297
+ % {
298
+ question: build ( :voting_question_content , contest_number: contest_assessment . number ) ,
299
+ assessment: voting_assessment
300
+ }
301
+ )
302
+
303
+ expected =
304
+ contest_answer
305
+ |> Enum . map (
306
+ & % {
307
+ "answer" => & 1 . answer . code ,
308
+ "student_name" => & 1 . submission . student . user . name ,
309
+ "final_score" => & 1 . relative_score
310
+ }
311
+ )
312
+
313
+ resp =
314
+ conn
315
+ |> get ( build_score_leaderboard_url ( course . id , voting_assessment . id ) )
316
+ |> json_response ( 200 )
317
+
318
+ assert expected == resp
319
+ end
320
+ end
321
+
162
322
describe "POST /, unauthenticated" do
163
323
test "unauthorized" , % {
164
324
conn: conn ,
@@ -757,6 +917,12 @@ defmodule CadetWeb.AdminAssessmentsControllerTest do
757
917
defp build_user_assessments_url ( course_id , course_reg_id ) ,
758
918
do: "/v2/courses/#{ course_id } /admin/users/#{ course_reg_id } /assessments"
759
919
920
+ defp build_popular_leaderboard_url ( course_id , assessment_id ) ,
921
+ do: "#{ build_url ( course_id , assessment_id ) } /popularVoteLeaderboard"
922
+
923
+ defp build_score_leaderboard_url ( course_id , assessment_id ) ,
924
+ do: "#{ build_url ( course_id , assessment_id ) } /scoreLeaderboard"
925
+
760
926
defp open_at_asc_comparator ( x , y ) , do: Timex . before? ( x . open_at , y . open_at )
761
927
762
928
defp get_assessment_status ( course_reg = % CourseRegistration { } , assessment = % Assessment { } ) do
0 commit comments