Refactor Core things, including Ecto handling, ActivityPub & Transmogrifier modules
* Data doesn't need anymore to be converted to ActivityStream format to be saved (this was taken from Pleroma and not at all a good idea here) * Everything saved when creating an event is inserted into PostgreSQL in a single transaction
This commit is contained in:
@@ -28,9 +28,9 @@
|
||||
"attributedTo": "https://framapiaf.org/users/admin",
|
||||
"cc": [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
"https://framapiaf.org/users/tcit"
|
||||
],
|
||||
"content": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span> #moo</p>",
|
||||
"content": "<p><span class=\"h-card\"><a href=\"https://framapiaf.org/users/tcit\" class=\"u-url mention\">@<span>tcit</span></a></span> #moo</p>",
|
||||
"conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
|
||||
"id": "https://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"inReplyTo": null,
|
||||
@@ -40,8 +40,8 @@
|
||||
"summary": "cw",
|
||||
"tag": [
|
||||
{
|
||||
"href": "http://localtesting.pleroma.lol/users/lain",
|
||||
"name": "@lain@localtesting.pleroma.lol",
|
||||
"href": "https://framapiaf.org/users/tcit",
|
||||
"name": "@tcit@framapiaf.org",
|
||||
"type": "Mention"
|
||||
},
|
||||
{
|
||||
|
||||
8
test/fixtures/mastodon-post-activity.json
vendored
8
test/fixtures/mastodon-post-activity.json
vendored
@@ -28,9 +28,9 @@
|
||||
"attributedTo": "https://framapiaf.org/users/admin",
|
||||
"cc": [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
"https://framapiaf.org/users/tcit"
|
||||
],
|
||||
"content": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>",
|
||||
"content": "<p><span class=\"h-card\"><a href=\"https://framapiaf.org/users/tcit\" class=\"u-url mention\">@<span>tcit</span></a></span></p>",
|
||||
"conversation": "tag:mastodon.example.org,2018-02-12:objectId=20:objectType=Conversation",
|
||||
"id": "https://framapiaf.org/users/admin/statuses/99512778738411822",
|
||||
"inReplyTo": null,
|
||||
@@ -40,8 +40,8 @@
|
||||
"summary": "cw",
|
||||
"tag": [
|
||||
{
|
||||
"href": "http://localtesting.pleroma.lol/users/lain",
|
||||
"name": "@lain@localtesting.pleroma.lol",
|
||||
"href": "https://framapiaf.org/users/tcit",
|
||||
"name": "@tcit@framapiaf.org",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
|
||||
10
test/fixtures/mobilizon-post-activity.json
vendored
10
test/fixtures/mobilizon-post-activity.json
vendored
@@ -14,7 +14,7 @@
|
||||
"actor": "https://event1.tcit.fr/@tcit",
|
||||
"cc": [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
"https://framapiaf.org/users/tcit"
|
||||
],
|
||||
"id": "https://event1.tcit.fr/@tcit/events/109ccdfd-ee3e-46e1-a877-6c228763df0c/activity",
|
||||
"object": {
|
||||
@@ -23,9 +23,9 @@
|
||||
"startTime": "2018-02-12T14:08:20Z",
|
||||
"cc": [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
"https://framapiaf.org/users/tcit"
|
||||
],
|
||||
"content": "<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>",
|
||||
"content": "<p><span class=\"h-card\"><a href=\"https://framapiaf.org/users/tcit\" class=\"u-url mention\">@<span>tcit</span></a></span></p>",
|
||||
"category": "TODO remove me",
|
||||
"id": "https://event1.tcit.fr/@tcit/events/109ccdfd-ee3e-46e1-a877-6c228763df0c",
|
||||
"inReplyTo": null,
|
||||
@@ -46,8 +46,8 @@
|
||||
"published": "2018-02-12T14:08:20Z",
|
||||
"tag": [
|
||||
{
|
||||
"href": "http://localtesting.pleroma.lol/users/lain",
|
||||
"name": "@lain@localtesting.pleroma.lol",
|
||||
"href": "https://framapiaf.org/users/tcit",
|
||||
"name": "@tcit@framapiaf.org",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -99,7 +99,7 @@ defmodule Mobilizon.ActorsTest do
|
||||
preferred_username: preferred_username,
|
||||
domain: domain,
|
||||
avatar: %FileModel{name: picture_name} = _picture
|
||||
} = _actor} = ActivityPub.get_or_fetch_by_url(@remote_account_url)
|
||||
} = _actor} = ActivityPub.get_or_fetch_actor_by_url(@remote_account_url)
|
||||
|
||||
assert picture_name == "avatar"
|
||||
|
||||
@@ -149,7 +149,7 @@ defmodule Mobilizon.ActorsTest do
|
||||
|
||||
test "get_actor_by_name_with_preload!/1 returns the remote actor with its organized events" do
|
||||
use_cassette "actors/remote_actor_mastodon_tcit" do
|
||||
with {:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_by_url(@remote_account_url) do
|
||||
with {:ok, %Actor{} = actor} <- ActivityPub.get_or_fetch_actor_by_url(@remote_account_url) do
|
||||
assert Actors.get_actor_by_name_with_preload(
|
||||
"#{actor.preferred_username}@#{actor.domain}"
|
||||
).organized_events == []
|
||||
@@ -178,7 +178,8 @@ defmodule Mobilizon.ActorsTest do
|
||||
test "test build_actors_by_username_or_name_page/4 returns actors with similar usernames",
|
||||
%{actor: %Actor{id: actor_id}} do
|
||||
use_cassette "actors/remote_actor_mastodon_tcit" do
|
||||
with {:ok, %Actor{id: actor2_id}} <- ActivityPub.get_or_fetch_by_url(@remote_account_url) do
|
||||
with {:ok, %Actor{id: actor2_id}} <-
|
||||
ActivityPub.get_or_fetch_actor_by_url(@remote_account_url) do
|
||||
%Page{total: 2, elements: actors} =
|
||||
Actors.build_actors_by_username_or_name_page("tcit", [:Person])
|
||||
|
||||
@@ -253,12 +254,11 @@ defmodule Mobilizon.ActorsTest do
|
||||
}
|
||||
|
||||
{:ok, data} = MobilizonWeb.Upload.store(file)
|
||||
url = hd(data["url"])["href"]
|
||||
|
||||
assert {:ok, actor} =
|
||||
Actors.update_actor(
|
||||
actor,
|
||||
Map.put(@update_attrs, :avatar, %{name: file.filename, url: url})
|
||||
Map.put(@update_attrs, :avatar, %{name: file.filename, url: data.url})
|
||||
)
|
||||
|
||||
assert %Actor{} = actor
|
||||
|
||||
@@ -115,7 +115,7 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
test "create_event/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Events.create_event(@invalid_attrs)
|
||||
assert {:error, :insert, %Ecto.Changeset{}, _} = Events.create_event(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_event/2 with valid data updates the event", %{event: event} do
|
||||
@@ -128,7 +128,7 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
test "update_event/2 with invalid data returns error changeset", %{event: event} do
|
||||
assert {:error, %Ecto.Changeset{}} = Events.update_event(event, @invalid_attrs)
|
||||
assert {:error, :update, %Ecto.Changeset{}, _} = Events.update_event(event, @invalid_attrs)
|
||||
assert event.title == Events.get_event!(event.id).title
|
||||
end
|
||||
|
||||
@@ -345,7 +345,8 @@ defmodule Mobilizon.EventsTest do
|
||||
end
|
||||
|
||||
test "create_participant/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Events.create_participant(@invalid_attrs)
|
||||
assert {:error, :participant, %Ecto.Changeset{}, _} =
|
||||
Events.create_participant(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_participant/2 with valid data updates the participant", %{
|
||||
|
||||
@@ -14,12 +14,10 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Converter
|
||||
alias Mobilizon.Service.HTTPSignatures.Signature
|
||||
|
||||
alias MobilizonWeb.ActivityPub.ActorView
|
||||
@activity_pub_public_audience "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
setup_all do
|
||||
HTTPoison.start()
|
||||
@@ -53,7 +51,7 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
test "returns an actor from url" do
|
||||
use_cassette "activity_pub/fetch_framapiaf.org_users_tcit" do
|
||||
assert {:ok, %Actor{preferred_username: "tcit", domain: "framapiaf.org"}} =
|
||||
ActivityPub.get_or_fetch_by_url("https://framapiaf.org/users/tcit")
|
||||
ActivityPub.get_or_fetch_actor_by_url("https://framapiaf.org/users/tcit")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -165,28 +163,15 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
|
||||
test "it creates an update activity with the new actor data" do
|
||||
actor = insert(:actor)
|
||||
actor_data = ActorView.render("actor.json", %{actor: actor})
|
||||
actor_data = Map.put(actor_data, "summary", @updated_actor_summary)
|
||||
actor_data = %{summary: @updated_actor_summary}
|
||||
|
||||
{:ok, update, updated_actor} =
|
||||
ActivityPub.update(%{
|
||||
actor: actor_data["url"],
|
||||
to: [actor.url <> "/followers"],
|
||||
cc: [],
|
||||
object: actor_data
|
||||
})
|
||||
{:ok, update, _} = ActivityPub.update(:actor, actor, actor_data, false)
|
||||
|
||||
assert update.data["actor"] == actor.url
|
||||
assert update.data["to"] == [actor.url <> "/followers"]
|
||||
assert update.data["object"]["id"] == actor_data["id"]
|
||||
assert update.data["object"]["type"] == actor_data["type"]
|
||||
assert update.data["to"] == [@activity_pub_public_audience]
|
||||
assert update.data["object"]["id"] == actor.url
|
||||
assert update.data["object"]["type"] == "Person"
|
||||
assert update.data["object"]["summary"] == @updated_actor_summary
|
||||
|
||||
refute updated_actor.summary == actor.summary
|
||||
|
||||
{:ok, %Actor{} = database_actor} = Mobilizon.Actors.get_actor_by_url(actor.url)
|
||||
assert database_actor.summary == @updated_actor_summary
|
||||
assert database_actor.preferred_username == actor.preferred_username
|
||||
end
|
||||
|
||||
@updated_start_time DateTime.utc_now() |> DateTime.truncate(:second)
|
||||
@@ -194,28 +179,15 @@ defmodule Mobilizon.Service.ActivityPub.ActivityPubTest do
|
||||
test "it creates an update activity with the new event data" do
|
||||
actor = insert(:actor)
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
event_data = Converter.Event.model_to_as(event)
|
||||
event_data = Map.put(event_data, "startTime", @updated_start_time)
|
||||
event_data = %{begins_on: @updated_start_time}
|
||||
|
||||
{:ok, update, updated_event} =
|
||||
ActivityPub.update(%{
|
||||
actor: actor.url,
|
||||
to: [actor.url <> "/followers"],
|
||||
cc: [],
|
||||
object: event_data
|
||||
})
|
||||
{:ok, update, _} = ActivityPub.update(:event, event, event_data)
|
||||
|
||||
assert update.data["actor"] == actor.url
|
||||
assert update.data["to"] == [actor.url <> "/followers"]
|
||||
assert update.data["object"]["id"] == event_data["id"]
|
||||
assert update.data["object"]["type"] == event_data["type"]
|
||||
assert update.data["object"]["startTime"] == @updated_start_time
|
||||
|
||||
refute updated_event.begins_on == event.begins_on
|
||||
|
||||
%Event{} = database_event = Mobilizon.Events.get_event_by_url(event.url)
|
||||
assert database_event.begins_on == @updated_start_time
|
||||
assert database_event.title == event.title
|
||||
assert update.data["to"] == [@activity_pub_public_audience]
|
||||
assert update.data["object"]["id"] == event.url
|
||||
assert update.data["object"]["type"] == "Event"
|
||||
assert update.data["object"]["startTime"] == DateTime.to_iso8601(@updated_start_time)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ defmodule Mobilizon.Service.ActivityPub.Converter.ActorTest do
|
||||
|
||||
describe "AS to Actor" do
|
||||
test "valid as data to model" do
|
||||
actor =
|
||||
{:ok, actor} =
|
||||
ActorConverter.as_to_model_data(%{
|
||||
"type" => "Person",
|
||||
"preferredUsername" => "test_account"
|
||||
|
||||
@@ -124,10 +124,10 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
|
||||
assert data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert data["cc"] == [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://mobilizon.com/@tcit"
|
||||
]
|
||||
# assert data["cc"] == [
|
||||
# "https://framapiaf.org/users/admin/followers",
|
||||
# "http://mobilizon.com/@tcit"
|
||||
# ]
|
||||
|
||||
assert data["actor"] == "https://framapiaf.org/users/admin"
|
||||
|
||||
@@ -136,16 +136,14 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
|
||||
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
|
||||
assert object["cc"] == [
|
||||
"https://framapiaf.org/users/admin/followers",
|
||||
"http://localtesting.pleroma.lol/users/lain"
|
||||
]
|
||||
# assert object["cc"] == [
|
||||
# "https://framapiaf.org/users/admin/followers",
|
||||
# "http://localtesting.pleroma.lol/users/lain"
|
||||
# ]
|
||||
|
||||
assert object["actor"] == "https://framapiaf.org/users/admin"
|
||||
assert object["attributedTo"] == "https://framapiaf.org/users/admin"
|
||||
|
||||
assert object["sensitive"] == true
|
||||
|
||||
{:ok, %Actor{}} = Actors.get_actor_by_url(object["actor"])
|
||||
end
|
||||
|
||||
@@ -153,6 +151,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Jason.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(data)
|
||||
assert Enum.at(data["object"]["tag"], 0)["name"] == "@tcit@framapiaf.org"
|
||||
assert Enum.at(data["object"]["tag"], 1)["name"] == "#moo"
|
||||
end
|
||||
|
||||
@@ -347,9 +346,9 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
|> Map.put("actor", data["actor"])
|
||||
|> Map.put("object", object)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(update_data)
|
||||
{:ok, %Activity{data: _data, local: false}, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
{:ok, %Actor{} = actor} = Actors.get_actor_by_url(data["actor"])
|
||||
{:ok, %Actor{} = actor} = Actors.get_actor_by_url(update_data["actor"])
|
||||
assert actor.name == "nextsoft"
|
||||
|
||||
assert actor.summary == "<p>Some bio</p>"
|
||||
@@ -406,7 +405,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
|
||||
test "it works for incoming deletes" do
|
||||
%Actor{url: actor_url} = actor = insert(:actor)
|
||||
%Comment{url: comment_url} = insert(:comment, actor: actor)
|
||||
%Comment{url: comment_url} = insert(:comment, actor: nil, actor_id: actor.id)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete.json")
|
||||
@@ -622,8 +621,8 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
{:ok, activity, _} = Transmogrifier.handle_incoming(accept_data)
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
assert activity.data["object"] =~ "/follow/"
|
||||
assert activity.data["object"]["id"] == follow_activity.data["id"]
|
||||
assert activity.data["object"]["id"] =~ "/follow/"
|
||||
assert activity.data["id"] =~ "/accept/follow/"
|
||||
|
||||
{:ok, follower} = Actors.get_actor_by_url(follower.url)
|
||||
@@ -756,8 +755,8 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
|> Map.put("object", participation.url)
|
||||
|
||||
{:ok, accept_activity, _} = Transmogrifier.handle_incoming(accept_data)
|
||||
assert accept_activity.data["object"] == join_activity.data["id"]
|
||||
assert accept_activity.data["object"] =~ "/join/"
|
||||
assert accept_activity.data["object"]["id"] == join_activity.data["id"]
|
||||
assert accept_activity.data["object"]["id"] =~ "/join/"
|
||||
assert accept_activity.data["id"] =~ "/accept/join/"
|
||||
|
||||
# We don't accept already accepted Accept activities
|
||||
@@ -847,10 +846,10 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
other_actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} =
|
||||
API.Comments.create_comment(
|
||||
actor.preferred_username,
|
||||
"hey, @#{other_actor.preferred_username}, how are ya? #2hu"
|
||||
)
|
||||
API.Comments.create_comment(%{
|
||||
actor_id: actor.id,
|
||||
text: "hey, @#{other_actor.preferred_username}, how are ya? #2hu"
|
||||
})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
object = modified["object"]
|
||||
@@ -883,7 +882,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it adds the json-ld context and the conversation property" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "hey"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
@@ -893,7 +892,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it sets the 'attributedTo' property to the actor of the object if it doesn't have one" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "hey")
|
||||
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "hey"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
@@ -903,7 +902,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it strips internal hashtag data" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"})
|
||||
|
||||
expected_tag = %{
|
||||
"href" => MobilizonWeb.Endpoint.url() <> "/tags/2hu",
|
||||
@@ -919,7 +918,7 @@ defmodule Mobilizon.Service.ActivityPub.TransmogrifierTest do
|
||||
test "it strips internal fields" do
|
||||
actor = insert(:actor)
|
||||
|
||||
{:ok, activity, _} = API.Comments.create_comment(actor.preferred_username, "#2hu")
|
||||
{:ok, activity, _} = API.Comments.create_comment(%{actor_id: actor.id, text: "#2hu"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
|
||||
@@ -17,12 +17,21 @@ defmodule Mobilizon.Service.ActivityPub.UtilsTest do
|
||||
describe "make" do
|
||||
test "comment data from struct" do
|
||||
comment = insert(:comment)
|
||||
reply = insert(:comment, in_reply_to_comment: comment)
|
||||
tag = insert(:tag, title: "MyTag")
|
||||
reply = insert(:comment, in_reply_to_comment: comment, tags: [tag])
|
||||
|
||||
assert %{
|
||||
"type" => "Note",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"content" => reply.text,
|
||||
"cc" => [],
|
||||
"tag" => [
|
||||
%{
|
||||
"href" => "http://mobilizon.test/tags/#{tag.slug}",
|
||||
"name" => "#MyTag",
|
||||
"type" => "Hashtag"
|
||||
}
|
||||
],
|
||||
"content" => "My Comment",
|
||||
"actor" => reply.actor.url,
|
||||
"uuid" => reply.uuid,
|
||||
"id" => Routes.page_url(Endpoint, :comment, reply.uuid),
|
||||
|
||||
@@ -18,8 +18,7 @@ defmodule MobilizonWeb.Plugs.UploadedMediaPlugTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file)
|
||||
[%{"href" => attachment_url} | _] = data["url"]
|
||||
[attachment_url: attachment_url]
|
||||
[attachment_url: data.url]
|
||||
end
|
||||
|
||||
setup_all :upload_file
|
||||
|
||||
@@ -18,7 +18,7 @@ defmodule MobilizonWeb.Resolvers.CommentResolverTest do
|
||||
mutation {
|
||||
createComment(
|
||||
text: "#{@comment.text}",
|
||||
actor_username: "#{actor.preferred_username}"
|
||||
actor_id: "#{actor.id}"
|
||||
) {
|
||||
text,
|
||||
uuid
|
||||
|
||||
@@ -363,7 +363,7 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
actor: actor,
|
||||
user: user
|
||||
} do
|
||||
address = insert(:address)
|
||||
address = %{street: "I am a street, please believe me", locality: "Where ever"}
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
@@ -383,6 +383,7 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
title,
|
||||
uuid,
|
||||
physicalAddress {
|
||||
id,
|
||||
url,
|
||||
geom,
|
||||
street
|
||||
@@ -403,8 +404,8 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["street"] ==
|
||||
address.street
|
||||
|
||||
refute json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["url"] ==
|
||||
address.url
|
||||
address_url = json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["url"]
|
||||
address_id = json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["id"]
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
@@ -417,12 +418,13 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
organizer_actor_id: "#{actor.id}",
|
||||
category: "birthday",
|
||||
physical_address: {
|
||||
url: "#{address.url}"
|
||||
id: "#{address_id}"
|
||||
}
|
||||
) {
|
||||
title,
|
||||
uuid,
|
||||
physicalAddress {
|
||||
id,
|
||||
url,
|
||||
geom,
|
||||
street
|
||||
@@ -443,8 +445,11 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["street"] ==
|
||||
address.street
|
||||
|
||||
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["id"] ==
|
||||
address_id
|
||||
|
||||
assert json_response(res, 200)["data"]["createEvent"]["physicalAddress"]["url"] ==
|
||||
address.url
|
||||
address_url
|
||||
end
|
||||
|
||||
test "create_event/3 creates an event with an attached picture", %{
|
||||
@@ -501,7 +506,7 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
|
||||
"picture for my event"
|
||||
end
|
||||
|
||||
test "create_event/3 creates an event with an picture URL", %{
|
||||
test "create_event/3 creates an event with an picture ID", %{
|
||||
conn: conn,
|
||||
actor: actor,
|
||||
user: user
|
||||
|
||||
@@ -2,7 +2,6 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
require Logger
|
||||
|
||||
@non_existent_username "nonexistent"
|
||||
@new_group_params %{groupname: "new group"}
|
||||
@@ -36,7 +35,7 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"Actor id is not owned by authenticated user"
|
||||
"Creator actor id is not owned by the current user"
|
||||
end
|
||||
|
||||
test "create_group/3 creates a group and check a group with this name does not already exist",
|
||||
|
||||
@@ -561,8 +561,8 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|
||||
event(uuid: "#{event.uuid}") {
|
||||
uuid,
|
||||
participantStats {
|
||||
approved,
|
||||
unapproved,
|
||||
going,
|
||||
notApproved,
|
||||
rejected
|
||||
}
|
||||
}
|
||||
@@ -574,8 +574,8 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
||||
|
||||
assert json_response(res, 200)["data"]["event"]["uuid"] == to_string(event.uuid)
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["approved"] == 1
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["unapproved"] == 0
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["going"] == 1
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["notApproved"] == 0
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["rejected"] == 0
|
||||
|
||||
moderator = insert(:actor)
|
||||
@@ -586,18 +586,18 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|
||||
actor_id: moderator.id
|
||||
})
|
||||
|
||||
unapproved = insert(:actor)
|
||||
not_approved = insert(:actor)
|
||||
|
||||
Events.create_participant(%{
|
||||
role: :not_approved,
|
||||
event_id: event.id,
|
||||
actor_id: unapproved.id
|
||||
actor_id: not_approved.id
|
||||
})
|
||||
|
||||
Events.create_participant(%{
|
||||
role: :rejected,
|
||||
event_id: event.id,
|
||||
actor_id: unapproved.id
|
||||
actor_id: not_approved.id
|
||||
})
|
||||
|
||||
query = """
|
||||
@@ -605,8 +605,8 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|
||||
event(uuid: "#{event.uuid}") {
|
||||
uuid,
|
||||
participantStats {
|
||||
approved,
|
||||
unapproved,
|
||||
going,
|
||||
notApproved,
|
||||
rejected
|
||||
}
|
||||
}
|
||||
@@ -618,8 +618,8 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "event"))
|
||||
|
||||
assert json_response(res, 200)["data"]["event"]["uuid"] == to_string(event.uuid)
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["approved"] == 2
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["unapproved"] == 1
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["going"] == 2
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["notApproved"] == 1
|
||||
assert json_response(res, 200)["data"]["event"]["participantStats"]["rejected"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,9 +25,9 @@ defmodule Mobilizon.UploadTest do
|
||||
{:ok, data} = Upload.store(file)
|
||||
|
||||
assert %{
|
||||
"url" => [%{"href" => url, "mediaType" => "image/jpeg"}],
|
||||
"size" => 13_227,
|
||||
"type" => "Image"
|
||||
url: url,
|
||||
content_type: "image/jpeg",
|
||||
size: 13_227
|
||||
} = data
|
||||
|
||||
assert String.starts_with?(url, MobilizonWeb.Endpoint.url() <> "/media/")
|
||||
@@ -46,9 +46,7 @@ defmodule Mobilizon.UploadTest do
|
||||
|
||||
{:ok, data} = Upload.store(file, base_url: base_url)
|
||||
|
||||
assert %{"url" => [%{"href" => url}]} = data
|
||||
|
||||
assert String.starts_with?(url, base_url <> "/media/")
|
||||
assert String.starts_with?(data.url, base_url <> "/media/")
|
||||
end
|
||||
|
||||
test "copies the file to the configured folder with deduping" do
|
||||
@@ -62,7 +60,7 @@ defmodule Mobilizon.UploadTest do
|
||||
|
||||
{:ok, data} = Upload.store(file, filters: [MobilizonWeb.Upload.Filter.Dedupe])
|
||||
|
||||
assert List.first(data["url"])["href"] ==
|
||||
assert data.url ==
|
||||
MobilizonWeb.Endpoint.url() <>
|
||||
"/media/590523d60d3831ec92d05cdd871078409d5780903910efec5cd35ab1b0f19d11.jpg"
|
||||
end
|
||||
@@ -77,7 +75,7 @@ defmodule Mobilizon.UploadTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file)
|
||||
assert data["name"] == "an [image.jpg"
|
||||
assert data.name == "an [image.jpg"
|
||||
end
|
||||
|
||||
test "fixes incorrect content type" do
|
||||
@@ -90,7 +88,7 @@ defmodule Mobilizon.UploadTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file, filters: [MobilizonWeb.Upload.Filter.Dedupe])
|
||||
assert hd(data["url"])["mediaType"] == "image/jpeg"
|
||||
assert data.content_type == "image/jpeg"
|
||||
end
|
||||
|
||||
test "adds missing extension" do
|
||||
@@ -103,7 +101,7 @@ defmodule Mobilizon.UploadTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file)
|
||||
assert data["name"] == "an [image.jpg"
|
||||
assert data.name == "an [image.jpg"
|
||||
end
|
||||
|
||||
test "fixes incorrect file extension" do
|
||||
@@ -116,7 +114,7 @@ defmodule Mobilizon.UploadTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file)
|
||||
assert data["name"] == "an [image.jpg"
|
||||
assert data.name == "an [image.jpg"
|
||||
end
|
||||
|
||||
test "don't modify filename of an unknown type" do
|
||||
@@ -129,7 +127,7 @@ defmodule Mobilizon.UploadTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file)
|
||||
assert data["name"] == "test.txt"
|
||||
assert data.name == "test.txt"
|
||||
end
|
||||
|
||||
test "copies the file to the configured folder with anonymizing filename" do
|
||||
@@ -143,7 +141,7 @@ defmodule Mobilizon.UploadTest do
|
||||
|
||||
{:ok, data} = Upload.store(file, filters: [MobilizonWeb.Upload.Filter.AnonymizeFilename])
|
||||
|
||||
refute data["name"] == "an [image.jpg"
|
||||
refute data.name == "an [image.jpg"
|
||||
end
|
||||
|
||||
test "escapes invalid characters in url" do
|
||||
@@ -156,9 +154,8 @@ defmodule Mobilizon.UploadTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file)
|
||||
[attachment_url | _] = data["url"]
|
||||
|
||||
assert Path.basename(attachment_url["href"]) == "an%E2%80%A6%20image.jpg"
|
||||
assert Path.basename(data.url) == "an%E2%80%A6%20image.jpg"
|
||||
end
|
||||
|
||||
test "escapes reserved uri characters" do
|
||||
@@ -171,9 +168,8 @@ defmodule Mobilizon.UploadTest do
|
||||
}
|
||||
|
||||
{:ok, data} = Upload.store(file)
|
||||
[attachment_url | _] = data["url"]
|
||||
|
||||
assert Path.basename(attachment_url["href"]) ==
|
||||
assert Path.basename(data.url) ==
|
||||
"%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg"
|
||||
end
|
||||
|
||||
@@ -210,9 +206,9 @@ defmodule Mobilizon.UploadTest do
|
||||
{:ok, data} = Upload.store(file)
|
||||
|
||||
assert %{
|
||||
"url" => [%{"href" => url, "mediaType" => "image/jpeg"}],
|
||||
"size" => 13_227,
|
||||
"type" => "Image"
|
||||
url: url,
|
||||
size: 13_227,
|
||||
content_type: "image/jpeg"
|
||||
} = data
|
||||
|
||||
assert String.starts_with?(url, MobilizonWeb.Endpoint.url() <> "/media/")
|
||||
|
||||
@@ -40,7 +40,7 @@ defmodule Mobilizon.Factory do
|
||||
following_url: Actor.build_url(preferred_username, :following),
|
||||
inbox_url: Actor.build_url(preferred_username, :inbox),
|
||||
outbox_url: Actor.build_url(preferred_username, :outbox),
|
||||
user: nil
|
||||
user: build(:user)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -100,6 +100,8 @@ defmodule Mobilizon.Factory do
|
||||
actor: build(:actor),
|
||||
event: build(:event),
|
||||
uuid: uuid,
|
||||
mentions: [],
|
||||
tags: build_list(3, :tag),
|
||||
in_reply_to_comment: nil,
|
||||
url: Routes.page_url(Endpoint, :comment, uuid)
|
||||
}
|
||||
@@ -121,11 +123,13 @@ defmodule Mobilizon.Factory do
|
||||
physical_address: build(:address),
|
||||
visibility: :public,
|
||||
tags: build_list(3, :tag),
|
||||
mentions: [],
|
||||
url: Routes.page_url(Endpoint, :event, uuid),
|
||||
picture: insert(:picture),
|
||||
uuid: uuid,
|
||||
join_options: :free,
|
||||
options: %{}
|
||||
options: %{},
|
||||
participant_stats: %{}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -195,9 +199,10 @@ defmodule Mobilizon.Factory do
|
||||
{:ok, data} = Upload.store(file)
|
||||
|
||||
%{
|
||||
"url" => [%{"href" => url, "mediaType" => "image/jpeg"}],
|
||||
"size" => 13_227,
|
||||
"type" => "Image"
|
||||
content_type: "image/jpeg",
|
||||
name: "image.jpg",
|
||||
url: url,
|
||||
size: 13_227
|
||||
} = data
|
||||
|
||||
%Mobilizon.Media.File{
|
||||
|
||||
Reference in New Issue
Block a user