Add an unique index on posts URLs

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-06-22 16:50:58 +02:00
parent 8caf1e302b
commit 7bb8568504
4 changed files with 108 additions and 0 deletions

View File

@@ -42,6 +42,29 @@ defmodule Mobilizon.PostsTest do
end
end
test "create_post/1 with an already existing URL returns error changeset" do
%Actor{} = actor = insert(:actor)
%Actor{} = group = insert(:group)
post_data =
Map.merge(@valid_attrs, %{
author_id: actor.id,
attributed_to_id: group.id,
url: "https://remote.tld/p/post"
})
{:ok, %Post{} = _post} = Posts.create_post(post_data)
assert {:error,
%Ecto.Changeset{
errors: [
url:
{"has already been taken",
[constraint: :unique, constraint_name: "posts_url_index"]}
]
}} = Posts.create_post(post_data)
end
test "create_post/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Posts.create_post(@invalid_attrs)
end