From 4a4a1172590e009a3f644dc94a70cbe3472223e4 Mon Sep 17 00:00:00 2001
From: Troels Thomsen
Date: Mon, 12 Aug 2019 23:54:25 +0200
Subject: [PATCH] Verify behavior of concurrent registrations
---
test/conduit/accounts/accounts_test.exs | 26 +++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/test/conduit/accounts/accounts_test.exs b/test/conduit/accounts/accounts_test.exs
index 707bc55..a2fd33a 100644
--- a/test/conduit/accounts/accounts_test.exs
+++ b/test/conduit/accounts/accounts_test.exs
@@ -31,9 +31,16 @@ defmodule Conduit.AccountsTest do
@tag :integration
test "should fail when registering identical username at same time and return error" do
- 1..2
- |> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, email: "jake#{x}@jake.jake")) end) end)
- |> Enum.map(&Task.await/1)
+ [success, failure] =
+ 1..2
+ |> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, email: "jake#{x}@jake.jake")) end) end)
+ |> Enum.map(&Task.await/1)
+ |> Enum.sort()
+
+ assert {:ok, %User{}} = success
+ assert {:error, :validation_failure, errors} = failure
+
+ assert errors == %{username: ["has already been taken"]}
end
@tag :integration
@@ -60,9 +67,16 @@ defmodule Conduit.AccountsTest do
@tag :integration
test "should fail when registering identical email addresses at same time and return error" do
- 1..2
- |> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, username: "user#{x}")) end) end)
- |> Enum.map(&Task.await/1)
+ [success, failure] =
+ 1..2
+ |> Enum.map(fn x -> Task.async(fn -> Accounts.register_user(build(:user, username: "user#{x}")) end) end)
+ |> Enum.map(&Task.await/1)
+ |> Enum.sort()
+
+ assert {:ok, %User{}} = success
+ assert {:error, :validation_failure, errors} = failure
+
+ assert errors == %{email: ["has already been taken"]}
end
@tag :integration