Attach actor to pictures entity
This commit is contained in:
@@ -22,17 +22,22 @@ defmodule Mobilizon.MediaTest do
|
||||
|
||||
test "get_picture!/1 returns the picture with given id" do
|
||||
picture = insert(:picture)
|
||||
assert Media.get_picture!(picture.id) == picture
|
||||
assert Media.get_picture!(picture.id).id == picture.id
|
||||
end
|
||||
|
||||
test "create_picture/1 with valid data creates a picture" do
|
||||
assert {:ok, %Picture{} = picture} = Media.create_picture(@valid_attrs)
|
||||
assert {:ok, %Picture{} = picture} =
|
||||
Media.create_picture(Map.put(@valid_attrs, :actor_id, insert(:actor).id))
|
||||
|
||||
assert picture.file.name == "something old"
|
||||
end
|
||||
|
||||
test "update_picture/2 with valid data updates the picture" do
|
||||
picture = insert(:picture)
|
||||
assert {:ok, %Picture{} = picture} = Media.update_picture(picture, @update_attrs)
|
||||
|
||||
assert {:ok, %Picture{} = picture} =
|
||||
Media.update_picture(picture, Map.put(@update_attrs, :actor_id, insert(:actor).id))
|
||||
|
||||
assert picture.file.name == "something new"
|
||||
end
|
||||
|
||||
|
||||
@@ -103,7 +103,8 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
picture: {
|
||||
name: "picture for my event",
|
||||
alt: "A very sunny landscape",
|
||||
file: "event.jpg"
|
||||
file: "event.jpg",
|
||||
actor_id: #{actor.id}
|
||||
}
|
||||
}
|
||||
) {
|
||||
@@ -148,7 +149,8 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
mutation { uploadPicture(
|
||||
name: "#{picture.name}",
|
||||
alt: "#{picture.alt}",
|
||||
file: "#{picture.file}"
|
||||
file: "#{picture.file}",
|
||||
actor_id: #{actor.id}
|
||||
) {
|
||||
id,
|
||||
url,
|
||||
|
||||
@@ -7,8 +7,9 @@ defmodule MobilizonWeb.Resolvers.PictureResolverTest do
|
||||
|
||||
setup %{conn: conn} do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
|
||||
{:ok, conn: conn, user: user}
|
||||
{:ok, conn: conn, user: user, actor: actor}
|
||||
end
|
||||
|
||||
describe "Resolver: Get picture" do
|
||||
@@ -56,14 +57,15 @@ defmodule MobilizonWeb.Resolvers.PictureResolverTest do
|
||||
end
|
||||
|
||||
describe "Resolver: Upload picture" do
|
||||
test "upload_picture/3 uploads a new picture", %{conn: conn, user: user} do
|
||||
test "upload_picture/3 uploads a new picture", %{conn: conn, user: user, actor: actor} do
|
||||
picture = %{name: "my pic", alt: "represents something", file: "picture.png"}
|
||||
|
||||
mutation = """
|
||||
mutation { uploadPicture(
|
||||
name: "#{picture.name}",
|
||||
alt: "#{picture.alt}",
|
||||
file: "#{picture.file}"
|
||||
file: "#{picture.file}",
|
||||
actor_id: #{actor.id}
|
||||
) {
|
||||
url,
|
||||
name
|
||||
@@ -92,14 +94,15 @@ defmodule MobilizonWeb.Resolvers.PictureResolverTest do
|
||||
assert json_response(res, 200)["data"]["uploadPicture"]["url"]
|
||||
end
|
||||
|
||||
test "upload_picture/3 forbids uploading if no auth", %{conn: conn} do
|
||||
test "upload_picture/3 forbids uploading if no auth", %{conn: conn, actor: actor} do
|
||||
picture = %{name: "my pic", alt: "represents something", file: "picture.png"}
|
||||
|
||||
mutation = """
|
||||
mutation { uploadPicture(
|
||||
name: "#{picture.name}",
|
||||
alt: "#{picture.alt}",
|
||||
file: "#{picture.file}"
|
||||
file: "#{picture.file}",
|
||||
actor_id: #{actor.id}
|
||||
) {
|
||||
url,
|
||||
name
|
||||
|
||||
@@ -180,7 +180,8 @@ defmodule Mobilizon.Factory do
|
||||
|
||||
def picture_factory do
|
||||
%Mobilizon.Media.Picture{
|
||||
file: build(:file)
|
||||
file: build(:file),
|
||||
actor: build(:actor)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user