I have a User
schema changeset with:
unique_constraint(:username, message: "Username is already taken")
And its migration has:
create(unique_index(:users, [:username]))
If I try making a user with an already-existing username in the shell, it fails correctly.
However, I cannot seem to test this. Here’s my current test:
test "create_user/1 with duplicate username error changeset" do
# Username here is "terra"
assert {:ok, %User{} = _user} = Accounts.create_user(@create_attrs)
# Just changing the email so it doesn't fail unique validation of that, username is still the same
duplicate_username = @create_attrs |> Map.put(:email, "terra.b@example.com")
assert {:error, changeset} = Accounts.create_user(duplicate_username)
end
It just succeeds and created in making the user. Any clues? Some sort of bad testing set up? Thanks.