X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_test.exs;h=475531a097e58dfcde78ae32eb6474e7a9284f76;hb=01fe5abad1a98b98a0dd5e3c04bf65809389fd78;hp=519141c964bb2cd149c6c7f9f029c290d86c11de;hpb=47b07cec495528ce22f83ca56717cc74aa0096f3;p=akkoma
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 519141c96..475531a09 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -41,18 +41,19 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
input = %{
"status" =>
- "Hello again, @shp.\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
+ "Hello again, @shp.\nThis is on another :firefox: line. #2hu #epic #phantasmagoric",
"media_ids" => [object.id]
}
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+ object = Object.normalize(activity.data["object"])
expected_text =
- "Hello again, @shp.<script></script>
This is on another :moominmamma: line. #2hu #epic #phantasmagoric
image.jpg"
+ "Hello again, @shp.<script></script>
This is on another :firefox: line. #2hu #epic #phantasmagoric
image.jpg"
- assert get_in(activity.data, ["object", "content"]) == expected_text
- assert get_in(activity.data, ["object", "type"]) == "Note"
- assert get_in(activity.data, ["object", "actor"]) == user.ap_id
+ assert get_in(object.data, ["content"]) == expected_text
+ assert get_in(object.data, ["type"]) == "Note"
+ assert get_in(object.data, ["actor"]) == user.ap_id
assert get_in(activity.data, ["actor"]) == user.ap_id
assert Enum.member?(get_in(activity.data, ["cc"]), User.ap_followers(user))
@@ -64,21 +65,20 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
assert activity.local == true
- assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
- activity.data["object"]["emoji"]
+ assert %{"firefox" => "http://localhost:4001/emoji/Firefox.gif"} = object.data["emoji"]
# hashtags
- assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
+ assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
# Add a context
assert is_binary(get_in(activity.data, ["context"]))
- assert is_binary(get_in(activity.data, ["object", "context"]))
+ assert is_binary(get_in(object.data, ["context"]))
- assert is_list(activity.data["object"]["attachment"])
+ assert is_list(object.data["attachment"])
- assert activity.data["object"] == Object.get_by_ap_id(activity.data["object"]["id"]).data
+ assert activity.data["object"] == object.data["id"]
- user = User.get_by_ap_id(user.ap_id)
+ user = User.get_cached_by_ap_id(user.ap_id)
assert user.info.note_count == 1
end
@@ -91,6 +91,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+ object = Object.normalize(activity.data["object"])
input = %{
"status" => "Here's your (you).",
@@ -98,14 +99,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
+ reply_object = Object.normalize(reply.data["object"])
assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
- assert get_in(reply.data, ["object", "context"]) ==
- get_in(activity.data, ["object", "context"])
+ assert get_in(reply_object.data, ["context"]) == get_in(object.data, ["context"])
- assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
- assert get_in(reply.data, ["object", "inReplyToStatusId"]) == activity.id
+ assert get_in(reply_object.data, ["inReplyTo"]) == get_in(activity.data, ["object"])
+ assert Activity.get_in_reply_to_activity(reply).id == activity.id
end
test "Follow another user using user_id" do
@@ -115,8 +116,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user, followed, _activity} = TwitterAPI.follow(user, %{"user_id" => followed.id})
assert User.ap_followers(followed) in user.following
- {:error, msg} = TwitterAPI.follow(user, %{"user_id" => followed.id})
- assert msg == "Could not follow user: #{followed.nickname} is already on your list."
+ {:ok, _, _, _} = TwitterAPI.follow(user, %{"user_id" => followed.id})
end
test "Follow another user using screen_name" do
@@ -128,11 +128,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert User.ap_followers(followed) in user.following
- followed = User.get_by_ap_id(followed.ap_id)
+ followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
- {:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
- assert msg == "Could not follow user: #{followed.nickname} is already on your list."
+ {:ok, _, _, _} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
end
test "Unfollow another user using user_id" do
@@ -280,7 +279,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -298,7 +297,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -325,7 +324,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert user.info.confirmation_pending
- Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+ email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
+
+ notify_email = Pleroma.Config.get([:instance, :notify_email])
+ instance_name = Pleroma.Config.get([:instance, :name])
+
+ Swoosh.TestAssertions.assert_email_sent(
+ from: {instance_name, notify_email},
+ to: {user.name, user.email},
+ html_body: email.html_body
+ )
end
test "it registers a new user and parses mentions in the bio" do
@@ -384,7 +392,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -407,7 +415,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Invalid token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on expired token" do
@@ -427,7 +435,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -452,7 +460,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
check_fn = fn invite ->
data = Map.put(data, "token", invite.token)
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -462,7 +470,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "returns user on success", %{check_fn: check_fn} do
- {:ok, invite} = UserInviteToken.create_invite(%{expire_at: Date.utc_today()})
+ {:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today()})
check_fn.(invite)
@@ -472,7 +480,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "returns user on token which expired tomorrow", %{check_fn: check_fn} do
- {:ok, invite} = UserInviteToken.create_invite(%{expire_at: Date.add(Date.utc_today(), 1)})
+ {:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), 1)})
check_fn.(invite)
@@ -482,17 +490,17 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "returns an error on overdue date", %{data: data} do
- {:ok, invite} = UserInviteToken.create_invite(%{expire_at: Date.add(Date.utc_today(), -1)})
+ {:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1)})
data = Map.put(data, "token", invite.token)
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("vinny")
+ refute User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
- assert invite.used == true
+ refute invite.used
end
end
@@ -524,7 +532,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -545,7 +553,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -562,7 +570,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "returns user on success" do
- {:ok, invite} = UserInviteToken.create_invite(%{expire_at: Date.utc_today(), max_use: 100})
+ {:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
data = %{
"nickname" => "vinny",
@@ -575,7 +583,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
refute invite.used
@@ -585,7 +593,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
end
test "error after max uses" do
- {:ok, invite} = UserInviteToken.create_invite(%{expire_at: Date.utc_today(), max_use: 100})
+ {:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
UserInviteToken.update_invite!(invite, uses: 99)
@@ -600,7 +608,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -620,12 +628,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on overdue date" do
{:ok, invite} =
- UserInviteToken.create_invite(%{expire_at: Date.add(Date.utc_today(), -1), max_use: 100})
+ UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1), max_use: 100})
data = %{
"nickname" => "GrimReaper",
@@ -640,12 +648,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on with overdue date and after max" do
{:ok, invite} =
- UserInviteToken.create_invite(%{expire_at: Date.add(Date.utc_today(), -1), max_use: 100})
+ UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1), max_use: 100})
UserInviteToken.update_invite!(invite, uses: 100)
@@ -662,7 +670,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -678,7 +686,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, error_object} = TwitterAPI.register_user(data)
assert is_binary(error_object[:error])
- refute User.get_by_nickname("lain")
+ refute User.get_cached_by_nickname("lain")
end
test "it assigns an integer conversation_id" do
@@ -699,7 +707,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
id = "https://mastodon.social/users/lambadalambda"
user = insert(:user)
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
- remote = User.get_by_ap_id(id)
+ remote = User.get_cached_by_ap_id(id)
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]