Merge remote-tracking branch 'origin/develop' into reactions
This commit is contained in:
commit
a7f31bf06c
102 changed files with 4649 additions and 6173 deletions
|
|
@ -173,4 +173,16 @@ defmodule Pleroma.ActivityTest do
|
|||
|> where([a], a.activity_id == ^activity.id)
|
||||
|> Repo.one!()
|
||||
end
|
||||
|
||||
test "all_by_ids_with_object/1" do
|
||||
%{id: id1} = insert(:note_activity)
|
||||
%{id: id2} = insert(:note_activity)
|
||||
|
||||
activities =
|
||||
[id1, id2]
|
||||
|> Activity.all_by_ids_with_object()
|
||||
|> Enum.sort(&(&1.id < &2.id))
|
||||
|
||||
assert [%{id: ^id1, object: %Object{}}, %{id: ^id2, object: %Object{}}] = activities
|
||||
end
|
||||
end
|
||||
|
|
|
|||
56
test/fixtures/osada-follow-activity.json
vendored
Normal file
56
test/fixtures/osada-follow-activity.json
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"@context":[
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
"https://apfed.club/apschema/v1.4"
|
||||
],
|
||||
"id":"https://apfed.club/follow/9",
|
||||
"type":"Follow",
|
||||
"actor":{
|
||||
"type":"Person",
|
||||
"id":"https://apfed.club/channel/indio",
|
||||
"preferredUsername":"indio",
|
||||
"name":"Indio",
|
||||
"updated":"2019-08-20T23:52:34Z",
|
||||
"icon":{
|
||||
"type":"Image",
|
||||
"mediaType":"image/jpeg",
|
||||
"updated":"2019-08-20T23:53:37Z",
|
||||
"url":"https://apfed.club/photo/profile/l/2",
|
||||
"height":300,
|
||||
"width":300
|
||||
},
|
||||
"url":"https://apfed.club/channel/indio",
|
||||
"inbox":"https://apfed.club/inbox/indio",
|
||||
"outbox":"https://apfed.club/outbox/indio",
|
||||
"followers":"https://apfed.club/followers/indio",
|
||||
"following":"https://apfed.club/following/indio",
|
||||
"endpoints":{
|
||||
"sharedInbox":"https://apfed.club/inbox"
|
||||
},
|
||||
"publicKey":{
|
||||
"id":"https://apfed.club/channel/indio",
|
||||
"owner":"https://apfed.club/channel/indio",
|
||||
"publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA77TIR1VuSYFnmDRFGHHb\n4vaGdx9ranzRX4bfOKAqa++Ch5L4EqJpPy08RuM+NrYCYiYl4QQFDSSDXAEgb5g9\nC1TgWTfI7q/E0UBX2Vr0mU6X4i1ztv0tuQvegRjcSJ7l1AvoBs8Ip4MEJ3OPEQhB\ngJqAACB3Gnps4zi2I0yavkxUfGVKr6zKT3BxWh5hTpKC7Do+ChIrVZC2EwxND9K6
|
||||
\nsAnQHThcb5EQuvuzUQZKeS7IEOsd0JpZDmJjbfMGrAWE81pLIfEeeA2joCJiBBTO\nglDsW+juvZ+lWqJpMr2hMWpvfrFjJeUawNJCIzsLdVIZR+aKj5yy6yqoS8hkN9Ha\n1MljZpsXl+EmwcwAIqim1YeLwERCEAQ/JWbSt8pQTQbzZ6ibwQ4mchCxacrRbIVR
|
||||
\nnL59fWMBassJcbY0VwrTugm2SBsYbDjESd55UZV03Rwr8qseGTyi+hH8O7w2SIaY\nzjN6AdZiPmsh00YflzlCk8MSLOHMol1vqIUzXxU8CdXn9+KsuQdZGrTz0YKN/db4\naVwUGJatz2Tsvf7R1tJBjJfeQWOWbbn3pycLVH86LjZ83qngp9ZVnAveUnUqz0yS
|
||||
\nhe+buZ6UMsfGzbIYon2bKNlz6gYTH0YPcr+cLe+29drtt0GZiXha1agbpo4RB8zE
|
||||
\naNL2fucF5YT0yNpbd/5WoV0CAwEAAQ==\n-----END PUBLIC KEY-----\n"
|
||||
}
|
||||
},
|
||||
"object":"https://pleroma.site/users/kaniini",
|
||||
"to":[
|
||||
"https://pleroma.site/users/kaniini"
|
||||
],
|
||||
"signature":{
|
||||
"@context":[
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1"
|
||||
],
|
||||
"type":"RsaSignature2017",
|
||||
"nonce":"52c035e0a9e81dce8b486159204e97c22637e91f75cdfad5378de91de68e9117",
|
||||
"creator":"https://apfed.club/channel/indio/public_key_pem",
|
||||
"created":"2019-08-22T03:38:02Z",
|
||||
"signatureValue":"oVliRCIqNIh6yUp851dYrF0y21aHp3Rz6VkIpW1pFMWfXuzExyWSfcELpyLseeRmsw5bUu9zJkH44B4G2LiJQKA9UoEQDjrDMZBmbeUpiQqq3DVUzkrBOI8bHZ7xyJ/CjSZcNHHh0MHhSKxswyxWMGi4zIqzkAZG3vRRgoPVHdjPm00sR3B8jBLw1cjoffv+KKeM/zEUpe13gqX9qHAWHHqZepxgSWmq+EKOkRvHUPBXiEJZfXzc5uW+vZ09F3WBYmaRoy8Y0e1P29fnRLqSy7EEINdrHaGclRqoUZyiawpkgy3lWWlynesV/HiLBR7EXT79eKstxf4wfTDaPKBCfTCsOWuMWHr7Genu37ew2/t7eiBGqCwwW12ylhml/OLHgNK3LOhmRABhtfpaFZSxfDVnlXfaLpY1xekVOj2oC0FpBtnoxVKLpIcyLw6dkfSil5ANd+hl59W/bpPA8KT90ii1fSNCo3+FcwQVx0YsPznJNA60XfFuVsme7zNcOst6393e1WriZxBanFpfB63zVQc9u1fjyfktx/yiUNxIlre+sz9OCc0AACn94iRhBYh4bbzdleUOTnM7lnD4Dj2FP+xeDIP8CA8wXUeq5+9kopSp2kAmlUEyFUdg4no7naIeu1SZnopfUg56PsVCp9JHiUK1SYAyWbdC+FbUECu5CvI="
|
||||
}
|
||||
}
|
||||
1
test/fixtures/tesla_mock/misskey_poll_no_end_date.json
vendored
Normal file
1
test/fixtures/tesla_mock/misskey_poll_no_end_date.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"Hashtag":"as:Hashtag"}],"id":"https://skippers-bin.com/notes/7x9tmrp97i","type":"Question","attributedTo":"https://skippers-bin.com/users/7v1w1r8ce6","summary":null,"content":"<p><a href=\"https://marchgenso.me/users/march\" class=\"mention\">@march@marchgenso.me</a><span> How are your notifications now?<br></span><a href=\"https://skippers-bin.com/notes/7x9tmrp97i\"><span>リモートで結果を表示</span></a></p>","_misskey_content":"@march@marchgenso.me How are your notifications now?\n[リモートで結果を表示](https://skippers-bin.com/notes/7x9tmrp97i)","published":"2019-09-05T05:35:32.541Z","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://skippers-bin.com/users/7v1w1r8ce6/followers","https://marchgenso.me/users/march"],"inReplyTo":null,"attachment":[],"sensitive":false,"tag":[{"type":"Mention","href":"https://marchgenso.me/users/march","name":"@march@marchgenso.me"}],"_misskey_fallback_content":"<p><a href=\"https://marchgenso.me/users/march\" class=\"mention\">@march@marchgenso.me</a><span> How are your notifications now?<br></span><a href=\"https://skippers-bin.com/notes/7x9tmrp97i\"><span>リモートで結果を表示</span></a><span><br>----------------------------------------<br>0: Working<br>1: Broken af<br>----------------------------------------<br>番号を返信して投票</span></p>","endTime":null,"oneOf":[{"type":"Note","name":"Working","replies":{"type":"Collection","totalItems":0}},{"type":"Note","name":"Broken af","replies":{"type":"Collection","totalItems":1}}]}
|
||||
1
test/fixtures/tesla_mock/osada-user-indio.json
vendored
Normal file
1
test/fixtures/tesla_mock/osada-user-indio.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],"type":"Person","id":"https://apfed.club/channel/indio","preferredUsername":"indio","name":"Indio","updated":"2019-08-20T23:52:34Z","icon":{"type":"Image","mediaType":"image/jpeg","updated":"2019-08-20T23:53:37Z","url":"https://apfed.club/photo/profile/l/2","height":300,"width":300},"url":"https://apfed.club/channel/indio","inbox":"https://apfed.club/inbox/indio","outbox":"https://apfed.club/outbox/indio","followers":"https://apfed.club/followers/indio","following":"https://apfed.club/following/indio","endpoints":{"sharedInbox":"https://apfed.club/inbox"},"publicKey":{"id":"https://apfed.club/channel/indio","owner":"https://apfed.club/channel/indio","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA77TIR1VuSYFnmDRFGHHb\n4vaGdx9ranzRX4bfOKAqa++Ch5L4EqJpPy08RuM+NrYCYiYl4QQFDSSDXAEgb5g9\nC1TgWTfI7q/E0UBX2Vr0mU6X4i1ztv0tuQvegRjcSJ7l1AvoBs8Ip4MEJ3OPEQhB\ngJqAACB3Gnps4zi2I0yavkxUfGVKr6zKT3BxWh5hTpKC7Do+ChIrVZC2EwxND9K6\nsAnQHThcb5EQuvuzUQZKeS7IEOsd0JpZDmJjbfMGrAWE81pLIfEeeA2joCJiBBTO\nglDsW+juvZ+lWqJpMr2hMWpvfrFjJeUawNJCIzsLdVIZR+aKj5yy6yqoS8hkN9Ha\n1MljZpsXl+EmwcwAIqim1YeLwERCEAQ/JWbSt8pQTQbzZ6ibwQ4mchCxacrRbIVR\nnL59fWMBassJcbY0VwrTugm2SBsYbDjESd55UZV03Rwr8qseGTyi+hH8O7w2SIaY\nzjN6AdZiPmsh00YflzlCk8MSLOHMol1vqIUzXxU8CdXn9+KsuQdZGrTz0YKN/db4\naVwUGJatz2Tsvf7R1tJBjJfeQWOWbbn3pycLVH86LjZ83qngp9ZVnAveUnUqz0yS\nhe+buZ6UMsfGzbIYon2bKNlz6gYTH0YPcr+cLe+29drtt0GZiXha1agbpo4RB8zE\naNL2fucF5YT0yNpbd/5WoV0CAwEAAQ==\n-----END PUBLIC KEY-----\n"},"signature":{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],"type":"RsaSignature2017","nonce":"c672a408d2e88b322b36a61bf0c25f586be9245d30293c55b8d653dcc867aaf7","creator":"https://apfed.club/channel/indio/public_key_pem","created":"2019-08-26T07:24:03Z","signatureValue":"MyAv5gnedu6L/DYFaE1TUYvp4LjI9ZUU0axwGYOhgD7qsjivMgwbOrjX/iH32xlcfF8nWOMh/ogu3+Qwr5sqLHkS2AimWmw1+Ubf2KccE58b8vI8zWfyu8QJnMuE92jtBPv8UTQUHw8ZebbExk3L99oXaeyVihKiMBmd63NpVTpGXZTg6m+H+KfWchVajPoyNKZtKMd3nH99x5j54Cqkz0BN5CSTwCSG0wP95G0VtZHtmhX+tsAPM3oAj0d+gtCZSCd8Nu8fvFAwCyTg1oKSfRqKb27EKHlskqK9X57x0jURH77CTAIQSejgGcKJ5GGLtvofubJkafadjagqrtqz6Mz6BZ642ssJ2KGkRAn79Q4F08goI6cfU5lLk2Tooe5A55XERnmE3SkYGyTvLpacZplxJdU0sa+deX9D7+alSGFJZSziaxpCxzrO6lEApe4b9kHXAzn9VaZt9trijkHq/kkq0i3NRcP7n8JG9q+Vv8jY9ddY6HcH89RNCBIA6MKLtAqc+vSc5G24qeZlw2MzlQWBp0KGuVG8DQR00AL6cXLBzF1WY8JZeEg6zqm+DMznbuNzgiS34BP+AehBSHlQ4MZebwDnK3ZPPqGSwioIWMxIFfZDaVDX9Pp1pXAARQMw0c/y4sDcf9FMzsr8jteEa7ZQcoqq5kXQTSCP56TEHnI="}}
|
||||
1
test/fixtures/tesla_mock/sjw.json
vendored
Normal file
1
test/fixtures/tesla_mock/sjw.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"Hashtag":"as:Hashtag"}],"type":"Person","id":"https://skippers-bin.com/users/7v1w1r8ce6","inbox":"https://skippers-bin.com/users/7v1w1r8ce6/inbox","outbox":"https://skippers-bin.com/users/7v1w1r8ce6/outbox","followers":"https://skippers-bin.com/users/7v1w1r8ce6/followers","following":"https://skippers-bin.com/users/7v1w1r8ce6/following","featured":"https://skippers-bin.com/users/7v1w1r8ce6/collections/featured","sharedInbox":"https://skippers-bin.com/inbox","endpoints":{"sharedInbox":"https://skippers-bin.com/inbox"},"url":"https://skippers-bin.com/@sjw","preferredUsername":"sjw","name":"It's ya boi sjw :verified:","summary":"<p><span>Admin of skippers-bin.com and neckbeard.xyz<br>For the most part I'm just a normal user. I mostly post animu, lewds, may-mays, and shitposts.<br><br>Not an alt of </span><a href=\"https://skippers-bin.com/@sjw@neckbeard.xyz\" class=\"mention\">@sjw@neckbeard.xyz</a><span> but another main.<br><br>Email/XMPP: neckbeard@rape.lol<br>PGP: d016 b622 75ba bcbc 5b3a fced a7d9 4824 0eb3 9c4e</span></p>","icon":{"type":"Image","url":"https://skippers-bin.com/files/webpublic-21b17f5b-3a83-4f50-8d4f-eda92066aa26","sensitive":false},"image":{"type":"Image","url":"https://skippers-bin.com/files/webpublic-1cd7f961-421e-4c31-aa03-74fb82584308","sensitive":false},"tag":[{"id":"https://skippers-bin.com/emojis/verified","type":"Emoji","name":":verified:","updated":"2019-07-12T02:16:12.088Z","icon":{"type":"Image","mediaType":"image/png","url":"https://skippers-bin.com/files/webpublic-dd10b435-6dad-4602-938b-f69ec0a19f2c"}}],"manuallyApprovesFollowers":false,"publicKey":{"id":"https://skippers-bin.com/users/7v1w1r8ce6/publickey","type":"Key","owner":"https://skippers-bin.com/users/7v1w1r8ce6","publicKeyPem":"-----BEGIN RSA PUBLIC KEY-----\nMIICCgKCAgEAvmp71/A6Oxe1UW/44HK0juAJhrjv9gYhaoslaS9K1FB+BHfIjaE9\n9+W2SKRLnVNYNFSN4JJrSGhX5RUjAsf4tcdRDVcmHl7tp2sgOAZeZz5geULm2sJQ\nwElnGk34jT/xCfX+w/O+7DuX31sU7ZK0B2P7ulNGDQXhrzVO0RMx7HhNcsFcusno\n3kmPyyPT1l+PbM2UNWms599/3yicKtuOzMgzxNeXvuHYtAO19txyPiOeYckQOMmT\nwEVIxypgCgNQ0MNtPLPKQTwOgVbvnN7MN+h3esKeKDcPcGQySkbkjZPaVnA6xCQf\nj58c19wqdCfAS4Effo5/bxVmhLpe0l9HYpV7IMasv2LhFntmSmAxBQzhdz0oTYb1\naNqiyfZdClnzutOiKcrFppADo4rZH9Z1WlPHapahrKbF0GRPN8DjSUsoBxfY9wZs\ntlL056hT4o+EFHYrRGo7KP6X/6aQ9sSsmpE08aVpVuXdwuaoaDlW1KrJ0oOk4lZw\nUNXvjEaN3c+VQAw2CNvkAqLuwrjnw7MdcxEGodEXb6s8VvoSOaiDqT7cexSaZe0R\nliCe/3dqFXpX1UrgRiryI4yc1BrEJIGTanchmP2aUJ2R2pccFsREp23C3vMN3M5b\nHw7fvKbUQHyf6lhRoLCOSCz1xaPutaMJmpwLuJo4wPCHGg9QFBYsqxcCAwEAAQ==\n-----END RSA PUBLIC KEY-----\n"},"isCat":true}
|
||||
|
|
@ -12,7 +12,6 @@ defmodule Pleroma.NotificationTest do
|
|||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Streamer
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
|
||||
describe "create_notifications" do
|
||||
test "notifies someone when they are directly addressed" do
|
||||
|
|
@ -21,7 +20,7 @@ defmodule Pleroma.NotificationTest do
|
|||
third_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(user, %{
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname}"
|
||||
})
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
User.subscribe(subscriber, user)
|
||||
|
||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
||||
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
|
||||
{:ok, [notification]} = Notification.create_notifications(status)
|
||||
|
||||
assert notification.user_id == subscriber.id
|
||||
|
|
@ -184,47 +183,20 @@ defmodule Pleroma.NotificationTest do
|
|||
test "it doesn't create a notification for follow-unfollow-follow chains" do
|
||||
user = insert(:user)
|
||||
followed_user = insert(:user)
|
||||
{:ok, _, _, activity} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
|
||||
{:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
|
||||
Notification.create_notification(activity, followed_user)
|
||||
TwitterAPI.unfollow(user, %{"user_id" => followed_user.id})
|
||||
{:ok, _, _, activity_dupe} = TwitterAPI.follow(user, %{"user_id" => followed_user.id})
|
||||
CommonAPI.unfollow(user, followed_user)
|
||||
{:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
|
||||
refute Notification.create_notification(activity_dupe, followed_user)
|
||||
end
|
||||
|
||||
test "it doesn't create a notification for like-unlike-like chains" do
|
||||
user = insert(:user)
|
||||
liked_user = insert(:user)
|
||||
{:ok, status} = TwitterAPI.create_status(liked_user, %{"status" => "Yui is best yuru"})
|
||||
{:ok, fav_status} = TwitterAPI.fav(user, status.id)
|
||||
Notification.create_notification(fav_status, liked_user)
|
||||
TwitterAPI.unfav(user, status.id)
|
||||
{:ok, dupe} = TwitterAPI.fav(user, status.id)
|
||||
refute Notification.create_notification(dupe, liked_user)
|
||||
end
|
||||
|
||||
test "it doesn't create a notification for repeat-unrepeat-repeat chains" do
|
||||
user = insert(:user)
|
||||
retweeted_user = insert(:user)
|
||||
|
||||
{:ok, status} =
|
||||
TwitterAPI.create_status(retweeted_user, %{
|
||||
"status" => "Send dupe notifications to the shadow realm"
|
||||
})
|
||||
|
||||
{:ok, retweeted_activity} = TwitterAPI.repeat(user, status.id)
|
||||
Notification.create_notification(retweeted_activity, retweeted_user)
|
||||
TwitterAPI.unrepeat(user, status.id)
|
||||
{:ok, dupe} = TwitterAPI.repeat(user, status.id)
|
||||
refute Notification.create_notification(dupe, retweeted_user)
|
||||
end
|
||||
|
||||
test "it doesn't create duplicate notifications for follow+subscribed users" do
|
||||
user = insert(:user)
|
||||
subscriber = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = TwitterAPI.follow(subscriber, %{"user_id" => user.id})
|
||||
{:ok, _, _, _} = CommonAPI.follow(subscriber, user)
|
||||
User.subscribe(subscriber, user)
|
||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
||||
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
|
||||
{:ok, [_notif]} = Notification.create_notifications(status)
|
||||
end
|
||||
|
||||
|
|
@ -234,8 +206,7 @@ defmodule Pleroma.NotificationTest do
|
|||
|
||||
User.subscribe(subscriber, user)
|
||||
|
||||
{:ok, status} =
|
||||
TwitterAPI.create_status(user, %{"status" => "inwisible", "visibility" => "direct"})
|
||||
{:ok, status} = CommonAPI.post(user, %{"status" => "inwisible", "visibility" => "direct"})
|
||||
|
||||
assert {:ok, []} == Notification.create_notifications(status)
|
||||
end
|
||||
|
|
@ -246,8 +217,7 @@ defmodule Pleroma.NotificationTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:ok, notification} = Notification.get(other_user, notification.id)
|
||||
|
|
@ -259,8 +229,7 @@ defmodule Pleroma.NotificationTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:error, _notification} = Notification.get(user, notification.id)
|
||||
|
|
@ -272,8 +241,7 @@ defmodule Pleroma.NotificationTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:ok, notification} = Notification.dismiss(other_user, notification.id)
|
||||
|
|
@ -285,8 +253,7 @@ defmodule Pleroma.NotificationTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
{:error, _notification} = Notification.dismiss(user, notification.id)
|
||||
|
|
@ -300,14 +267,14 @@ defmodule Pleroma.NotificationTest do
|
|||
third_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(user, %{
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "hey @#{other_user.nickname} and @#{third_user.nickname} !"
|
||||
})
|
||||
|
||||
{:ok, _notifs} = Notification.create_notifications(activity)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(user, %{
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "hey again @#{other_user.nickname} and @#{third_user.nickname} !"
|
||||
})
|
||||
|
||||
|
|
@ -325,12 +292,12 @@ defmodule Pleroma.NotificationTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
TwitterAPI.create_status(user, %{
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "hey @#{other_user.nickname}!"
|
||||
})
|
||||
|
||||
{:ok, _activity} =
|
||||
TwitterAPI.create_status(user, %{
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "hey again @#{other_user.nickname}!"
|
||||
})
|
||||
|
||||
|
|
@ -340,7 +307,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert n2.id > n1.id
|
||||
|
||||
{:ok, _activity} =
|
||||
TwitterAPI.create_status(user, %{
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "hey yet again @#{other_user.nickname}!"
|
||||
})
|
||||
|
||||
|
|
@ -677,7 +644,7 @@ defmodule Pleroma.NotificationTest do
|
|||
muted = insert(:user)
|
||||
{:ok, user} = User.mute(user, muted, false)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert length(Notification.for_user(user)) == 1
|
||||
end
|
||||
|
|
@ -687,7 +654,7 @@ defmodule Pleroma.NotificationTest do
|
|||
muted = insert(:user)
|
||||
{:ok, user} = User.mute(user, muted)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
|
@ -697,7 +664,7 @@ defmodule Pleroma.NotificationTest do
|
|||
blocked = insert(:user)
|
||||
{:ok, user} = User.block(user, blocked)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
|
@ -707,7 +674,7 @@ defmodule Pleroma.NotificationTest do
|
|||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
|
@ -716,8 +683,7 @@ defmodule Pleroma.NotificationTest do
|
|||
user = insert(:user)
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
|
||||
assert Notification.for_user(user) == []
|
||||
|
|
@ -728,7 +694,7 @@ defmodule Pleroma.NotificationTest do
|
|||
muted = insert(:user)
|
||||
{:ok, user} = User.mute(user, muted)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(muted, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, _activity} = CommonAPI.post(muted, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||
end
|
||||
|
|
@ -738,7 +704,7 @@ defmodule Pleroma.NotificationTest do
|
|||
blocked = insert(:user)
|
||||
{:ok, user} = User.block(user, blocked)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||
end
|
||||
|
|
@ -748,7 +714,7 @@ defmodule Pleroma.NotificationTest do
|
|||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||
end
|
||||
|
|
@ -757,8 +723,7 @@ defmodule Pleroma.NotificationTest do
|
|||
user = insert(:user)
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(another_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(another_user, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
|
||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||
|
|
|
|||
|
|
@ -53,9 +53,12 @@ defmodule Pleroma.ObjectTest do
|
|||
|
||||
assert object == cached_object
|
||||
|
||||
Cachex.put(:web_resp_cache, URI.parse(object.data["id"]).path, "cofe")
|
||||
|
||||
Object.delete(cached_object)
|
||||
|
||||
{:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
|
||||
{:ok, nil} = Cachex.get(:web_resp_cache, URI.parse(object.data["id"]).path)
|
||||
|
||||
cached_object = Object.get_cached_by_ap_id(object.data["id"])
|
||||
|
||||
|
|
|
|||
78
test/pagination_test.exs
Normal file
78
test/pagination_test.exs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.PaginationTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Pagination
|
||||
|
||||
describe "keyset" do
|
||||
setup do
|
||||
notes = insert_list(5, :note)
|
||||
|
||||
%{notes: notes}
|
||||
end
|
||||
|
||||
test "paginates by min_id", %{notes: notes} do
|
||||
id = Enum.at(notes, 2).id |> Integer.to_string()
|
||||
|
||||
%{total: total, items: paginated} =
|
||||
Pagination.fetch_paginated(Object, %{"min_id" => id, "total" => true})
|
||||
|
||||
assert length(paginated) == 2
|
||||
assert total == 5
|
||||
end
|
||||
|
||||
test "paginates by since_id", %{notes: notes} do
|
||||
id = Enum.at(notes, 2).id |> Integer.to_string()
|
||||
|
||||
%{total: total, items: paginated} =
|
||||
Pagination.fetch_paginated(Object, %{"since_id" => id, "total" => true})
|
||||
|
||||
assert length(paginated) == 2
|
||||
assert total == 5
|
||||
end
|
||||
|
||||
test "paginates by max_id", %{notes: notes} do
|
||||
id = Enum.at(notes, 1).id |> Integer.to_string()
|
||||
|
||||
%{total: total, items: paginated} =
|
||||
Pagination.fetch_paginated(Object, %{"max_id" => id, "total" => true})
|
||||
|
||||
assert length(paginated) == 1
|
||||
assert total == 5
|
||||
end
|
||||
|
||||
test "paginates by min_id & limit", %{notes: notes} do
|
||||
id = Enum.at(notes, 2).id |> Integer.to_string()
|
||||
|
||||
paginated = Pagination.fetch_paginated(Object, %{"min_id" => id, "limit" => 1})
|
||||
|
||||
assert length(paginated) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "offset" do
|
||||
setup do
|
||||
notes = insert_list(5, :note)
|
||||
|
||||
%{notes: notes}
|
||||
end
|
||||
|
||||
test "paginates by limit" do
|
||||
paginated = Pagination.fetch_paginated(Object, %{"limit" => 2}, :offset)
|
||||
|
||||
assert length(paginated) == 2
|
||||
end
|
||||
|
||||
test "paginates by limit & offset" do
|
||||
paginated = Pagination.fetch_paginated(Object, %{"limit" => 2, "offset" => 4}, :offset)
|
||||
|
||||
assert length(paginated) == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
186
test/plugs/cache_test.exs
Normal file
186
test/plugs/cache_test.exs
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Plugs.CacheTest do
|
||||
use ExUnit.Case, async: true
|
||||
use Plug.Test
|
||||
|
||||
alias Pleroma.Plugs.Cache
|
||||
|
||||
@miss_resp {200,
|
||||
[
|
||||
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||
{"content-type", "cofe/hot; charset=utf-8"},
|
||||
{"x-cache", "MISS from Pleroma"}
|
||||
], "cofe"}
|
||||
|
||||
@hit_resp {200,
|
||||
[
|
||||
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||
{"content-type", "cofe/hot; charset=utf-8"},
|
||||
{"x-cache", "HIT from Pleroma"}
|
||||
], "cofe"}
|
||||
|
||||
@ttl 5
|
||||
|
||||
setup do
|
||||
Cachex.clear(:web_resp_cache)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "caches a response" do
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
|
||||
assert_raise(Plug.Conn.AlreadySentError, fn ->
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
end)
|
||||
|
||||
assert @hit_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> sent_resp()
|
||||
end
|
||||
|
||||
test "ttl is set" do
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: @ttl})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
|
||||
assert @hit_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: @ttl})
|
||||
|> sent_resp()
|
||||
|
||||
:timer.sleep(@ttl + 1)
|
||||
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: @ttl})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
end
|
||||
|
||||
test "set ttl via conn.assigns" do
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> assign(:cache_ttl, @ttl)
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
|
||||
assert @hit_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> sent_resp()
|
||||
|
||||
:timer.sleep(@ttl + 1)
|
||||
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
end
|
||||
|
||||
test "ignore query string when `query_params` is false" do
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/?cofe")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
|
||||
assert @hit_resp ==
|
||||
conn(:get, "/?cofefe")
|
||||
|> Cache.call(%{query_params: false, ttl: nil})
|
||||
|> sent_resp()
|
||||
end
|
||||
|
||||
test "take query string into account when `query_params` is true" do
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/?cofe")
|
||||
|> Cache.call(%{query_params: true, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/?cofefe")
|
||||
|> Cache.call(%{query_params: true, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
end
|
||||
|
||||
test "take specific query params into account when `query_params` is list" do
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/?a=1&b=2&c=3&foo=bar")
|
||||
|> fetch_query_params()
|
||||
|> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
|
||||
assert @hit_resp ==
|
||||
conn(:get, "/?bar=foo&c=3&b=2&a=1")
|
||||
|> fetch_query_params()
|
||||
|> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
|
||||
|> sent_resp()
|
||||
|
||||
assert @miss_resp ==
|
||||
conn(:get, "/?bar=foo&c=3&b=2&a=2")
|
||||
|> fetch_query_params()
|
||||
|> Cache.call(%{query_params: ["a", "b", "c"], ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
end
|
||||
|
||||
test "ignore not GET requests" do
|
||||
expected =
|
||||
{200,
|
||||
[
|
||||
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||
{"content-type", "cofe/hot; charset=utf-8"}
|
||||
], "cofe"}
|
||||
|
||||
assert expected ==
|
||||
conn(:post, "/")
|
||||
|> Cache.call(%{query_params: true, ttl: nil})
|
||||
|> put_resp_content_type("cofe/hot")
|
||||
|> send_resp(:ok, "cofe")
|
||||
|> sent_resp()
|
||||
end
|
||||
|
||||
test "ignore non-successful responses" do
|
||||
expected =
|
||||
{418,
|
||||
[
|
||||
{"cache-control", "max-age=0, private, must-revalidate"},
|
||||
{"content-type", "tea/iced; charset=utf-8"}
|
||||
], "🥤"}
|
||||
|
||||
assert expected ==
|
||||
conn(:get, "/cofe")
|
||||
|> Cache.call(%{query_params: true, ttl: nil})
|
||||
|> put_resp_content_type("tea/iced")
|
||||
|> send_resp(:im_a_teapot, "🥤")
|
||||
|> sent_resp()
|
||||
end
|
||||
end
|
||||
|
|
@ -775,6 +775,11 @@ defmodule HttpRequestMock do
|
|||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
|
||||
end
|
||||
|
||||
def get("https://apfed.club/channel/indio", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
|
||||
end
|
||||
|
||||
def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
|
||||
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
|
||||
end
|
||||
|
|
@ -987,6 +992,18 @@ defmodule HttpRequestMock do
|
|||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
|
||||
end
|
||||
|
||||
def get("https://skippers-bin.com/notes/7x9tmrp97i", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/misskey_poll_no_end_date.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://skippers-bin.com/users/7v1w1r8ce6", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ defmodule Pleroma.UserTest do
|
|||
locked = insert(:user, %{info: %{locked: true}})
|
||||
follower = insert(:user)
|
||||
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => unlocked.id})
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(follower, %{"user_id" => locked.id})
|
||||
CommonAPI.follow(follower, unlocked)
|
||||
CommonAPI.follow(follower, locked)
|
||||
|
||||
assert {:ok, []} = User.get_follow_requests(unlocked)
|
||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||
|
|
@ -83,9 +83,9 @@ defmodule Pleroma.UserTest do
|
|||
pending_follower = insert(:user)
|
||||
accepted_follower = insert(:user)
|
||||
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(pending_follower, %{"user_id" => locked.id})
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.follow(accepted_follower, %{"user_id" => locked.id})
|
||||
CommonAPI.follow(pending_follower, locked)
|
||||
CommonAPI.follow(pending_follower, locked)
|
||||
CommonAPI.follow(accepted_follower, locked)
|
||||
User.follow(accepted_follower, locked)
|
||||
|
||||
assert {:ok, [activity]} = User.get_follow_requests(locked)
|
||||
|
|
@ -1279,11 +1279,9 @@ defmodule Pleroma.UserTest do
|
|||
{:ok, _follower2} = User.follow(follower2, user)
|
||||
{:ok, _follower3} = User.follow(follower3, user)
|
||||
|
||||
{:ok, _} = User.block(user, follower)
|
||||
{:ok, user} = User.block(user, follower)
|
||||
|
||||
user_show = Pleroma.Web.TwitterAPI.UserView.render("show.json", %{user: user})
|
||||
|
||||
assert Map.get(user_show, "followers_count") == 2
|
||||
assert User.user_info(user).follower_count == 2
|
||||
end
|
||||
|
||||
describe "list_inactive_users_query/1" do
|
||||
|
|
@ -1327,7 +1325,7 @@ defmodule Pleroma.UserTest do
|
|||
to = Enum.random(users -- [user])
|
||||
|
||||
{:ok, _} =
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(user, %{
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "hey @#{to.nickname}"
|
||||
})
|
||||
end)
|
||||
|
|
@ -1359,12 +1357,12 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
Enum.each(recipients, fn to ->
|
||||
{:ok, _} =
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
|
||||
CommonAPI.post(sender, %{
|
||||
"status" => "hey @#{to.nickname}"
|
||||
})
|
||||
|
||||
{:ok, _} =
|
||||
Pleroma.Web.TwitterAPI.TwitterAPI.create_status(sender, %{
|
||||
CommonAPI.post(sender, %{
|
||||
"status" => "hey again @#{to.nickname}"
|
||||
})
|
||||
end)
|
||||
|
|
@ -1616,4 +1614,31 @@ defmodule Pleroma.UserTest do
|
|||
assert User.user_info(other_user).following_count == 152
|
||||
end
|
||||
end
|
||||
|
||||
describe "change_email/2" do
|
||||
setup do
|
||||
[user: insert(:user)]
|
||||
end
|
||||
|
||||
test "blank email returns error", %{user: user} do
|
||||
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
|
||||
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
|
||||
end
|
||||
|
||||
test "non unique email returns error", %{user: user} do
|
||||
%{email: email} = insert(:user)
|
||||
|
||||
assert {:error, %{errors: [email: {"has already been taken", _}]}} =
|
||||
User.change_email(user, email)
|
||||
end
|
||||
|
||||
test "invalid email returns error", %{user: user} do
|
||||
assert {:error, %{errors: [email: {"has invalid format", _}]}} =
|
||||
User.change_email(user, "cofe")
|
||||
end
|
||||
|
||||
test "changes email", %{user: user} do
|
||||
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -175,6 +175,49 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "it caches a response", %{conn: conn} do
|
||||
note = insert(:note)
|
||||
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||
|
||||
conn1 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}")
|
||||
|
||||
assert json_response(conn1, :ok)
|
||||
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}")
|
||||
|
||||
assert json_response(conn1, :ok) == json_response(conn2, :ok)
|
||||
assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
|
||||
end
|
||||
|
||||
test "cached purged after object deletion", %{conn: conn} do
|
||||
note = insert(:note)
|
||||
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||
|
||||
conn1 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}")
|
||||
|
||||
assert json_response(conn1, :ok)
|
||||
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||
|
||||
Object.delete(note)
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/objects/#{uuid}")
|
||||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/object/:uuid/likes" do
|
||||
|
|
@ -264,6 +307,51 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "it caches a response", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn1 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert json_response(conn1, :ok)
|
||||
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert json_response(conn1, :ok) == json_response(conn2, :ok)
|
||||
assert Enum.any?(conn2.resp_headers, &(&1 == {"x-cache", "HIT from Pleroma"}))
|
||||
end
|
||||
|
||||
test "cached purged after activity deletion", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "cofe"})
|
||||
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn1 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert json_response(conn1, :ok)
|
||||
assert Enum.any?(conn1.resp_headers, &(&1 == {"x-cache", "MISS from Pleroma"}))
|
||||
|
||||
Activity.delete_by_ap_id(activity.object.data["id"])
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/inbox" do
|
||||
|
|
@ -365,6 +453,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert json_response(conn, 403)
|
||||
end
|
||||
|
||||
test "it doesn't crash without an authenticated user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/inbox")
|
||||
|
||||
assert json_response(conn, 403)
|
||||
end
|
||||
|
||||
test "it returns a note activity in a collection", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
note_object = Object.normalize(note_activity)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
end
|
||||
|
||||
describe "handle_incoming" do
|
||||
test "it works for osada follow request" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/osada-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "https://apfed.club/channel/indio"
|
||||
assert data["type"] == "Follow"
|
||||
assert data["id"] == "https://apfed.club/follow/9"
|
||||
|
||||
activity = Repo.get(Activity, activity.id)
|
||||
assert activity.data["state"] == "accept"
|
||||
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it works for incoming follow requests" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert capture_log(fn ->
|
||||
{:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "[error] Couldn't fetch \"\"https://404.site/whatever\"\", error: nil"
|
||||
end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"
|
||||
end
|
||||
|
||||
test "it works for incoming notices" do
|
||||
|
|
|
|||
|
|
@ -1779,7 +1779,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
%{"tuple" => [":seconds_valid", 60]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":key1", nil]},
|
||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
|
||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
|
||||
%{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
|
||||
%{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
|
||||
%{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
|
||||
%{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -1796,7 +1800,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
%{"tuple" => [":seconds_valid", 60]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":key1", nil]},
|
||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
|
||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
|
||||
%{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
|
||||
%{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
|
||||
%{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
|
||||
%{"tuple" => [":regex4", "~r/https:\\/\\/example.com/s"]}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -103,6 +103,30 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
|
|||
assert Config.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
|
||||
end
|
||||
|
||||
test "link sigil" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/
|
||||
end
|
||||
|
||||
test "link sigil with u modifier" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/u")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/u)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/u
|
||||
end
|
||||
|
||||
test "link sigil with i modifier" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/i")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/i)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/i
|
||||
end
|
||||
|
||||
test "link sigil with s modifier" do
|
||||
binary = Config.transform("~r/https:\/\/example.com/s")
|
||||
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/s)
|
||||
assert Config.from_binary(binary) == ~r/https:\/\/example.com/s
|
||||
end
|
||||
|
||||
test "2 child tuple" do
|
||||
binary = Config.transform(%{"tuple" => ["v1", ":v2"]})
|
||||
assert binary == :erlang.term_to_binary({"v1", :v2})
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
alias Pleroma.Web.OAuth.Token
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.Push
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
import Tesla.Mock
|
||||
|
|
@ -745,6 +744,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert id == to_string(activity.id)
|
||||
end
|
||||
|
||||
test "get statuses by IDs", %{conn: conn} do
|
||||
%{id: id1} = insert(:note_activity)
|
||||
%{id: id2} = insert(:note_activity)
|
||||
|
||||
query_string = "ids[]=#{id1}&ids[]=#{id2}"
|
||||
conn = get(conn, "/api/v1/statuses/?#{query_string}")
|
||||
|
||||
assert [%{"id" => ^id1}, %{"id" => ^id2}] = json_response(conn, :ok)
|
||||
end
|
||||
|
||||
describe "deleting a status" do
|
||||
test "when you created it", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -1484,12 +1493,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
media =
|
||||
TwitterAPI.upload(file, user, "json")
|
||||
|> Jason.decode!()
|
||||
{:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
|
||||
{:ok, image_post} =
|
||||
CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
|
||||
{:ok, image_post} = CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media_id]})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -1675,32 +1681,85 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "account fetching", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
describe "account fetching" do
|
||||
test "works by id" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}")
|
||||
conn =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/#{user.id}")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == to_string(user.id)
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == to_string(user.id)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/-1")
|
||||
conn =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/-1")
|
||||
|
||||
assert %{"error" => "Can't find user"} = json_response(conn, 404)
|
||||
end
|
||||
assert %{"error" => "Can't find user"} = json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "account fetching also works nickname", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
test "works by nickname" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
conn =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == user.id
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == user.id
|
||||
end
|
||||
|
||||
test "works by nickname for remote users" do
|
||||
limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == user.id
|
||||
end
|
||||
|
||||
test "respects limit_to_local_content == :all for remote user nicknames" do
|
||||
limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :all)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
|
||||
assert json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
|
||||
limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
reading_user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|
||||
assert json_response(conn, 404)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, reading_user)
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == user.id
|
||||
end
|
||||
end
|
||||
|
||||
test "mascot upload", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|||
alias Pleroma.Notification
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.MastodonAPI
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -75,8 +75,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|||
|
||||
User.subscribe(subscriber, user)
|
||||
|
||||
{:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
|
||||
{:ok, status1} = TwitterAPI.create_status(user, %{"status" => "Magi"})
|
||||
{:ok, status} = CommonAPI.post(user, %{"status" => "Akariiiin"})
|
||||
|
||||
{:ok, status1} = CommonAPI.post(user, %{"status" => "Magi"})
|
||||
{:ok, [notification]} = Notification.create_notifications(status)
|
||||
{:ok, [notification1]} = Notification.create_notifications(status1)
|
||||
res = MastodonAPI.get_notifications(subscriber)
|
||||
|
|
|
|||
|
|
@ -150,7 +150,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
|
||||
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
|
||||
expires_at: nil,
|
||||
direct_conversation_id: nil
|
||||
direct_conversation_id: nil,
|
||||
thread_muted: false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,6 +174,24 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert status.muted == true
|
||||
end
|
||||
|
||||
test "tells if the message is thread muted" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.mute(user, other_user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.pleroma.thread_muted == false
|
||||
|
||||
{:ok, activity} = CommonAPI.add_mute(user, activity)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.pleroma.thread_muted == true
|
||||
end
|
||||
|
||||
test "tells if the status is bookmarked" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -532,6 +551,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert Enum.at(result[:options], 1)[:votes_count] == 1
|
||||
assert Enum.at(result[:options], 2)[:votes_count] == 1
|
||||
end
|
||||
|
||||
test "does not crash on polls with no end date" do
|
||||
object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i")
|
||||
result = StatusView.render("poll.json", %{object: object})
|
||||
|
||||
assert result[:expires_at] == nil
|
||||
assert result[:expired] == false
|
||||
end
|
||||
end
|
||||
|
||||
test "embeds a relationship in the account" do
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -130,4 +131,59 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
assert user in participation.recipients
|
||||
assert other_user in participation.recipients
|
||||
end
|
||||
|
||||
describe "POST /api/v1/pleroma/notifications/read" do
|
||||
test "it marks a single notification as read", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||
{:ok, [notification1]} = Notification.create_notifications(activity1)
|
||||
{:ok, [notification2]} = Notification.create_notifications(activity2)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert %{"pleroma" => %{"is_seen" => true}} = response
|
||||
assert Repo.get(Notification, notification1.id).seen
|
||||
refute Repo.get(Notification, notification2.id).seen
|
||||
end
|
||||
|
||||
test "it marks multiple notifications as read", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||
{:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||
{:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"})
|
||||
|
||||
[notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3})
|
||||
|
||||
[response1, response2] =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert %{"pleroma" => %{"is_seen" => true}} = response1
|
||||
assert %{"pleroma" => %{"is_seen" => true}} = response2
|
||||
assert Repo.get(Notification, notification1.id).seen
|
||||
assert Repo.get(Notification, notification2.id).seen
|
||||
refute Repo.get(Notification, notification3.id).seen
|
||||
end
|
||||
|
||||
test "it returns error when notification not found", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"})
|
||||
|> json_response(:bad_request)
|
||||
|
||||
assert response == %{"error" => "Cannot get notification"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
|
||||
|
||||
test "represent an image attachment" do
|
||||
object = %Object{
|
||||
id: 5,
|
||||
data: %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"mediaType" => "sometype",
|
||||
"href" => "someurl"
|
||||
}
|
||||
],
|
||||
"uuid" => 6
|
||||
}
|
||||
}
|
||||
|
||||
expected_object = %{
|
||||
id: 6,
|
||||
url: "someurl",
|
||||
mimetype: "sometype",
|
||||
oembed: false,
|
||||
description: nil
|
||||
}
|
||||
|
||||
assert expected_object == ObjectRepresenter.to_map(object)
|
||||
end
|
||||
|
||||
test "represents mastodon-style attachments" do
|
||||
object = %Object{
|
||||
id: nil,
|
||||
data: %{
|
||||
"mediaType" => "image/png",
|
||||
"name" => "blabla",
|
||||
"type" => "Document",
|
||||
"url" =>
|
||||
"http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
|
||||
}
|
||||
}
|
||||
|
||||
expected_object = %{
|
||||
url:
|
||||
"http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
|
||||
mimetype: "image/png",
|
||||
oembed: false,
|
||||
id: nil,
|
||||
description: "blabla"
|
||||
}
|
||||
|
||||
assert expected_object == ObjectRepresenter.to_map(object)
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -4,270 +4,17 @@
|
|||
|
||||
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "create a status" do
|
||||
user = insert(:user)
|
||||
mentioned_user = insert(:user, %{nickname: "shp", ap_id: "shp"})
|
||||
|
||||
object_data = %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "image/jpg",
|
||||
"href" => "http://example.org/image.jpg"
|
||||
}
|
||||
],
|
||||
"uuid" => 1
|
||||
}
|
||||
|
||||
object = Repo.insert!(%Object{data: object_data})
|
||||
|
||||
input = %{
|
||||
"status" =>
|
||||
"Hello again, @shp.<script></script>\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)
|
||||
|
||||
expected_text =
|
||||
"Hello again, <span class='h-card'><a data-user='#{mentioned_user.id}' class='u-url mention' href='shp'>@<span>shp</span></a></span>.<script></script><br>This is on another :firefox: line. <a class='hashtag' data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a class='hashtag' data-tag='epic' href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a class='hashtag' data-tag='phantasmagoric' href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
|
||||
|
||||
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))
|
||||
|
||||
assert Enum.member?(
|
||||
get_in(activity.data, ["to"]),
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
)
|
||||
|
||||
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
|
||||
assert activity.local == true
|
||||
|
||||
assert %{"firefox" => "http://localhost:4001/emoji/Firefox.gif"} = object.data["emoji"]
|
||||
|
||||
# hashtags
|
||||
assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
|
||||
|
||||
# Add a context
|
||||
assert is_binary(get_in(activity.data, ["context"]))
|
||||
assert is_binary(get_in(object.data, ["context"]))
|
||||
|
||||
assert is_list(object.data["attachment"])
|
||||
|
||||
assert activity.data["object"] == object.data["id"]
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert user.info.note_count == 1
|
||||
end
|
||||
|
||||
test "create a status that is a reply" do
|
||||
user = insert(:user)
|
||||
|
||||
input = %{
|
||||
"status" => "Hello again."
|
||||
}
|
||||
|
||||
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
input = %{
|
||||
"status" => "Here's your (you).",
|
||||
"in_reply_to_status_id" => activity.id
|
||||
}
|
||||
|
||||
{:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
|
||||
reply_object = Object.normalize(reply)
|
||||
|
||||
assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
|
||||
|
||||
assert get_in(reply_object.data, ["context"]) == get_in(object.data, ["context"])
|
||||
|
||||
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
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user, followed, _activity} = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
assert User.ap_followers(followed) in user.following
|
||||
|
||||
{:ok, _, _, _} = TwitterAPI.follow(user, %{"user_id" => followed.id})
|
||||
end
|
||||
|
||||
test "Follow another user using screen_name" do
|
||||
user = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, user, followed, _activity} =
|
||||
TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
|
||||
assert User.ap_followers(followed) in user.following
|
||||
|
||||
followed = User.get_cached_by_ap_id(followed.ap_id)
|
||||
assert followed.info.follower_count == 1
|
||||
|
||||
{:ok, _, _, _} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
|
||||
end
|
||||
|
||||
test "Unfollow another user using user_id" do
|
||||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
ActivityPub.follow(user, unfollowed)
|
||||
|
||||
{:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert user.following == []
|
||||
|
||||
{:error, msg} = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
test "Unfollow another user using screen_name" do
|
||||
unfollowed = insert(:user)
|
||||
user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
|
||||
|
||||
ActivityPub.follow(user, unfollowed)
|
||||
|
||||
{:ok, user, unfollowed} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert user.following == []
|
||||
|
||||
{:error, msg} = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
|
||||
assert msg == "Not subscribed!"
|
||||
end
|
||||
|
||||
test "Block another user using user_id" do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, user, blocked} = TwitterAPI.block(user, %{"user_id" => blocked.id})
|
||||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
|
||||
test "Block another user using screen_name" do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user)
|
||||
|
||||
{:ok, user, blocked} = TwitterAPI.block(user, %{"screen_name" => blocked.nickname})
|
||||
assert User.blocks?(user, blocked)
|
||||
end
|
||||
|
||||
test "Unblock another user using user_id" do
|
||||
unblocked = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"user_id" => unblocked.id})
|
||||
|
||||
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"user_id" => unblocked.id})
|
||||
assert user.info.blocks == []
|
||||
end
|
||||
|
||||
test "Unblock another user using screen_name" do
|
||||
unblocked = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, user, _unblocked} = TwitterAPI.block(user, %{"screen_name" => unblocked.nickname})
|
||||
|
||||
{:ok, user, _unblocked} = TwitterAPI.unblock(user, %{"screen_name" => unblocked.nickname})
|
||||
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, 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)
|
||||
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
assert status == updated_activity
|
||||
|
||||
{:ok, _status} = TwitterAPI.fav(other_user, note_activity.id)
|
||||
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
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
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
{:ok, _like_activity, _object} = ActivityPub.like(user, object)
|
||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
||||
|
||||
assert ActivityView.render("activity.json", activity: updated_activity)["fave_num"] == 1
|
||||
|
||||
{:ok, activity} = TwitterAPI.unfav(user, note_activity.id)
|
||||
|
||||
assert ActivityView.render("activity.json", activity: activity)["fave_num"] == 0
|
||||
end
|
||||
|
||||
test "it retweets a status and returns the retweet" do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
{:ok, status} = TwitterAPI.repeat(user, note_activity.id)
|
||||
updated_activity = Activity.get_by_ap_id(note_activity.data["id"])
|
||||
|
||||
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",
|
||||
|
|
@ -281,8 +28,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
fetched_user = User.get_cached_by_nickname("lain")
|
||||
|
||||
assert UserView.render("show.json", %{user: user}) ==
|
||||
UserView.render("show.json", %{user: fetched_user})
|
||||
assert AccountView.render("account.json", %{user: user}) ==
|
||||
AccountView.render("account.json", %{user: fetched_user})
|
||||
end
|
||||
|
||||
test "it registers a new user with empty string in bio and returns the user." do
|
||||
|
|
@ -299,8 +46,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
fetched_user = User.get_cached_by_nickname("lain")
|
||||
|
||||
assert UserView.render("show.json", %{user: user}) ==
|
||||
UserView.render("show.json", %{user: fetched_user})
|
||||
assert AccountView.render("account.json", %{user: user}) ==
|
||||
AccountView.render("account.json", %{user: fetched_user})
|
||||
end
|
||||
|
||||
test "it sends confirmation email if :account_activation_required is specified in instance config" do
|
||||
|
|
@ -397,8 +144,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
assert invite.used == true
|
||||
|
||||
assert UserView.render("show.json", %{user: user}) ==
|
||||
UserView.render("show.json", %{user: fetched_user})
|
||||
assert AccountView.render("account.json", %{user: user}) ==
|
||||
AccountView.render("account.json", %{user: fetched_user})
|
||||
end
|
||||
|
||||
test "returns error on invalid token" do
|
||||
|
|
@ -462,8 +209,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
|
||||
assert UserView.render("show.json", %{user: user}) ==
|
||||
UserView.render("show.json", %{user: fetched_user})
|
||||
assert AccountView.render("account.json", %{user: user}) ==
|
||||
AccountView.render("account.json", %{user: fetched_user})
|
||||
end
|
||||
|
||||
{:ok, data: data, check_fn: check_fn}
|
||||
|
|
@ -537,8 +284,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
assert invite.used == true
|
||||
|
||||
assert UserView.render("show.json", %{user: user}) ==
|
||||
UserView.render("show.json", %{user: fetched_user})
|
||||
assert AccountView.render("account.json", %{user: user}) ==
|
||||
AccountView.render("account.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
|
|
@ -588,8 +335,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
refute invite.used
|
||||
|
||||
assert UserView.render("show.json", %{user: user}) ==
|
||||
UserView.render("show.json", %{user: fetched_user})
|
||||
assert AccountView.render("account.json", %{user: user}) ==
|
||||
AccountView.render("account.json", %{user: fetched_user})
|
||||
end
|
||||
|
||||
test "error after max uses" do
|
||||
|
|
@ -612,8 +359,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
invite = Repo.get_by(UserInviteToken, token: invite.token)
|
||||
assert invite.used == true
|
||||
|
||||
assert UserView.render("show.json", %{user: user}) ==
|
||||
UserView.render("show.json", %{user: fetched_user})
|
||||
assert AccountView.render("account.json", %{user: user}) ==
|
||||
AccountView.render("account.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
|
|
@ -689,31 +436,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
refute User.get_cached_by_nickname("lain")
|
||||
end
|
||||
|
||||
test "it assigns an integer conversation_id" do
|
||||
note_activity = insert(:note_activity)
|
||||
status = ActivityView.render("activity.json", activity: note_activity)
|
||||
|
||||
assert is_number(status["statusnet_conversation_id"])
|
||||
end
|
||||
|
||||
setup do
|
||||
Supervisor.terminate_child(Pleroma.Supervisor, Cachex)
|
||||
Supervisor.restart_child(Pleroma.Supervisor, Cachex)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "fetching a user by uri" do
|
||||
test "fetches a user by uri" do
|
||||
id = "https://mastodon.social/users/lambadalambda"
|
||||
user = insert(:user)
|
||||
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
|
||||
remote = User.get_cached_by_ap_id(id)
|
||||
|
||||
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
|
||||
|
||||
# Also fetches the feed.
|
||||
# assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
|
||||
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -141,37 +140,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/notifications/read" do
|
||||
test "it marks a single notification as read", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"})
|
||||
{:ok, [notification1]} = Notification.create_notifications(activity1)
|
||||
{:ok, [notification2]} = Notification.create_notifications(activity2)
|
||||
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/pleroma/notifications/read", %{"id" => "#{notification1.id}"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert Repo.get(Notification, notification1.id).seen
|
||||
refute Repo.get(Notification, notification2.id).seen
|
||||
end
|
||||
|
||||
test "it returns error when notification not found", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user1)
|
||||
|> post("/api/pleroma/notifications/read", %{"id" => "22222222222222"})
|
||||
|> json_response(403)
|
||||
|
||||
assert response == %{"error" => "Cannot get notification"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /api/pleroma/notification_settings" do
|
||||
test "it updates notification settings", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
@ -694,4 +662,111 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert called(Pleroma.Captcha.new())
|
||||
end
|
||||
end
|
||||
|
||||
defp with_credentials(conn, username, password) do
|
||||
header_content = "Basic " <> Base.encode64("#{username}:#{password}")
|
||||
put_req_header(conn, "authorization", header_content)
|
||||
end
|
||||
|
||||
defp valid_user(_context) do
|
||||
user = insert(:user)
|
||||
[user: user]
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/change_email" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without credentials", %{conn: conn} do
|
||||
conn = post(conn, "/api/pleroma/change_email")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_email", %{
|
||||
"password" => "hi",
|
||||
"email" => "test@test.com"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and invalid email", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => "foobar"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email has invalid format."}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and no email", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_email", %{
|
||||
"password" => "test"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and blank email", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => ""
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email can't be blank."}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and non unique email", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => user.email
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Email has already been taken."}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and valid email", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_email", %{
|
||||
"password" => "test",
|
||||
"email" => "cofe@foobar.com"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,384 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
import Mock
|
||||
|
||||
test "returns a temporary ap_id based user for activities missing db users" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
||||
|
||||
Repo.delete(user)
|
||||
Cachex.clear(:user_cache)
|
||||
|
||||
%{"user" => tw_user} = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
assert tw_user["screen_name"] == "erroruser@example.com"
|
||||
assert tw_user["name"] == user.ap_id
|
||||
assert tw_user["statusnet_profile_url"] == user.ap_id
|
||||
end
|
||||
|
||||
test "tries to get a user by nickname if fetching by ap_id doesn't work" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
|
||||
|> Repo.update()
|
||||
|
||||
Cachex.clear(:user_cache)
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
assert result["user"]["id"] == user.id
|
||||
end
|
||||
|
||||
test "tells if the message is muted for some reason" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.mute(user, other_user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||
status = ActivityView.render("activity.json", %{activity: activity})
|
||||
|
||||
assert status["muted"] == false
|
||||
|
||||
status = ActivityView.render("activity.json", %{activity: activity, for: user})
|
||||
|
||||
assert status["muted"] == true
|
||||
end
|
||||
|
||||
test "a create activity with a html status" do
|
||||
text = """
|
||||
#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
|
||||
"""
|
||||
|
||||
{:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
assert result["statusnet_html"] ==
|
||||
"<a class=\"hashtag\" data-tag=\"bike\" href=\"http://localhost:4001/tag/bike\" rel=\"tag\">#Bike</a> log - Commute Tuesday<br /><a href=\"https://pla.bike/posts/20181211/\">https://pla.bike/posts/20181211/</a><br /><a class=\"hashtag\" data-tag=\"cycling\" href=\"http://localhost:4001/tag/cycling\" rel=\"tag\">#cycling</a> <a class=\"hashtag\" data-tag=\"chscycling\" href=\"http://localhost:4001/tag/chscycling\" rel=\"tag\">#CHScycling</a> <a class=\"hashtag\" data-tag=\"commute\" href=\"http://localhost:4001/tag/commute\" rel=\"tag\">#commute</a><br />MVIMG_20181211_054020.jpg"
|
||||
|
||||
assert result["text"] ==
|
||||
"#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
|
||||
end
|
||||
|
||||
test "a create activity with a summary containing emoji" do
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(insert(:user), %{
|
||||
"spoiler_text" => ":firefox: meow",
|
||||
"status" => "."
|
||||
})
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
expected = ":firefox: meow"
|
||||
|
||||
expected_html =
|
||||
"<img class=\"emoji\" alt=\"firefox\" title=\"firefox\" src=\"http://localhost:4001/emoji/Firefox.gif\" /> meow"
|
||||
|
||||
assert result["summary"] == expected
|
||||
assert result["summary_html"] == expected_html
|
||||
end
|
||||
|
||||
test "a create activity with a summary containing invalid HTML" do
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(insert(:user), %{
|
||||
"spoiler_text" => "<span style=\"color: magenta; font-size: 32px;\">meow</span>",
|
||||
"status" => "."
|
||||
})
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
expected = "meow"
|
||||
|
||||
assert result["summary"] == expected
|
||||
assert result["summary_html"] == expected
|
||||
end
|
||||
|
||||
test "a create activity with a note" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
||||
object = Object.normalize(activity)
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
convo_id = Utils.context_to_conversation_id(object.data["context"])
|
||||
|
||||
expected = %{
|
||||
"activity_type" => "post",
|
||||
"attachments" => [],
|
||||
"attentions" => [
|
||||
UserView.render("show.json", %{user: other_user})
|
||||
],
|
||||
"created_at" => object.data["published"] |> Utils.date_to_asctime(),
|
||||
"external_url" => object.data["id"],
|
||||
"fave_num" => 0,
|
||||
"favorited" => false,
|
||||
"id" => activity.id,
|
||||
"in_reply_to_status_id" => nil,
|
||||
"in_reply_to_screen_name" => nil,
|
||||
"in_reply_to_user_id" => nil,
|
||||
"in_reply_to_profileurl" => nil,
|
||||
"in_reply_to_ostatus_uri" => nil,
|
||||
"is_local" => true,
|
||||
"is_post_verb" => true,
|
||||
"possibly_sensitive" => false,
|
||||
"repeat_num" => 0,
|
||||
"repeated" => false,
|
||||
"pinned" => false,
|
||||
"statusnet_conversation_id" => convo_id,
|
||||
"summary" => "",
|
||||
"summary_html" => "",
|
||||
"statusnet_html" =>
|
||||
"Hey <span class=\"h-card\"><a data-user=\"#{other_user.id}\" class=\"u-url mention\" href=\"#{
|
||||
other_user.ap_id
|
||||
}\">@<span>shp</span></a></span>!",
|
||||
"tags" => [],
|
||||
"text" => "Hey @shp!",
|
||||
"uri" => object.data["id"],
|
||||
"user" => UserView.render("show.json", %{user: user}),
|
||||
"visibility" => "direct",
|
||||
"card" => nil,
|
||||
"muted" => false
|
||||
}
|
||||
|
||||
assert result == expected
|
||||
end
|
||||
|
||||
test "a list of activities" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{nickname: "shp"})
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||
object = Object.normalize(activity)
|
||||
|
||||
convo_id = Utils.context_to_conversation_id(object.data["context"])
|
||||
|
||||
mocks = [
|
||||
{
|
||||
Utils,
|
||||
[:passthrough],
|
||||
[context_to_conversation_id: fn _ -> false end]
|
||||
},
|
||||
{
|
||||
User,
|
||||
[:passthrough],
|
||||
[get_cached_by_ap_id: fn _ -> nil end]
|
||||
}
|
||||
]
|
||||
|
||||
with_mocks mocks do
|
||||
[result] = ActivityView.render("index.json", activities: [activity])
|
||||
|
||||
assert result["statusnet_conversation_id"] == convo_id
|
||||
assert result["user"]
|
||||
refute called(Utils.context_to_conversation_id(:_))
|
||||
refute called(User.get_cached_by_ap_id(user.ap_id))
|
||||
refute called(User.get_cached_by_ap_id(other_user.ap_id))
|
||||
end
|
||||
end
|
||||
|
||||
test "an activity that is a reply" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||
|
||||
{:ok, answer} =
|
||||
CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
|
||||
|
||||
result = ActivityView.render("activity.json", %{activity: answer})
|
||||
|
||||
assert result["in_reply_to_status_id"] == activity.id
|
||||
end
|
||||
|
||||
test "a like activity" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
|
||||
|
||||
result = ActivityView.render("activity.json", activity: like)
|
||||
activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
|
||||
|
||||
expected = %{
|
||||
"activity_type" => "like",
|
||||
"created_at" => like.data["published"] |> Utils.date_to_asctime(),
|
||||
"external_url" => like.data["id"],
|
||||
"id" => like.id,
|
||||
"in_reply_to_status_id" => activity.id,
|
||||
"is_local" => true,
|
||||
"is_post_verb" => false,
|
||||
"favorited_status" => ActivityView.render("activity.json", activity: activity),
|
||||
"statusnet_html" => "shp favorited a status.",
|
||||
"text" => "shp favorited a status.",
|
||||
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
|
||||
"user" => UserView.render("show.json", user: other_user)
|
||||
}
|
||||
|
||||
assert result == expected
|
||||
end
|
||||
|
||||
test "a like activity for deleted post" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
|
||||
CommonAPI.delete(activity.id, user)
|
||||
|
||||
result = ActivityView.render("activity.json", activity: like)
|
||||
|
||||
expected = %{
|
||||
"activity_type" => "like",
|
||||
"created_at" => like.data["published"] |> Utils.date_to_asctime(),
|
||||
"external_url" => like.data["id"],
|
||||
"id" => like.id,
|
||||
"in_reply_to_status_id" => nil,
|
||||
"is_local" => true,
|
||||
"is_post_verb" => false,
|
||||
"favorited_status" => nil,
|
||||
"statusnet_html" => "shp favorited a status.",
|
||||
"text" => "shp favorited a status.",
|
||||
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
|
||||
"user" => UserView.render("show.json", user: other_user)
|
||||
}
|
||||
|
||||
assert result == expected
|
||||
end
|
||||
|
||||
test "an announce activity" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||
{:ok, announce, object} = CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
convo_id = Utils.context_to_conversation_id(object.data["context"])
|
||||
|
||||
activity = Activity.get_by_id(activity.id)
|
||||
|
||||
result = ActivityView.render("activity.json", activity: announce)
|
||||
|
||||
expected = %{
|
||||
"activity_type" => "repeat",
|
||||
"created_at" => announce.data["published"] |> Utils.date_to_asctime(),
|
||||
"external_url" => announce.data["id"],
|
||||
"id" => announce.id,
|
||||
"is_local" => true,
|
||||
"is_post_verb" => false,
|
||||
"statusnet_html" => "shp repeated a status.",
|
||||
"text" => "shp repeated a status.",
|
||||
"uri" => "tag:#{announce.data["id"]}:objectType=note",
|
||||
"user" => UserView.render("show.json", user: other_user),
|
||||
"retweeted_status" => ActivityView.render("activity.json", activity: activity),
|
||||
"statusnet_conversation_id" => convo_id
|
||||
}
|
||||
|
||||
assert result == expected
|
||||
end
|
||||
|
||||
test "A follow activity" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{nickname: "shp"})
|
||||
|
||||
{:ok, follower} = User.follow(user, other_user)
|
||||
{:ok, follow} = ActivityPub.follow(follower, other_user)
|
||||
|
||||
result = ActivityView.render("activity.json", activity: follow)
|
||||
|
||||
expected = %{
|
||||
"activity_type" => "follow",
|
||||
"attentions" => [],
|
||||
"created_at" => follow.data["published"] |> Utils.date_to_asctime(),
|
||||
"external_url" => follow.data["id"],
|
||||
"id" => follow.id,
|
||||
"in_reply_to_status_id" => nil,
|
||||
"is_local" => true,
|
||||
"is_post_verb" => false,
|
||||
"statusnet_html" => "#{user.nickname} started following shp",
|
||||
"text" => "#{user.nickname} started following shp",
|
||||
"user" => UserView.render("show.json", user: user)
|
||||
}
|
||||
|
||||
assert result == expected
|
||||
end
|
||||
|
||||
test "a delete activity" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
||||
{:ok, delete} = CommonAPI.delete(activity.id, user)
|
||||
|
||||
result = ActivityView.render("activity.json", activity: delete)
|
||||
|
||||
expected = %{
|
||||
"activity_type" => "delete",
|
||||
"attentions" => [],
|
||||
"created_at" => delete.data["published"] |> Utils.date_to_asctime(),
|
||||
"external_url" => delete.data["id"],
|
||||
"id" => delete.id,
|
||||
"in_reply_to_status_id" => nil,
|
||||
"is_local" => true,
|
||||
"is_post_verb" => false,
|
||||
"statusnet_html" => "deleted notice {{tag",
|
||||
"text" => "deleted notice {{tag",
|
||||
"uri" => Object.normalize(delete).data["id"],
|
||||
"user" => UserView.render("show.json", user: user)
|
||||
}
|
||||
|
||||
assert result == expected
|
||||
end
|
||||
|
||||
test "a peertube video" do
|
||||
{:ok, object} =
|
||||
Pleroma.Object.Fetcher.fetch_object_from_id(
|
||||
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
||||
)
|
||||
|
||||
%Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
assert length(result["attachments"]) == 1
|
||||
assert result["summary"] == "Friday Night"
|
||||
end
|
||||
|
||||
test "special characters are not escaped in text field for status created" do
|
||||
text = "<3 is on the way"
|
||||
|
||||
{:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
|
||||
|
||||
result = ActivityView.render("activity.json", activity: activity)
|
||||
|
||||
assert result["text"] == text
|
||||
end
|
||||
end
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.TwitterAPI.ActivityView
|
||||
alias Pleroma.Web.TwitterAPI.NotificationView
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
user = insert(:user, bio: "<span>Here's some html</span>")
|
||||
[user: user]
|
||||
end
|
||||
|
||||
test "A follow notification" do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
{:ok, activity} = ActivityPub.follow(follower, user)
|
||||
Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
|
||||
[follow_notif] = Notification.for_user(user)
|
||||
|
||||
represented = %{
|
||||
"created_at" => follow_notif.inserted_at |> Utils.format_naive_asctime(),
|
||||
"from_profile" => UserView.render("show.json", %{user: follower, for: user}),
|
||||
"id" => follow_notif.id,
|
||||
"is_seen" => 0,
|
||||
"notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
|
||||
"ntype" => "follow"
|
||||
}
|
||||
|
||||
assert represented ==
|
||||
NotificationView.render("notification.json", %{notification: follow_notif, for: user})
|
||||
end
|
||||
|
||||
test "A mention notification" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
|
||||
|
||||
[notification] = Notification.for_user(user)
|
||||
|
||||
represented = %{
|
||||
"created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
|
||||
"from_profile" => UserView.render("show.json", %{user: other_user, for: user}),
|
||||
"id" => notification.id,
|
||||
"is_seen" => 0,
|
||||
"notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
|
||||
"ntype" => "mention"
|
||||
}
|
||||
|
||||
assert represented ==
|
||||
NotificationView.render("notification.json", %{notification: notification, for: user})
|
||||
end
|
||||
|
||||
test "A retweet notification" do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
repeater = insert(:user)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.repeat(repeater, note_activity.id)
|
||||
[notification] = Notification.for_user(user)
|
||||
|
||||
represented = %{
|
||||
"created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
|
||||
"from_profile" => UserView.render("show.json", %{user: repeater, for: user}),
|
||||
"id" => notification.id,
|
||||
"is_seen" => 0,
|
||||
"notice" =>
|
||||
ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
|
||||
"ntype" => "repeat"
|
||||
}
|
||||
|
||||
assert represented ==
|
||||
NotificationView.render("notification.json", %{notification: notification, for: user})
|
||||
end
|
||||
|
||||
test "A like notification" do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
liker = insert(:user)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.fav(liker, note_activity.id)
|
||||
[notification] = Notification.for_user(user)
|
||||
|
||||
represented = %{
|
||||
"created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
|
||||
"from_profile" => UserView.render("show.json", %{user: liker, for: user}),
|
||||
"id" => notification.id,
|
||||
"is_seen" => 0,
|
||||
"notice" =>
|
||||
ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
|
||||
"ntype" => "like"
|
||||
}
|
||||
|
||||
assert represented ==
|
||||
NotificationView.render("notification.json", %{notification: notification, for: user})
|
||||
end
|
||||
end
|
||||
|
|
@ -1,323 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.UserViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
user = insert(:user, bio: "<span>Here's some html</span>")
|
||||
[user: user]
|
||||
end
|
||||
|
||||
test "A user with only a nickname", %{user: user} do
|
||||
user = %{user | name: nil, nickname: "scarlett@catgirl.science"}
|
||||
represented = UserView.render("show.json", %{user: user})
|
||||
assert represented["name"] == user.nickname
|
||||
assert represented["name_html"] == user.nickname
|
||||
end
|
||||
|
||||
test "A user with an avatar object", %{user: user} do
|
||||
image = "image"
|
||||
user = %{user | avatar: %{"url" => [%{"href" => image}]}}
|
||||
represented = UserView.render("show.json", %{user: user})
|
||||
assert represented["profile_image_url"] == image
|
||||
end
|
||||
|
||||
test "A user with emoji in username" do
|
||||
expected =
|
||||
"<img class=\"emoji\" alt=\"karjalanpiirakka\" title=\"karjalanpiirakka\" src=\"/file.png\" /> man"
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{
|
||||
source_data: %{
|
||||
"tag" => [
|
||||
%{
|
||||
"type" => "Emoji",
|
||||
"icon" => %{"url" => "/file.png"},
|
||||
"name" => ":karjalanpiirakka:"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
name: ":karjalanpiirakka: man"
|
||||
})
|
||||
|
||||
represented = UserView.render("show.json", %{user: user})
|
||||
assert represented["name_html"] == expected
|
||||
end
|
||||
|
||||
test "A user" do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
{:ok, user} = User.update_note_count(user)
|
||||
follower = insert(:user)
|
||||
second_follower = insert(:user)
|
||||
|
||||
User.follow(follower, user)
|
||||
User.follow(second_follower, user)
|
||||
User.follow(user, follower)
|
||||
{:ok, user} = User.update_follower_count(user)
|
||||
Cachex.put(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
|
||||
|
||||
image = "http://localhost:4001/images/avi.png"
|
||||
banner = "http://localhost:4001/images/banner.png"
|
||||
|
||||
represented = %{
|
||||
"id" => user.id,
|
||||
"name" => user.name,
|
||||
"screen_name" => user.nickname,
|
||||
"name_html" => user.name,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
|
||||
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 1,
|
||||
"friends_count" => 1,
|
||||
"followers_count" => 2,
|
||||
"profile_image_url" => image,
|
||||
"profile_image_url_https" => image,
|
||||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => false,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => false,
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => [],
|
||||
"skip_thread_containment" => false
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: user})
|
||||
end
|
||||
|
||||
test "User exposes settings for themselves and only for themselves", %{user: user} do
|
||||
as_user = UserView.render("show.json", %{user: user, for: user})
|
||||
assert as_user["default_scope"] == user.info.default_scope
|
||||
assert as_user["no_rich_text"] == user.info.no_rich_text
|
||||
assert as_user["pleroma"]["notification_settings"] == user.info.notification_settings
|
||||
as_stranger = UserView.render("show.json", %{user: user})
|
||||
refute as_stranger["default_scope"]
|
||||
refute as_stranger["no_rich_text"]
|
||||
refute as_stranger["pleroma"]["notification_settings"]
|
||||
end
|
||||
|
||||
test "A user for a given other follower", %{user: user} do
|
||||
follower = insert(:user, %{following: [User.ap_followers(user)]})
|
||||
{:ok, user} = User.update_follower_count(user)
|
||||
image = "http://localhost:4001/images/avi.png"
|
||||
banner = "http://localhost:4001/images/banner.png"
|
||||
|
||||
represented = %{
|
||||
"id" => user.id,
|
||||
"name" => user.name,
|
||||
"screen_name" => user.nickname,
|
||||
"name_html" => user.name,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
|
||||
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 0,
|
||||
"followers_count" => 1,
|
||||
"profile_image_url" => image,
|
||||
"profile_image_url_https" => image,
|
||||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => true,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => false,
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => [],
|
||||
"skip_thread_containment" => false
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: user, for: follower})
|
||||
end
|
||||
|
||||
test "A user that follows you", %{user: user} do
|
||||
follower = insert(:user)
|
||||
{:ok, follower} = User.follow(follower, user)
|
||||
{:ok, user} = User.update_follower_count(user)
|
||||
image = "http://localhost:4001/images/avi.png"
|
||||
banner = "http://localhost:4001/images/banner.png"
|
||||
|
||||
represented = %{
|
||||
"id" => follower.id,
|
||||
"name" => follower.name,
|
||||
"screen_name" => follower.nickname,
|
||||
"name_html" => follower.name,
|
||||
"description" => HtmlSanitizeEx.strip_tags(follower.bio |> String.replace("<br>", "\n")),
|
||||
"description_html" => HtmlSanitizeEx.basic_html(follower.bio),
|
||||
"created_at" => follower.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 1,
|
||||
"followers_count" => 0,
|
||||
"profile_image_url" => image,
|
||||
"profile_image_url_https" => image,
|
||||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => false,
|
||||
"follows_you" => true,
|
||||
"statusnet_blocking" => false,
|
||||
"statusnet_profile_url" => follower.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => [],
|
||||
"skip_thread_containment" => false
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
assert represented == UserView.render("show.json", %{user: follower, for: user})
|
||||
end
|
||||
|
||||
test "a user that is a moderator" do
|
||||
user = insert(:user, %{info: %{is_moderator: true}})
|
||||
represented = UserView.render("show.json", %{user: user, for: user})
|
||||
|
||||
assert represented["rights"]["delete_others_notice"]
|
||||
assert represented["role"] == "moderator"
|
||||
end
|
||||
|
||||
test "a user that is a admin" do
|
||||
user = insert(:user, %{info: %{is_admin: true}})
|
||||
represented = UserView.render("show.json", %{user: user, for: user})
|
||||
|
||||
assert represented["rights"]["admin"]
|
||||
assert represented["role"] == "admin"
|
||||
end
|
||||
|
||||
test "A moderator with hidden role for another user", %{user: user} do
|
||||
admin = insert(:user, %{info: %{is_moderator: true, show_role: false}})
|
||||
represented = UserView.render("show.json", %{user: admin, for: user})
|
||||
|
||||
assert represented["role"] == nil
|
||||
end
|
||||
|
||||
test "An admin with hidden role for another user", %{user: user} do
|
||||
admin = insert(:user, %{info: %{is_admin: true, show_role: false}})
|
||||
represented = UserView.render("show.json", %{user: admin, for: user})
|
||||
|
||||
assert represented["role"] == nil
|
||||
end
|
||||
|
||||
test "A regular user for the admin", %{user: user} do
|
||||
admin = insert(:user, %{info: %{is_admin: true}})
|
||||
represented = UserView.render("show.json", %{user: user, for: admin})
|
||||
|
||||
assert represented["pleroma"]["deactivated"] == false
|
||||
end
|
||||
|
||||
test "A blocked user for the blocker" do
|
||||
user = insert(:user)
|
||||
blocker = insert(:user)
|
||||
User.block(blocker, user)
|
||||
image = "http://localhost:4001/images/avi.png"
|
||||
banner = "http://localhost:4001/images/banner.png"
|
||||
|
||||
represented = %{
|
||||
"id" => user.id,
|
||||
"name" => user.name,
|
||||
"screen_name" => user.nickname,
|
||||
"name_html" => user.name,
|
||||
"description" => HtmlSanitizeEx.strip_tags(user.bio |> String.replace("<br>", "\n")),
|
||||
"description_html" => HtmlSanitizeEx.basic_html(user.bio),
|
||||
"created_at" => user.inserted_at |> Utils.format_naive_asctime(),
|
||||
"favourites_count" => 0,
|
||||
"statuses_count" => 0,
|
||||
"friends_count" => 0,
|
||||
"followers_count" => 0,
|
||||
"profile_image_url" => image,
|
||||
"profile_image_url_https" => image,
|
||||
"profile_image_url_profile_size" => image,
|
||||
"profile_image_url_original" => image,
|
||||
"following" => false,
|
||||
"follows_you" => false,
|
||||
"statusnet_blocking" => true,
|
||||
"statusnet_profile_url" => user.ap_id,
|
||||
"cover_photo" => banner,
|
||||
"background_image" => nil,
|
||||
"is_local" => true,
|
||||
"locked" => false,
|
||||
"hide_follows" => false,
|
||||
"hide_followers" => false,
|
||||
"fields" => [],
|
||||
"pleroma" => %{
|
||||
"confirmation_pending" => false,
|
||||
"tags" => [],
|
||||
"skip_thread_containment" => false
|
||||
},
|
||||
"rights" => %{"admin" => false, "delete_others_notice" => false},
|
||||
"role" => "member"
|
||||
}
|
||||
|
||||
blocker = User.get_cached_by_id(blocker.id)
|
||||
assert represented == UserView.render("show.json", %{user: user, for: blocker})
|
||||
end
|
||||
|
||||
test "a user with mastodon fields" do
|
||||
fields = [
|
||||
%{
|
||||
"name" => "Pronouns",
|
||||
"value" => "she/her"
|
||||
},
|
||||
%{
|
||||
"name" => "Website",
|
||||
"value" => "https://example.org/"
|
||||
}
|
||||
]
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{
|
||||
source_data: %{
|
||||
"attachment" =>
|
||||
Enum.map(fields, fn field -> Map.put(field, "type", "PropertyValue") end)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
userview = UserView.render("show.json", %{user: user})
|
||||
assert userview["fields"] == fields
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue