Skip to content

Commit 4f1a3e6

Browse files
committed
Fix rival uniqueness check for food_court_frenzy
In the alpha test, competitors found they couldn’t submit for an answer that a rival had already submitted.
1 parent 8424c63 commit 4f1a3e6

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

registrations/lib/registrations/waydowntown.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ defmodule Registrations.Waydowntown do
391391
check_for_duplicate_normalised_submission(current_user_id, run, submission_text)
392392

393393
concept when concept in ["food_court_frenzy", "fill_in_the_blank", "count_the_items"] ->
394-
check_for_paired_answer(run, answer_id)
394+
check_for_paired_answer(current_user_id, run, answer_id)
395395

396396
concept when concept in ["orientation_memory", "cardinal_memory"] ->
397397
check_for_ordered_answer(current_user_id, run, answer_id)
@@ -414,7 +414,7 @@ defmodule Registrations.Waydowntown do
414414
end
415415
end
416416

417-
defp check_for_paired_answer(run, answer_id) do
417+
defp check_for_paired_answer(current_user_id, run, answer_id) do
418418
answer_with_submitted_id = Enum.find(run.specification.answers, fn a -> a.id == answer_id end)
419419

420420
cond do
@@ -424,7 +424,7 @@ defmodule Registrations.Waydowntown do
424424
is_nil(answer_with_submitted_id) ->
425425
{:error, "Unknown answer: #{answer_id}"}
426426

427-
Enum.any?(run.submissions, fn s -> s.correct && s.answer_id == answer_id end) ->
427+
Enum.any?(run.submissions, fn s -> s.correct && s.answer_id == answer_id && s.creator_id == current_user_id end) ->
428428
{:error, "Submission already exists for label: #{answer_with_submitted_id.label}"}
429429

430430
true ->

registrations/test/registrations_web/controllers/submission_controller_test.exs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,45 @@ defmodule RegistrationsWeb.SubmissionControllerTest do
11871187

11881188
assert json_response(conn, 201)
11891189
end
1190+
1191+
test "accepts a submission that duplicates that of another participant", %{
1192+
conn: conn,
1193+
run: run,
1194+
burger: burger
1195+
} do
1196+
other_user = insert(:user)
1197+
1198+
Repo.insert!(%Submission{
1199+
submission: "5.99",
1200+
run_id: run.id,
1201+
answer_id: burger.id,
1202+
correct: true,
1203+
creator: other_user
1204+
})
1205+
1206+
conn =
1207+
conn
1208+
|> setup_conn()
1209+
|> post(
1210+
Routes.submission_path(conn, :create),
1211+
%{
1212+
"data" => %{
1213+
"type" => "submissions",
1214+
"attributes" => %{"submission" => "5.99"},
1215+
"relationships" => %{
1216+
"run" => %{
1217+
"data" => %{"type" => "runs", "id" => run.id}
1218+
},
1219+
"answer" => %{
1220+
"data" => %{"type" => "answers", "id" => burger.id}
1221+
}
1222+
}
1223+
}
1224+
}
1225+
)
1226+
1227+
assert json_response(conn, 201)
1228+
end
11901229
end
11911230

11921231
describe "create submissions for run with multiple participants" do

0 commit comments

Comments
 (0)