1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
6 use Pleroma.Web.ConnCase
9 alias Pleroma.ActivityExpiration
11 alias Pleroma.Conversation.Participation
14 alias Pleroma.ScheduledActivity
15 alias Pleroma.Tests.ObanHelpers
17 alias Pleroma.Web.ActivityPub.ActivityPub
18 alias Pleroma.Web.CommonAPI
20 import Pleroma.Factory
22 setup do: clear_config([:instance, :federating])
23 setup do: clear_config([:instance, :allow_relay])
24 setup do: clear_config([:rich_media, :enabled])
25 setup do: clear_config([:mrf, :policies])
26 setup do: clear_config([:mrf_keyword, :reject])
28 describe "posting statuses" do
29 setup do: oauth_access(["write:statuses"])
31 test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
32 Pleroma.Config.put([:instance, :federating], true)
33 Pleroma.Config.get([:instance, :allow_relay], true)
37 |> put_req_header("content-type", "application/json")
38 |> post("api/v1/statuses", %{
39 "content_type" => "text/plain",
40 "source" => "Pleroma FE",
41 "status" => "Hello world",
42 "visibility" => "public"
44 |> json_response_and_validate_schema(200)
46 assert response["reblogs_count"] == 0
47 ObanHelpers.perform_all()
51 |> get("api/v1/statuses/#{response["id"]}", %{})
52 |> json_response_and_validate_schema(200)
54 assert response["reblogs_count"] == 0
57 test "posting a status", %{conn: conn} do
58 idempotency_key = "Pikachu rocks!"
62 |> put_req_header("content-type", "application/json")
63 |> put_req_header("idempotency-key", idempotency_key)
64 |> post("/api/v1/statuses", %{
66 "spoiler_text" => "2hu",
70 {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
72 assert ttl > :timer.seconds(6 * 60 * 60 - 1)
74 assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} =
75 json_response_and_validate_schema(conn_one, 200)
77 assert Activity.get_by_id(id)
81 |> put_req_header("content-type", "application/json")
82 |> put_req_header("idempotency-key", idempotency_key)
83 |> post("/api/v1/statuses", %{
85 "spoiler_text" => "2hu",
89 assert %{"id" => second_id} = json_response(conn_two, 200)
90 assert id == second_id
94 |> put_req_header("content-type", "application/json")
95 |> post("/api/v1/statuses", %{
97 "spoiler_text" => "2hu",
98 "sensitive" => "False"
101 assert %{"id" => third_id} = json_response_and_validate_schema(conn_three, 200)
102 refute id == third_id
104 # An activity that will expire:
106 expires_in = 120 * 60
110 |> put_req_header("content-type", "application/json")
111 |> post("api/v1/statuses", %{
112 "status" => "oolong",
113 "expires_in" => expires_in
116 assert fourth_response =
117 %{"id" => fourth_id} = json_response_and_validate_schema(conn_four, 200)
119 assert activity = Activity.get_by_id(fourth_id)
120 assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
122 estimated_expires_at =
123 NaiveDateTime.utc_now()
124 |> NaiveDateTime.add(expires_in)
125 |> NaiveDateTime.truncate(:second)
127 # This assert will fail if the test takes longer than a minute. I sure hope it never does:
128 assert abs(NaiveDateTime.diff(expiration.scheduled_at, estimated_expires_at, :second)) < 60
130 assert fourth_response["pleroma"]["expires_at"] ==
131 NaiveDateTime.to_iso8601(expiration.scheduled_at)
134 test "it fails to create a status if `expires_in` is less or equal than an hour", %{
140 assert %{"error" => "Expiry date is too soon"} =
142 |> put_req_header("content-type", "application/json")
143 |> post("api/v1/statuses", %{
144 "status" => "oolong",
145 "expires_in" => expires_in
147 |> json_response_and_validate_schema(422)
152 assert %{"error" => "Expiry date is too soon"} =
154 |> put_req_header("content-type", "application/json")
155 |> post("api/v1/statuses", %{
156 "status" => "oolong",
157 "expires_in" => expires_in
159 |> json_response_and_validate_schema(422)
162 test "Get MRF reason when posting a status is rejected by one", %{conn: conn} do
163 Pleroma.Config.put([:mrf_keyword, :reject], ["GNO"])
164 Pleroma.Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
166 assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =
168 |> put_req_header("content-type", "application/json")
169 |> post("api/v1/statuses", %{"status" => "GNO/Linux"})
170 |> json_response_and_validate_schema(422)
173 test "posting an undefined status with an attachment", %{user: user, conn: conn} do
175 content_type: "image/jpg",
176 path: Path.absname("test/fixtures/image.jpg"),
177 filename: "an_image.jpg"
180 {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
184 |> put_req_header("content-type", "application/json")
185 |> post("/api/v1/statuses", %{
186 "media_ids" => [to_string(upload.id)]
189 assert json_response_and_validate_schema(conn, 200)
192 test "replying to a status", %{user: user, conn: conn} do
193 {:ok, replied_to} = CommonAPI.post(user, %{status: "cofe"})
197 |> put_req_header("content-type", "application/json")
198 |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
200 assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn, 200)
202 activity = Activity.get_by_id(id)
204 assert activity.data["context"] == replied_to.data["context"]
205 assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
208 test "replying to a direct message with visibility other than direct", %{
212 {:ok, replied_to} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
214 Enum.each(["public", "private", "unlisted"], fn visibility ->
217 |> put_req_header("content-type", "application/json")
218 |> post("/api/v1/statuses", %{
219 "status" => "@#{user.nickname} hey",
220 "in_reply_to_id" => replied_to.id,
221 "visibility" => visibility
224 assert json_response_and_validate_schema(conn, 422) == %{
225 "error" => "The message visibility must be direct"
230 test "posting a status with an invalid in_reply_to_id", %{conn: conn} do
233 |> put_req_header("content-type", "application/json")
234 |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => ""})
236 assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn, 200)
237 assert Activity.get_by_id(id)
240 test "posting a sensitive status", %{conn: conn} do
243 |> put_req_header("content-type", "application/json")
244 |> post("/api/v1/statuses", %{"status" => "cofe", "sensitive" => true})
246 assert %{"content" => "cofe", "id" => id, "sensitive" => true} =
247 json_response_and_validate_schema(conn, 200)
249 assert Activity.get_by_id(id)
252 test "posting a fake status", %{conn: conn} do
255 |> put_req_header("content-type", "application/json")
256 |> post("/api/v1/statuses", %{
258 "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it"
261 real_status = json_response_and_validate_schema(real_conn, 200)
264 assert Object.get_by_ap_id(real_status["uri"])
268 |> Map.put("id", nil)
269 |> Map.put("url", nil)
270 |> Map.put("uri", nil)
271 |> Map.put("created_at", nil)
272 |> Kernel.put_in(["pleroma", "conversation_id"], nil)
276 |> put_req_header("content-type", "application/json")
277 |> post("/api/v1/statuses", %{
279 "\"Tenshi Eating a Corndog\" is a much discussed concept on /jp/. The significance of it is disputed, so I will focus on one core concept: the symbolism behind it",
283 fake_status = json_response_and_validate_schema(fake_conn, 200)
286 refute Object.get_by_ap_id(fake_status["uri"])
290 |> Map.put("id", nil)
291 |> Map.put("url", nil)
292 |> Map.put("uri", nil)
293 |> Map.put("created_at", nil)
294 |> Kernel.put_in(["pleroma", "conversation_id"], nil)
296 assert real_status == fake_status
299 test "posting a status with OGP link preview", %{conn: conn} do
300 Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
301 Config.put([:rich_media, :enabled], true)
305 |> put_req_header("content-type", "application/json")
306 |> post("/api/v1/statuses", %{
307 "status" => "https://example.com/ogp"
310 assert %{"id" => id, "card" => %{"title" => "The Rock"}} =
311 json_response_and_validate_schema(conn, 200)
313 assert Activity.get_by_id(id)
316 test "posting a direct status", %{conn: conn} do
317 user2 = insert(:user)
318 content = "direct cofe @#{user2.nickname}"
322 |> put_req_header("content-type", "application/json")
323 |> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
325 assert %{"id" => id} = response = json_response_and_validate_schema(conn, 200)
326 assert response["visibility"] == "direct"
327 assert response["pleroma"]["direct_conversation_id"]
328 assert activity = Activity.get_by_id(id)
329 assert activity.recipients == [user2.ap_id, conn.assigns[:user].ap_id]
330 assert activity.data["to"] == [user2.ap_id]
331 assert activity.data["cc"] == []
335 describe "posting scheduled statuses" do
336 setup do: oauth_access(["write:statuses"])
338 test "creates a scheduled activity", %{conn: conn} do
340 NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
341 |> NaiveDateTime.to_iso8601()
346 |> put_req_header("content-type", "application/json")
347 |> post("/api/v1/statuses", %{
348 "status" => "scheduled",
349 "scheduled_at" => scheduled_at
352 assert %{"scheduled_at" => expected_scheduled_at} =
353 json_response_and_validate_schema(conn, 200)
355 assert expected_scheduled_at == CommonAPI.Utils.to_masto_date(scheduled_at)
356 assert [] == Repo.all(Activity)
359 test "ignores nil values", %{conn: conn} do
362 |> put_req_header("content-type", "application/json")
363 |> post("/api/v1/statuses", %{
364 "status" => "not scheduled",
365 "scheduled_at" => nil
368 assert result = json_response_and_validate_schema(conn, 200)
369 assert Activity.get_by_id(result["id"])
372 test "creates a scheduled activity with a media attachment", %{user: user, conn: conn} do
374 NaiveDateTime.utc_now()
375 |> NaiveDateTime.add(:timer.minutes(120), :millisecond)
376 |> NaiveDateTime.to_iso8601()
380 content_type: "image/jpg",
381 path: Path.absname("test/fixtures/image.jpg"),
382 filename: "an_image.jpg"
385 {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
389 |> put_req_header("content-type", "application/json")
390 |> post("/api/v1/statuses", %{
391 "media_ids" => [to_string(upload.id)],
392 "status" => "scheduled",
393 "scheduled_at" => scheduled_at
396 assert %{"media_attachments" => [media_attachment]} =
397 json_response_and_validate_schema(conn, 200)
399 assert %{"type" => "image"} = media_attachment
402 test "skips the scheduling and creates the activity if scheduled_at is earlier than 5 minutes from now",
405 NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(5) - 1, :millisecond)
406 |> NaiveDateTime.to_iso8601()
411 |> put_req_header("content-type", "application/json")
412 |> post("/api/v1/statuses", %{
413 "status" => "not scheduled",
414 "scheduled_at" => scheduled_at
417 assert %{"content" => "not scheduled"} = json_response_and_validate_schema(conn, 200)
418 assert [] == Repo.all(ScheduledActivity)
421 test "returns error when daily user limit is exceeded", %{user: user, conn: conn} do
423 NaiveDateTime.utc_now()
424 |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
425 |> NaiveDateTime.to_iso8601()
429 attrs = %{params: %{}, scheduled_at: today}
430 {:ok, _} = ScheduledActivity.create(user, attrs)
431 {:ok, _} = ScheduledActivity.create(user, attrs)
435 |> put_req_header("content-type", "application/json")
436 |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => today})
438 assert %{"error" => "daily limit exceeded"} == json_response_and_validate_schema(conn, 422)
441 test "returns error when total user limit is exceeded", %{user: user, conn: conn} do
443 NaiveDateTime.utc_now()
444 |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
445 |> NaiveDateTime.to_iso8601()
449 NaiveDateTime.utc_now()
450 |> NaiveDateTime.add(:timer.hours(36), :millisecond)
451 |> NaiveDateTime.to_iso8601()
454 attrs = %{params: %{}, scheduled_at: today}
455 {:ok, _} = ScheduledActivity.create(user, attrs)
456 {:ok, _} = ScheduledActivity.create(user, attrs)
457 {:ok, _} = ScheduledActivity.create(user, %{params: %{}, scheduled_at: tomorrow})
461 |> put_req_header("content-type", "application/json")
462 |> post("/api/v1/statuses", %{"status" => "scheduled", "scheduled_at" => tomorrow})
464 assert %{"error" => "total limit exceeded"} == json_response_and_validate_schema(conn, 422)
468 describe "posting polls" do
469 setup do: oauth_access(["write:statuses"])
471 test "posting a poll", %{conn: conn} do
472 time = NaiveDateTime.utc_now()
476 |> put_req_header("content-type", "application/json")
477 |> post("/api/v1/statuses", %{
478 "status" => "Who is the #bestgrill?",
480 "options" => ["Rei", "Asuka", "Misato"],
485 response = json_response_and_validate_schema(conn, 200)
487 assert Enum.all?(response["poll"]["options"], fn %{"title" => title} ->
488 title in ["Rei", "Asuka", "Misato"]
491 assert NaiveDateTime.diff(NaiveDateTime.from_iso8601!(response["poll"]["expires_at"]), time) in 420..430
492 refute response["poll"]["expred"]
494 question = Object.get_by_id(response["poll"]["id"])
496 # closed contains utc timezone
497 assert question.data["closed"] =~ "Z"
500 test "option limit is enforced", %{conn: conn} do
501 limit = Config.get([:instance, :poll_limits, :max_options])
505 |> put_req_header("content-type", "application/json")
506 |> post("/api/v1/statuses", %{
508 "poll" => %{"options" => Enum.map(0..limit, fn _ -> "desu" end), "expires_in" => 1}
511 %{"error" => error} = json_response_and_validate_schema(conn, 422)
512 assert error == "Poll can't contain more than #{limit} options"
515 test "option character limit is enforced", %{conn: conn} do
516 limit = Config.get([:instance, :poll_limits, :max_option_chars])
520 |> put_req_header("content-type", "application/json")
521 |> post("/api/v1/statuses", %{
524 "options" => [Enum.reduce(0..limit, "", fn _, acc -> acc <> "." end)],
529 %{"error" => error} = json_response_and_validate_schema(conn, 422)
530 assert error == "Poll options cannot be longer than #{limit} characters each"
533 test "minimal date limit is enforced", %{conn: conn} do
534 limit = Config.get([:instance, :poll_limits, :min_expiration])
538 |> put_req_header("content-type", "application/json")
539 |> post("/api/v1/statuses", %{
540 "status" => "imagine arbitrary limits",
542 "options" => ["this post was made by pleroma gang"],
543 "expires_in" => limit - 1
547 %{"error" => error} = json_response_and_validate_schema(conn, 422)
548 assert error == "Expiration date is too soon"
551 test "maximum date limit is enforced", %{conn: conn} do
552 limit = Config.get([:instance, :poll_limits, :max_expiration])
556 |> put_req_header("content-type", "application/json")
557 |> post("/api/v1/statuses", %{
558 "status" => "imagine arbitrary limits",
560 "options" => ["this post was made by pleroma gang"],
561 "expires_in" => limit + 1
565 %{"error" => error} = json_response_and_validate_schema(conn, 422)
566 assert error == "Expiration date is too far in the future"
570 test "get a status" do
571 %{conn: conn} = oauth_access(["read:statuses"])
572 activity = insert(:note_activity)
574 conn = get(conn, "/api/v1/statuses/#{activity.id}")
576 assert %{"id" => id} = json_response_and_validate_schema(conn, 200)
577 assert id == to_string(activity.id)
580 defp local_and_remote_activities do
581 local = insert(:note_activity)
582 remote = insert(:note_activity, local: false)
583 {:ok, local: local, remote: remote}
586 describe "status with restrict unauthenticated activities for local and remote" do
587 setup do: local_and_remote_activities()
589 setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
591 setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
593 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
594 res_conn = get(conn, "/api/v1/statuses/#{local.id}")
596 assert json_response_and_validate_schema(res_conn, :not_found) == %{
597 "error" => "Record not found"
600 res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
602 assert json_response_and_validate_schema(res_conn, :not_found) == %{
603 "error" => "Record not found"
607 test "if user is authenticated", %{local: local, remote: remote} do
608 %{conn: conn} = oauth_access(["read"])
609 res_conn = get(conn, "/api/v1/statuses/#{local.id}")
610 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
612 res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
613 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
617 describe "status with restrict unauthenticated activities for local" do
618 setup do: local_and_remote_activities()
620 setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
622 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
623 res_conn = get(conn, "/api/v1/statuses/#{local.id}")
625 assert json_response_and_validate_schema(res_conn, :not_found) == %{
626 "error" => "Record not found"
629 res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
630 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
633 test "if user is authenticated", %{local: local, remote: remote} do
634 %{conn: conn} = oauth_access(["read"])
635 res_conn = get(conn, "/api/v1/statuses/#{local.id}")
636 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
638 res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
639 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
643 describe "status with restrict unauthenticated activities for remote" do
644 setup do: local_and_remote_activities()
646 setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
648 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
649 res_conn = get(conn, "/api/v1/statuses/#{local.id}")
650 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
652 res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
654 assert json_response_and_validate_schema(res_conn, :not_found) == %{
655 "error" => "Record not found"
659 test "if user is authenticated", %{local: local, remote: remote} do
660 %{conn: conn} = oauth_access(["read"])
661 res_conn = get(conn, "/api/v1/statuses/#{local.id}")
662 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
664 res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
665 assert %{"id" => _} = json_response_and_validate_schema(res_conn, 200)
669 test "getting a status that doesn't exist returns 404" do
670 %{conn: conn} = oauth_access(["read:statuses"])
671 activity = insert(:note_activity)
673 conn = get(conn, "/api/v1/statuses/#{String.downcase(activity.id)}")
675 assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
678 test "get a direct status" do
679 %{user: user, conn: conn} = oauth_access(["read:statuses"])
680 other_user = insert(:user)
683 CommonAPI.post(user, %{status: "@#{other_user.nickname}", visibility: "direct"})
687 |> assign(:user, user)
688 |> get("/api/v1/statuses/#{activity.id}")
690 [participation] = Participation.for_user(user)
692 res = json_response_and_validate_schema(conn, 200)
693 assert res["pleroma"]["direct_conversation_id"] == participation.id
696 test "get statuses by IDs" do
697 %{conn: conn} = oauth_access(["read:statuses"])
698 %{id: id1} = insert(:note_activity)
699 %{id: id2} = insert(:note_activity)
701 query_string = "ids[]=#{id1}&ids[]=#{id2}"
702 conn = get(conn, "/api/v1/statuses/?#{query_string}")
704 assert [%{"id" => ^id1}, %{"id" => ^id2}] =
705 Enum.sort_by(json_response_and_validate_schema(conn, :ok), & &1["id"])
708 describe "getting statuses by ids with restricted unauthenticated for local and remote" do
709 setup do: local_and_remote_activities()
711 setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
713 setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
715 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
716 res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
718 assert json_response_and_validate_schema(res_conn, 200) == []
721 test "if user is authenticated", %{local: local, remote: remote} do
722 %{conn: conn} = oauth_access(["read"])
724 res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
726 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
730 describe "getting statuses by ids with restricted unauthenticated for local" do
731 setup do: local_and_remote_activities()
733 setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
735 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
736 res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
738 remote_id = remote.id
739 assert [%{"id" => ^remote_id}] = json_response_and_validate_schema(res_conn, 200)
742 test "if user is authenticated", %{local: local, remote: remote} do
743 %{conn: conn} = oauth_access(["read"])
745 res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
747 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
751 describe "getting statuses by ids with restricted unauthenticated for remote" do
752 setup do: local_and_remote_activities()
754 setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
756 test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
757 res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
760 assert [%{"id" => ^local_id}] = json_response_and_validate_schema(res_conn, 200)
763 test "if user is authenticated", %{local: local, remote: remote} do
764 %{conn: conn} = oauth_access(["read"])
766 res_conn = get(conn, "/api/v1/statuses?ids[]=#{local.id}&ids[]=#{remote.id}")
768 assert length(json_response_and_validate_schema(res_conn, 200)) == 2
772 describe "deleting a status" do
773 test "when you created it" do
774 %{user: author, conn: conn} = oauth_access(["write:statuses"])
775 activity = insert(:note_activity, user: author)
776 object = Object.normalize(activity)
778 content = object.data["content"]
779 source = object.data["source"]
783 |> assign(:user, author)
784 |> delete("/api/v1/statuses/#{activity.id}")
785 |> json_response_and_validate_schema(200)
787 assert match?(%{"content" => ^content, "text" => ^source}, result)
789 refute Activity.get_by_id(activity.id)
792 test "when it doesn't exist" do
793 %{user: author, conn: conn} = oauth_access(["write:statuses"])
794 activity = insert(:note_activity, user: author)
798 |> assign(:user, author)
799 |> delete("/api/v1/statuses/#{String.downcase(activity.id)}")
801 assert %{"error" => "Record not found"} == json_response_and_validate_schema(conn, 404)
804 test "when you didn't create it" do
805 %{conn: conn} = oauth_access(["write:statuses"])
806 activity = insert(:note_activity)
808 conn = delete(conn, "/api/v1/statuses/#{activity.id}")
810 assert %{"error" => "Record not found"} == json_response_and_validate_schema(conn, 404)
812 assert Activity.get_by_id(activity.id) == activity
815 test "when you're an admin or moderator", %{conn: conn} do
816 activity1 = insert(:note_activity)
817 activity2 = insert(:note_activity)
818 admin = insert(:user, is_admin: true)
819 moderator = insert(:user, is_moderator: true)
823 |> assign(:user, admin)
824 |> assign(:token, insert(:oauth_token, user: admin, scopes: ["write:statuses"]))
825 |> delete("/api/v1/statuses/#{activity1.id}")
827 assert %{} = json_response_and_validate_schema(res_conn, 200)
831 |> assign(:user, moderator)
832 |> assign(:token, insert(:oauth_token, user: moderator, scopes: ["write:statuses"]))
833 |> delete("/api/v1/statuses/#{activity2.id}")
835 assert %{} = json_response_and_validate_schema(res_conn, 200)
837 refute Activity.get_by_id(activity1.id)
838 refute Activity.get_by_id(activity2.id)
842 describe "reblogging" do
843 setup do: oauth_access(["write:statuses"])
845 test "reblogs and returns the reblogged status", %{conn: conn} do
846 activity = insert(:note_activity)
850 |> put_req_header("content-type", "application/json")
851 |> post("/api/v1/statuses/#{activity.id}/reblog")
854 "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
856 } = json_response_and_validate_schema(conn, 200)
858 assert to_string(activity.id) == id
861 test "returns 404 if the reblogged status doesn't exist", %{conn: conn} do
862 activity = insert(:note_activity)
866 |> put_req_header("content-type", "application/json")
867 |> post("/api/v1/statuses/#{String.downcase(activity.id)}/reblog")
869 assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn, 404)
872 test "reblogs privately and returns the reblogged status", %{conn: conn} do
873 activity = insert(:note_activity)
877 |> put_req_header("content-type", "application/json")
879 "/api/v1/statuses/#{activity.id}/reblog",
880 %{"visibility" => "private"}
884 "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1},
886 "visibility" => "private"
887 } = json_response_and_validate_schema(conn, 200)
889 assert to_string(activity.id) == id
892 test "reblogged status for another user" do
893 activity = insert(:note_activity)
894 user1 = insert(:user)
895 user2 = insert(:user)
896 user3 = insert(:user)
897 {:ok, _} = CommonAPI.favorite(user2, activity.id)
898 {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
899 {:ok, reblog_activity1} = CommonAPI.repeat(activity.id, user1)
900 {:ok, _} = CommonAPI.repeat(activity.id, user2)
904 |> assign(:user, user3)
905 |> assign(:token, insert(:oauth_token, user: user3, scopes: ["read:statuses"]))
906 |> get("/api/v1/statuses/#{reblog_activity1.id}")
909 "reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
910 "reblogged" => false,
911 "favourited" => false,
912 "bookmarked" => false
913 } = json_response_and_validate_schema(conn_res, 200)
917 |> assign(:user, user2)
918 |> assign(:token, insert(:oauth_token, user: user2, scopes: ["read:statuses"]))
919 |> get("/api/v1/statuses/#{reblog_activity1.id}")
922 "reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
924 "favourited" => true,
926 } = json_response_and_validate_schema(conn_res, 200)
928 assert to_string(activity.id) == id
932 describe "unreblogging" do
933 setup do: oauth_access(["write:statuses"])
935 test "unreblogs and returns the unreblogged status", %{user: user, conn: conn} do
936 activity = insert(:note_activity)
938 {:ok, _} = CommonAPI.repeat(activity.id, user)
942 |> put_req_header("content-type", "application/json")
943 |> post("/api/v1/statuses/#{activity.id}/unreblog")
945 assert %{"id" => id, "reblogged" => false, "reblogs_count" => 0} =
946 json_response_and_validate_schema(conn, 200)
948 assert to_string(activity.id) == id
951 test "returns 404 error when activity does not exist", %{conn: conn} do
954 |> put_req_header("content-type", "application/json")
955 |> post("/api/v1/statuses/foo/unreblog")
957 assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
961 describe "favoriting" do
962 setup do: oauth_access(["write:favourites"])
964 test "favs a status and returns it", %{conn: conn} do
965 activity = insert(:note_activity)
969 |> put_req_header("content-type", "application/json")
970 |> post("/api/v1/statuses/#{activity.id}/favourite")
972 assert %{"id" => id, "favourites_count" => 1, "favourited" => true} =
973 json_response_and_validate_schema(conn, 200)
975 assert to_string(activity.id) == id
978 test "favoriting twice will just return 200", %{conn: conn} do
979 activity = insert(:note_activity)
982 |> put_req_header("content-type", "application/json")
983 |> post("/api/v1/statuses/#{activity.id}/favourite")
986 |> put_req_header("content-type", "application/json")
987 |> post("/api/v1/statuses/#{activity.id}/favourite")
988 |> json_response_and_validate_schema(200)
991 test "returns 404 error for a wrong id", %{conn: conn} do
994 |> put_req_header("content-type", "application/json")
995 |> post("/api/v1/statuses/1/favourite")
997 assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
1001 describe "unfavoriting" do
1002 setup do: oauth_access(["write:favourites"])
1004 test "unfavorites a status and returns it", %{user: user, conn: conn} do
1005 activity = insert(:note_activity)
1007 {:ok, _} = CommonAPI.favorite(user, activity.id)
1011 |> put_req_header("content-type", "application/json")
1012 |> post("/api/v1/statuses/#{activity.id}/unfavourite")
1014 assert %{"id" => id, "favourites_count" => 0, "favourited" => false} =
1015 json_response_and_validate_schema(conn, 200)
1017 assert to_string(activity.id) == id
1020 test "returns 404 error for a wrong id", %{conn: conn} do
1023 |> put_req_header("content-type", "application/json")
1024 |> post("/api/v1/statuses/1/unfavourite")
1026 assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
1030 describe "pinned statuses" do
1031 setup do: oauth_access(["write:accounts"])
1033 setup %{user: user} do
1034 {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
1036 %{activity: activity}
1039 setup do: clear_config([:instance, :max_pinned_statuses], 1)
1041 test "pin status", %{conn: conn, user: user, activity: activity} do
1042 id_str = to_string(activity.id)
1044 assert %{"id" => ^id_str, "pinned" => true} =
1046 |> put_req_header("content-type", "application/json")
1047 |> post("/api/v1/statuses/#{activity.id}/pin")
1048 |> json_response_and_validate_schema(200)
1050 assert [%{"id" => ^id_str, "pinned" => true}] =
1052 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
1053 |> json_response_and_validate_schema(200)
1056 test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
1057 {:ok, dm} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
1061 |> put_req_header("content-type", "application/json")
1062 |> post("/api/v1/statuses/#{dm.id}/pin")
1064 assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not pin"}
1067 test "unpin status", %{conn: conn, user: user, activity: activity} do
1068 {:ok, _} = CommonAPI.pin(activity.id, user)
1069 user = refresh_record(user)
1071 id_str = to_string(activity.id)
1073 assert %{"id" => ^id_str, "pinned" => false} =
1075 |> assign(:user, user)
1076 |> post("/api/v1/statuses/#{activity.id}/unpin")
1077 |> json_response_and_validate_schema(200)
1081 |> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
1082 |> json_response_and_validate_schema(200)
1085 test "/unpin: returns 400 error when activity is not exist", %{conn: conn} do
1088 |> put_req_header("content-type", "application/json")
1089 |> post("/api/v1/statuses/1/unpin")
1091 assert json_response_and_validate_schema(conn, 400) == %{"error" => "Could not unpin"}
1094 test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
1095 {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
1097 id_str_one = to_string(activity_one.id)
1099 assert %{"id" => ^id_str_one, "pinned" => true} =
1101 |> put_req_header("content-type", "application/json")
1102 |> post("/api/v1/statuses/#{id_str_one}/pin")
1103 |> json_response_and_validate_schema(200)
1105 user = refresh_record(user)
1107 assert %{"error" => "You have already pinned the maximum number of statuses"} =
1109 |> assign(:user, user)
1110 |> post("/api/v1/statuses/#{activity_two.id}/pin")
1111 |> json_response_and_validate_schema(400)
1117 Config.put([:rich_media, :enabled], true)
1119 oauth_access(["read:statuses"])
1122 test "returns rich-media card", %{conn: conn, user: user} do
1123 Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
1125 {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp"})
1128 "image" => "http://ia.media-imdb.com/images/rock.jpg",
1129 "provider_name" => "example.com",
1130 "provider_url" => "https://example.com",
1131 "title" => "The Rock",
1133 "url" => "https://example.com/ogp",
1135 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
1138 "image" => "http://ia.media-imdb.com/images/rock.jpg",
1139 "title" => "The Rock",
1140 "type" => "video.movie",
1141 "url" => "https://example.com/ogp",
1143 "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
1150 |> get("/api/v1/statuses/#{activity.id}/card")
1151 |> json_response_and_validate_schema(200)
1153 assert response == card_data
1155 # works with private posts
1157 CommonAPI.post(user, %{status: "https://example.com/ogp", visibility: "direct"})
1161 |> get("/api/v1/statuses/#{activity.id}/card")
1162 |> json_response_and_validate_schema(200)
1164 assert response_two == card_data
1167 test "replaces missing description with an empty string", %{conn: conn, user: user} do
1168 Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
1170 {:ok, activity} = CommonAPI.post(user, %{status: "https://example.com/ogp-missing-data"})
1174 |> get("/api/v1/statuses/#{activity.id}/card")
1175 |> json_response_and_validate_schema(:ok)
1177 assert response == %{
1179 "title" => "Pleroma",
1180 "description" => "",
1182 "provider_name" => "example.com",
1183 "provider_url" => "https://example.com",
1184 "url" => "https://example.com/ogp-missing-data",
1187 "title" => "Pleroma",
1188 "type" => "website",
1189 "url" => "https://example.com/ogp-missing-data"
1197 bookmarks_uri = "/api/v1/bookmarks"
1199 %{conn: conn} = oauth_access(["write:bookmarks", "read:bookmarks"])
1200 author = insert(:user)
1202 {:ok, activity1} = CommonAPI.post(author, %{status: "heweoo?"})
1203 {:ok, activity2} = CommonAPI.post(author, %{status: "heweoo!"})
1207 |> put_req_header("content-type", "application/json")
1208 |> post("/api/v1/statuses/#{activity1.id}/bookmark")
1210 assert json_response_and_validate_schema(response1, 200)["bookmarked"] == true
1214 |> put_req_header("content-type", "application/json")
1215 |> post("/api/v1/statuses/#{activity2.id}/bookmark")
1217 assert json_response_and_validate_schema(response2, 200)["bookmarked"] == true
1219 bookmarks = get(conn, bookmarks_uri)
1222 json_response_and_validate_schema(response2, 200),
1223 json_response_and_validate_schema(response1, 200)
1225 json_response_and_validate_schema(bookmarks, 200)
1229 |> put_req_header("content-type", "application/json")
1230 |> post("/api/v1/statuses/#{activity1.id}/unbookmark")
1232 assert json_response_and_validate_schema(response1, 200)["bookmarked"] == false
1234 bookmarks = get(conn, bookmarks_uri)
1236 assert [json_response_and_validate_schema(response2, 200)] ==
1237 json_response_and_validate_schema(bookmarks, 200)
1240 describe "conversation muting" do
1241 setup do: oauth_access(["write:mutes"])
1244 post_user = insert(:user)
1245 {:ok, activity} = CommonAPI.post(post_user, %{status: "HIE"})
1246 %{activity: activity}
1249 test "mute conversation", %{conn: conn, activity: activity} do
1250 id_str = to_string(activity.id)
1252 assert %{"id" => ^id_str, "muted" => true} =
1254 |> put_req_header("content-type", "application/json")
1255 |> post("/api/v1/statuses/#{activity.id}/mute")
1256 |> json_response_and_validate_schema(200)
1259 test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do
1260 {:ok, _} = CommonAPI.add_mute(user, activity)
1264 |> put_req_header("content-type", "application/json")
1265 |> post("/api/v1/statuses/#{activity.id}/mute")
1267 assert json_response_and_validate_schema(conn, 400) == %{
1268 "error" => "conversation is already muted"
1272 test "unmute conversation", %{conn: conn, user: user, activity: activity} do
1273 {:ok, _} = CommonAPI.add_mute(user, activity)
1275 id_str = to_string(activity.id)
1277 assert %{"id" => ^id_str, "muted" => false} =
1279 # |> assign(:user, user)
1280 |> post("/api/v1/statuses/#{activity.id}/unmute")
1281 |> json_response_and_validate_schema(200)
1285 test "Repeated posts that are replies incorrectly have in_reply_to_id null", %{conn: conn} do
1286 user1 = insert(:user)
1287 user2 = insert(:user)
1288 user3 = insert(:user)
1290 {:ok, replied_to} = CommonAPI.post(user1, %{status: "cofe"})
1292 # Reply to status from another user
1295 |> assign(:user, user2)
1296 |> assign(:token, insert(:oauth_token, user: user2, scopes: ["write:statuses"]))
1297 |> put_req_header("content-type", "application/json")
1298 |> post("/api/v1/statuses", %{"status" => "xD", "in_reply_to_id" => replied_to.id})
1300 assert %{"content" => "xD", "id" => id} = json_response_and_validate_schema(conn1, 200)
1302 activity = Activity.get_by_id_with_object(id)
1304 assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"]
1305 assert Activity.get_in_reply_to_activity(activity).id == replied_to.id
1307 # Reblog from the third user
1310 |> assign(:user, user3)
1311 |> assign(:token, insert(:oauth_token, user: user3, scopes: ["write:statuses"]))
1312 |> put_req_header("content-type", "application/json")
1313 |> post("/api/v1/statuses/#{activity.id}/reblog")
1315 assert %{"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 1}} =
1316 json_response_and_validate_schema(conn2, 200)
1318 assert to_string(activity.id) == id
1320 # Getting third user status
1323 |> assign(:user, user3)
1324 |> assign(:token, insert(:oauth_token, user: user3, scopes: ["read:statuses"]))
1325 |> get("api/v1/timelines/home")
1327 [reblogged_activity] = json_response(conn3, 200)
1329 assert reblogged_activity["reblog"]["in_reply_to_id"] == replied_to.id
1331 replied_to_user = User.get_by_ap_id(replied_to.data["actor"])
1332 assert reblogged_activity["reblog"]["in_reply_to_account_id"] == replied_to_user.id
1335 describe "GET /api/v1/statuses/:id/favourited_by" do
1336 setup do: oauth_access(["read:accounts"])
1338 setup %{user: user} do
1339 {:ok, activity} = CommonAPI.post(user, %{status: "test"})
1341 %{activity: activity}
1344 test "returns users who have favorited the status", %{conn: conn, activity: activity} do
1345 other_user = insert(:user)
1346 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
1350 |> get("/api/v1/statuses/#{activity.id}/favourited_by")
1351 |> json_response_and_validate_schema(:ok)
1353 [%{"id" => id}] = response
1355 assert id == other_user.id
1358 test "returns empty array when status has not been favorited yet", %{
1364 |> get("/api/v1/statuses/#{activity.id}/favourited_by")
1365 |> json_response_and_validate_schema(:ok)
1367 assert Enum.empty?(response)
1370 test "does not return users who have favorited the status but are blocked", %{
1371 conn: %{assigns: %{user: user}} = conn,
1374 other_user = insert(:user)
1375 {:ok, _user_relationship} = User.block(user, other_user)
1377 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
1381 |> get("/api/v1/statuses/#{activity.id}/favourited_by")
1382 |> json_response_and_validate_schema(:ok)
1384 assert Enum.empty?(response)
1387 test "does not fail on an unauthenticated request", %{activity: activity} do
1388 other_user = insert(:user)
1389 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
1393 |> get("/api/v1/statuses/#{activity.id}/favourited_by")
1394 |> json_response_and_validate_schema(:ok)
1396 [%{"id" => id}] = response
1397 assert id == other_user.id
1400 test "requires authentication for private posts", %{user: user} do
1401 other_user = insert(:user)
1404 CommonAPI.post(user, %{
1405 status: "@#{other_user.nickname} wanna get some #cofe together?",
1406 visibility: "direct"
1409 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
1411 favourited_by_url = "/api/v1/statuses/#{activity.id}/favourited_by"
1414 |> get(favourited_by_url)
1415 |> json_response_and_validate_schema(404)
1419 |> assign(:user, other_user)
1420 |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))
1423 |> assign(:token, nil)
1424 |> get(favourited_by_url)
1425 |> json_response_and_validate_schema(404)
1429 |> get(favourited_by_url)
1430 |> json_response_and_validate_schema(200)
1432 [%{"id" => id}] = response
1433 assert id == other_user.id
1436 test "returns empty array when :show_reactions is disabled", %{conn: conn, activity: activity} do
1437 clear_config([:instance, :show_reactions], false)
1439 other_user = insert(:user)
1440 {:ok, _} = CommonAPI.favorite(other_user, activity.id)
1444 |> get("/api/v1/statuses/#{activity.id}/favourited_by")
1445 |> json_response_and_validate_schema(:ok)
1447 assert Enum.empty?(response)
1451 describe "GET /api/v1/statuses/:id/reblogged_by" do
1452 setup do: oauth_access(["read:accounts"])
1454 setup %{user: user} do
1455 {:ok, activity} = CommonAPI.post(user, %{status: "test"})
1457 %{activity: activity}
1460 test "returns users who have reblogged the status", %{conn: conn, activity: activity} do
1461 other_user = insert(:user)
1462 {:ok, _} = CommonAPI.repeat(activity.id, other_user)
1466 |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
1467 |> json_response_and_validate_schema(:ok)
1469 [%{"id" => id}] = response
1471 assert id == other_user.id
1474 test "returns empty array when status has not been reblogged yet", %{
1480 |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
1481 |> json_response_and_validate_schema(:ok)
1483 assert Enum.empty?(response)
1486 test "does not return users who have reblogged the status but are blocked", %{
1487 conn: %{assigns: %{user: user}} = conn,
1490 other_user = insert(:user)
1491 {:ok, _user_relationship} = User.block(user, other_user)
1493 {:ok, _} = CommonAPI.repeat(activity.id, other_user)
1497 |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
1498 |> json_response_and_validate_schema(:ok)
1500 assert Enum.empty?(response)
1503 test "does not return users who have reblogged the status privately", %{
1506 other_user = insert(:user)
1507 {:ok, activity} = CommonAPI.post(other_user, %{status: "my secret post"})
1509 {:ok, _} = CommonAPI.repeat(activity.id, other_user, %{visibility: "private"})
1513 |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
1514 |> json_response_and_validate_schema(:ok)
1516 assert Enum.empty?(response)
1519 test "does not fail on an unauthenticated request", %{activity: activity} do
1520 other_user = insert(:user)
1521 {:ok, _} = CommonAPI.repeat(activity.id, other_user)
1525 |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
1526 |> json_response_and_validate_schema(:ok)
1528 [%{"id" => id}] = response
1529 assert id == other_user.id
1532 test "requires authentication for private posts", %{user: user} do
1533 other_user = insert(:user)
1536 CommonAPI.post(user, %{
1537 status: "@#{other_user.nickname} wanna get some #cofe together?",
1538 visibility: "direct"
1542 |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
1543 |> json_response_and_validate_schema(404)
1547 |> assign(:user, other_user)
1548 |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:accounts"]))
1549 |> get("/api/v1/statuses/#{activity.id}/reblogged_by")
1550 |> json_response_and_validate_schema(200)
1552 assert [] == response
1557 user = insert(:user)
1559 {:ok, %{id: id1}} = CommonAPI.post(user, %{status: "1"})
1560 {:ok, %{id: id2}} = CommonAPI.post(user, %{status: "2", in_reply_to_status_id: id1})
1561 {:ok, %{id: id3}} = CommonAPI.post(user, %{status: "3", in_reply_to_status_id: id2})
1562 {:ok, %{id: id4}} = CommonAPI.post(user, %{status: "4", in_reply_to_status_id: id3})
1563 {:ok, %{id: id5}} = CommonAPI.post(user, %{status: "5", in_reply_to_status_id: id4})
1567 |> get("/api/v1/statuses/#{id3}/context")
1568 |> json_response_and_validate_schema(:ok)
1571 "ancestors" => [%{"id" => ^id1}, %{"id" => ^id2}],
1572 "descendants" => [%{"id" => ^id4}, %{"id" => ^id5}]
1576 test "favorites paginate correctly" do
1577 %{user: user, conn: conn} = oauth_access(["read:favourites"])
1578 other_user = insert(:user)
1579 {:ok, first_post} = CommonAPI.post(other_user, %{status: "bla"})
1580 {:ok, second_post} = CommonAPI.post(other_user, %{status: "bla"})
1581 {:ok, third_post} = CommonAPI.post(other_user, %{status: "bla"})
1583 {:ok, _first_favorite} = CommonAPI.favorite(user, third_post.id)
1584 {:ok, _second_favorite} = CommonAPI.favorite(user, first_post.id)
1585 {:ok, third_favorite} = CommonAPI.favorite(user, second_post.id)
1589 |> get("/api/v1/favourites?limit=1")
1591 assert [%{"id" => post_id}] = json_response_and_validate_schema(result, 200)
1592 assert post_id == second_post.id
1594 # Using the header for pagination works correctly
1595 [next, _] = get_resp_header(result, "link") |> hd() |> String.split(", ")
1596 [_, max_id] = Regex.run(~r/max_id=([^&]+)/, next)
1598 assert max_id == third_favorite.id
1602 |> get("/api/v1/favourites?max_id=#{max_id}")
1604 assert [%{"id" => first_post_id}, %{"id" => third_post_id}] =
1605 json_response_and_validate_schema(result, 200)
1607 assert first_post_id == first_post.id
1608 assert third_post_id == third_post.id
1611 test "returns the favorites of a user" do
1612 %{user: user, conn: conn} = oauth_access(["read:favourites"])
1613 other_user = insert(:user)
1615 {:ok, _} = CommonAPI.post(other_user, %{status: "bla"})
1616 {:ok, activity} = CommonAPI.post(other_user, %{status: "trees are happy"})
1618 {:ok, last_like} = CommonAPI.favorite(user, activity.id)
1620 first_conn = get(conn, "/api/v1/favourites")
1622 assert [status] = json_response_and_validate_schema(first_conn, 200)
1623 assert status["id"] == to_string(activity.id)
1625 assert [{"link", _link_header}] =
1626 Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
1628 # Honours query params
1629 {:ok, second_activity} =
1630 CommonAPI.post(other_user, %{
1631 status: "Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
1634 {:ok, _} = CommonAPI.favorite(user, second_activity.id)
1636 second_conn = get(conn, "/api/v1/favourites?since_id=#{last_like.id}")
1638 assert [second_status] = json_response_and_validate_schema(second_conn, 200)
1639 assert second_status["id"] == to_string(second_activity.id)
1641 third_conn = get(conn, "/api/v1/favourites?limit=0")
1643 assert [] = json_response_and_validate_schema(third_conn, 200)
1646 test "expires_at is nil for another user" do
1647 %{conn: conn, user: user} = oauth_access(["read:statuses"])
1648 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", expires_in: 1_000_000})
1652 |> ActivityExpiration.get_by_activity_id()
1653 |> Map.get(:scheduled_at)
1654 |> NaiveDateTime.to_iso8601()
1656 assert %{"pleroma" => %{"expires_at" => ^expires_at}} =
1658 |> get("/api/v1/statuses/#{activity.id}")
1659 |> json_response_and_validate_schema(:ok)
1661 %{conn: conn} = oauth_access(["read:statuses"])
1663 assert %{"pleroma" => %{"expires_at" => nil}} =
1665 |> get("/api/v1/statuses/#{activity.id}")
1666 |> json_response_and_validate_schema(:ok)