Make sure actor usernames are unique

Closes #72

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-02-25 18:35:00 +01:00
parent 3507438f17
commit 8efb1af306
2 changed files with 33 additions and 7 deletions

View File

@@ -35,7 +35,7 @@ defmodule Mobilizon.ActorsTest do
suspended: nil,
uri: nil,
url: nil,
preferred_username: nil
preferred_username: "never"
}
@remote_account_url "https://social.tcit.fr/users/tcit"
@@ -388,6 +388,22 @@ defmodule Mobilizon.ActorsTest do
assert group.preferred_username == "some-title"
end
test "create_group/1 with an existing profile username fails" do
_actor = insert(:actor, preferred_username: @valid_attrs.preferred_username)
assert {:error,
%Ecto.Changeset{errors: [preferred_username: {"Username is already taken", []}]}} =
Actors.create_group(@valid_attrs)
end
test "create_group/1 with an existing group username fails" do
assert {:ok, %Actor{} = group} = Actors.create_group(@valid_attrs)
assert {:error,
%Ecto.Changeset{errors: [preferred_username: {"Username is already taken", []}]}} =
Actors.create_group(@valid_attrs)
end
test "create_group/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Actors.create_group(@invalid_attrs)
end