Refactor media upload
Use Upload Media logic from Pleroma Backend changes for picture upload Move AS <-> Model conversion to separate module Front changes Downgrade apollo-client: https://github.com/Akryum/vue-apollo/issues/577 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -4,6 +4,7 @@ defmodule Mobilizon.ActorsTest do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{Actor, Member, Follower, Bot}
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Media.File
|
||||
import Mobilizon.Factory
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
|
||||
@@ -91,13 +92,23 @@ defmodule Mobilizon.ActorsTest do
|
||||
|
||||
test "get_actor_by_name/1 returns a remote actor" do
|
||||
use_cassette "actors/remote_actor_mastodon_tcit" do
|
||||
with {:ok,
|
||||
%Actor{id: actor_id, preferred_username: preferred_username, domain: domain} =
|
||||
_actor} <- Actors.get_or_fetch_by_url(@remote_account_url),
|
||||
%Actor{id: actor_found_id} <-
|
||||
Actors.get_actor_by_name("#{preferred_username}@#{domain}").id do
|
||||
assert actor_found_id == actor_id
|
||||
end
|
||||
{:ok,
|
||||
%Actor{
|
||||
id: actor_id,
|
||||
preferred_username: preferred_username,
|
||||
domain: domain,
|
||||
avatar: %File{name: picture_name} = _picture
|
||||
} = _actor} = Actors.get_or_fetch_by_url(@remote_account_url)
|
||||
|
||||
assert picture_name == "avatar"
|
||||
|
||||
%Actor{
|
||||
id: actor_found_id,
|
||||
avatar: %File{name: picture_name} = _picture
|
||||
} = Actors.get_actor_by_name("#{preferred_username}@#{domain}")
|
||||
|
||||
assert actor_found_id == actor_id
|
||||
assert picture_name == "avatar"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
50
test/mobilizon/media/media_test.exs
Normal file
50
test/mobilizon/media/media_test.exs
Normal file
@@ -0,0 +1,50 @@
|
||||
defmodule Mobilizon.MediaTest do
|
||||
use Mobilizon.DataCase
|
||||
|
||||
alias Mobilizon.Media
|
||||
import Mobilizon.Factory
|
||||
|
||||
describe "media" do
|
||||
alias Mobilizon.Media.Picture
|
||||
|
||||
@valid_attrs %{
|
||||
file: %{
|
||||
url: "https://something.tld/media/something",
|
||||
name: "something old"
|
||||
}
|
||||
}
|
||||
@update_attrs %{
|
||||
file: %{
|
||||
url: "https://something.tld/media/something_updated",
|
||||
name: "something new"
|
||||
}
|
||||
}
|
||||
|
||||
test "get_picture!/1 returns the picture with given id" do
|
||||
picture = insert(:picture)
|
||||
assert Media.get_picture!(picture.id) == picture
|
||||
end
|
||||
|
||||
test "create_picture/1 with valid data creates a picture" do
|
||||
assert {:ok, %Picture{} = picture} = Media.create_picture(@valid_attrs)
|
||||
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 picture.file.name == "something new"
|
||||
end
|
||||
|
||||
test "delete_picture/1 deletes the picture" do
|
||||
picture = insert(:picture)
|
||||
assert {:ok, %Picture{}} = Media.delete_picture(picture)
|
||||
assert_raise Ecto.NoResultsError, fn -> Media.get_picture!(picture.id) end
|
||||
end
|
||||
|
||||
test "change_picture/1 returns a picture changeset" do
|
||||
picture = insert(:picture)
|
||||
assert %Ecto.Changeset{} = Media.change_picture(picture)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -72,15 +72,15 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
|
||||
describe "fetching an" do
|
||||
test "object by url" do
|
||||
use_cassette "activity_pub/fetch_social_tcit_fr_status" do
|
||||
use_cassette "activity_pub/fetch_framapiaf_framasoft_status" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://social.tcit.fr/users/tcit/statuses/99908779444618462"
|
||||
"https://framapiaf.org/users/Framasoft/statuses/102093631881522097"
|
||||
)
|
||||
|
||||
{:ok, object_again} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://social.tcit.fr/users/tcit/statuses/99908779444618462"
|
||||
"https://framapiaf.org/users/Framasoft/statuses/102093631881522097"
|
||||
)
|
||||
|
||||
assert object.id == object_again.id
|
||||
@@ -88,14 +88,12 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
end
|
||||
|
||||
test "object reply by url" do
|
||||
use_cassette "activity_pub/fetch_social_tcit_fr_reply" do
|
||||
use_cassette "activity_pub/fetch_framasoft_framapiaf_reply" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://social.tcit.fr/users/tcit/statuses/101160654038714030"
|
||||
)
|
||||
ActivityPub.fetch_object_from_url("https://mamot.fr/@imacrea/102094441327423790")
|
||||
|
||||
assert object.in_reply_to_comment.url ==
|
||||
"https://social.tcit.fr/users/tcit/statuses/101160195754333819"
|
||||
"https://framapiaf.org/users/Framasoft/statuses/102093632302210150"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,7 +101,7 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
use_cassette "activity_pub/fetch_reply_to_framatube" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_object_from_url(
|
||||
"https://framapiaf.org/@troisiemelobe/101156292125317651"
|
||||
"https://diaspodon.fr/users/dada/statuses/100820008426311925"
|
||||
)
|
||||
|
||||
assert object.in_reply_to_comment == nil
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
defmodule Mobilizon.Service.ActivityPub.Converters.ActorTest do
|
||||
use Mobilizon.DataCase
|
||||
alias Mobilizon.Service.ActivityPub.Converters.Actor, as: ActorConverter
|
||||
alias Mobilizon.Actors.Actor
|
||||
|
||||
describe "actor to AS" do
|
||||
test "valid actor to as" do
|
||||
data = ActorConverter.model_to_as(%Actor{type: :Person, preferred_username: "test_account"})
|
||||
assert is_map(data)
|
||||
assert data["type"] == "Person"
|
||||
assert data["preferred_username"] == "test_account"
|
||||
end
|
||||
end
|
||||
|
||||
describe "AS to Actor" do
|
||||
test "valid as data to model" do
|
||||
actor =
|
||||
ActorConverter.as_to_model_data(%{
|
||||
"type" => "Person",
|
||||
"preferred_username" => "test_account"
|
||||
})
|
||||
|
||||
assert actor["type"] == :Person
|
||||
assert actor["preferred_username"] == "test_account"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -307,12 +307,6 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
{:ok, %Actor{} = actor} = Actors.get_actor_by_url(data["actor"])
|
||||
assert actor.name == "gargle"
|
||||
|
||||
assert actor.avatar_url ==
|
||||
"https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
|
||||
|
||||
assert actor.banner_url ==
|
||||
"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
|
||||
assert actor.summary == "<p>Some bio</p>"
|
||||
end
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ defmodule Mobilizon.Service.ActivityPub.UtilsTest do
|
||||
"id" => Routes.page_url(Endpoint, :comment, reply.uuid),
|
||||
"inReplyTo" => comment.url,
|
||||
"attributedTo" => reply.actor.url
|
||||
} == Utils.make_comment_data(reply)
|
||||
} == Mobilizon.Service.ActivityPub.Converters.Comment.model_to_as(reply)
|
||||
end
|
||||
|
||||
test "comment data from map" do
|
||||
|
||||
Reference in New Issue
Block a user