X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Ftwitter_api_test.exs;h=aa2a4d6508e633dbf0107d5bcd1ebd08f85a6285;hb=dff5e1e46ab5e622ae0cc4b4422ae57ce0a0d5de;hp=4716abb84e38824bab8d0d97f3f0ad6b655010c1;hpb=4b3ec5351466f8615b32e62cc4e6215f8a80b105;p=akkoma
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 4716abb84..aa2a4d650 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -1,8 +1,16 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
- alias Pleroma.Builders.UserBuilder
- alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
- alias Pleroma.{Activity, User, Object, Repo}
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
+ alias Pleroma.Web.TwitterAPI.UserView
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView
@@ -10,7 +18,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
test "create a status" do
user = insert(:user)
- _mentioned_user = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
+ mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
object_data = %{
"type" => "Image",
@@ -35,7 +43,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
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 :moominmamma: line. #2hu #epic #phantasmagoric
image.jpg"
assert get_in(activity.data, ["object", "content"]) == expected_text
assert get_in(activity.data, ["object", "type"]) == "Note"
@@ -48,7 +56,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
"https://www.w3.org/ns/activitystreams#Public"
)
- assert Enum.member?(get_in(activity.data, ["cc"]), "shp")
+ assert Enum.member?(get_in(activity.data, ["to"]), "shp")
assert activity.local == true
assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
@@ -67,7 +75,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
user = User.get_by_ap_id(user.ap_id)
- assert user.info["note_count"] == 1
+ assert user.info.note_count == 1
end
test "create a status that is a reply" do
@@ -116,7 +124,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert User.ap_followers(followed) in user.following
followed = User.get_by_ap_id(followed.ap_id)
- assert followed.info["follower_count"] == 1
+ 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."
@@ -169,7 +177,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id})
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
- assert user.info["blocks"] == []
+ assert user.info.blocks == []
end
test "Unblock another user using screen_name" do
@@ -178,29 +186,46 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname})
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
- assert user.info["blocks"] == []
+ assert user.info.blocks == []
end
test "upload a file" do
+ user = insert(:user)
+
file = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
- response = TwitterAPI.upload(file)
+ response = TwitterAPI.upload(file, user)
assert is_binary(response)
end
test "it favorites a status, returns the updated activity" do
user = insert(:user)
+ other_user = insert(:user)
note_activity = insert(:note_activity)
{:ok, status} = TwitterAPI.fav(user, note_activity.id)
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+ assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 1
+
+ object = Object.normalize(note_activity.data["object"])
+
+ assert object.data["like_count"] == 1
assert status == updated_activity
+
+ {:ok, _status} = TwitterAPI.fav(other_user, note_activity.id)
+
+ object = Object.normalize(note_activity.data["object"])
+
+ assert object.data["like_count"] == 2
+
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+ assert ActivityView.render("activity.json", %{activity: updated_activity})["fave_num"] == 2
end
test "it unfavorites a status, returns the updated activity" do
@@ -228,12 +253,22 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert status == updated_activity
end
+ test "it unretweets an already retweeted status" do
+ user = insert(:user)
+ note_activity = insert(:note_activity)
+
+ {:ok, _status} = TwitterAPI.repeat(user, note_activity.id)
+ {:ok, status} = TwitterAPI.unrepeat(user, note_activity.id)
+ updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
+
+ assert status == updated_activity
+ end
+
test "it registers a new user and returns the user." do
data = %{
"nickname" => "lain",
"email" => "lain@wired.jp",
"fullname" => "lain iwakura",
- "bio" => "close the world.",
"password" => "bear",
"confirm" => "bear"
}
@@ -246,6 +281,142 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
UserView.render("show.json", %{user: fetched_user})
end
+ test "it registers a new user with empty string in bio and returns the user." do
+ data = %{
+ "nickname" => "lain",
+ "email" => "lain@wired.jp",
+ "fullname" => "lain iwakura",
+ "bio" => "",
+ "password" => "bear",
+ "confirm" => "bear"
+ }
+
+ {:ok, user} = TwitterAPI.register_user(data)
+
+ fetched_user = Repo.get_by(User, nickname: "lain")
+
+ assert UserView.render("show.json", %{user: user}) ==
+ UserView.render("show.json", %{user: fetched_user})
+ end
+
+ @moduletag skip: "needs 'account_activation_required: true' in config"
+ test "it sends confirmation email if :account_activation_required is specified in instance config" do
+ setting = Pleroma.Config.get([:instance, :account_activation_required])
+
+ unless setting do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
+ end
+
+ data = %{
+ "nickname" => "lain",
+ "email" => "lain@wired.jp",
+ "fullname" => "lain iwakura",
+ "bio" => "",
+ "password" => "bear",
+ "confirm" => "bear"
+ }
+
+ {:ok, user} = TwitterAPI.register_user(data)
+
+ assert user.info.confirmation_pending
+
+ Swoosh.TestAssertions.assert_email_sent(Pleroma.UserEmail.account_confirmation_email(user))
+ end
+
+ test "it registers a new user and parses mentions in the bio" do
+ data1 = %{
+ "nickname" => "john",
+ "email" => "john@gmail.com",
+ "fullname" => "John Doe",
+ "bio" => "test",
+ "password" => "bear",
+ "confirm" => "bear"
+ }
+
+ {:ok, user1} = TwitterAPI.register_user(data1)
+
+ data2 = %{
+ "nickname" => "lain",
+ "email" => "lain@wired.jp",
+ "fullname" => "lain iwakura",
+ "bio" => "@john test",
+ "password" => "bear",
+ "confirm" => "bear"
+ }
+
+ {:ok, user2} = TwitterAPI.register_user(data2)
+
+ expected_text =
+ "@john test"
+
+ assert user2.bio == expected_text
+ end
+
+ @moduletag skip: "needs 'registrations_open: false' in config"
+ test "it registers a new user via invite token and returns the user." do
+ {:ok, token} = UserInviteToken.create_token()
+
+ data = %{
+ "nickname" => "vinny",
+ "email" => "pasta@pizza.vs",
+ "fullname" => "Vinny Vinesauce",
+ "bio" => "streamer",
+ "password" => "hiptofbees",
+ "confirm" => "hiptofbees",
+ "token" => token.token
+ }
+
+ {:ok, user} = TwitterAPI.register_user(data)
+
+ fetched_user = Repo.get_by(User, nickname: "vinny")
+ token = Repo.get_by(UserInviteToken, token: token.token)
+
+ assert token.used == true
+
+ assert UserView.render("show.json", %{user: user}) ==
+ UserView.render("show.json", %{user: fetched_user})
+ end
+
+ @moduletag skip: "needs 'registrations_open: false' in config"
+ test "it returns an error if invalid token submitted" do
+ data = %{
+ "nickname" => "GrimReaper",
+ "email" => "death@reapers.afterlife",
+ "fullname" => "Reaper Grim",
+ "bio" => "Your time has come",
+ "password" => "scythe",
+ "confirm" => "scythe",
+ "token" => "DudeLetMeInImAFairy"
+ }
+
+ {:error, msg} = TwitterAPI.register_user(data)
+
+ assert msg == "Invalid token"
+ refute Repo.get_by(User, nickname: "GrimReaper")
+ end
+
+ @moduletag skip: "needs 'registrations_open: false' in config"
+ test "it returns an error if expired token submitted" do
+ {:ok, token} = UserInviteToken.create_token()
+ UserInviteToken.mark_as_used(token.token)
+
+ data = %{
+ "nickname" => "GrimReaper",
+ "email" => "death@reapers.afterlife",
+ "fullname" => "Reaper Grim",
+ "bio" => "Your time has come",
+ "password" => "scythe",
+ "confirm" => "scythe",
+ "token" => token.token
+ }
+
+ {:error, msg} = TwitterAPI.register_user(data)
+
+ assert msg == "Expired token"
+ refute Repo.get_by(User, nickname: "GrimReaper")
+ end
+
test "it returns the error on registration problems" do
data = %{
"nickname" => "lain",
@@ -300,7 +471,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
# Also fetches the feed.
- # assert Activity.get_create_activity_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
+ # assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
end
end
end