From c447552453f78799755de73f66999e4c9d20383c Mon Sep 17 00:00:00 2001 From: Chen Yanyu <39845424+YaleChen299@users.noreply.github.com> Date: Fri, 24 Sep 2021 14:44:32 +0800 Subject: [PATCH] Contest leaderboard hiding (#826) * Add contest leaderboard hiding * fix open leaderboard wrong condition --- lib/cadet/assessments/assessments.ex | 4 ++-- .../controllers/assessments_controller_test.exs | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/cadet/assessments/assessments.ex b/lib/cadet/assessments/assessments.ex index f95cdfec2..d37b0c45c 100644 --- a/lib/cadet/assessments/assessments.ex +++ b/lib/cadet/assessments/assessments.ex @@ -953,8 +953,8 @@ defmodule Cadet.Assessments do defp leaderboard_open?(assessment, voting_question) do Timex.before?( - Timex.now(), - Timex.shift(assessment.close_at, hours: voting_question.question["reveal_hours"]) + Timex.shift(assessment.close_at, hours: voting_question.question["reveal_hours"]), + Timex.now() ) end diff --git a/test/cadet_web/controllers/assessments_controller_test.exs b/test/cadet_web/controllers/assessments_controller_test.exs index 1a27ec05c..709fa960e 100644 --- a/test/cadet_web/controllers/assessments_controller_test.exs +++ b/test/cadet_web/controllers/assessments_controller_test.exs @@ -480,6 +480,15 @@ defmodule CadetWeb.AssessmentsControllerTest do role_crs: role_crs, assessments: assessments } do + voting_assessment = assessments["practical"].assessment + + voting_assessment + |> Assessment.changeset(%{ + open_at: Timex.shift(Timex.now(), days: -30), + close_at: Timex.shift(Timex.now(), days: -20) + }) + |> Repo.update() + voting_question = assessments["practical"].voting_questions |> List.first() contest_assessment_number = voting_question.question.contest_number @@ -548,8 +557,7 @@ defmodule CadetWeb.AssessmentsControllerTest do voting_assessment |> Assessment.changeset(%{ - open_at: Timex.shift(Timex.now(), days: -30), - close_at: Timex.shift(Timex.now(), days: -20) + close_at: Timex.shift(Timex.now(), days: 20) }) |> Repo.update() @@ -621,8 +629,7 @@ defmodule CadetWeb.AssessmentsControllerTest do voting_assessment |> Assessment.changeset(%{ - open_at: Timex.shift(Timex.now(), days: -30), - close_at: Timex.shift(Timex.now(), days: -20) + close_at: Timex.shift(Timex.now(), days: 20) }) |> Repo.update()