add visibility check on quote (#178)
[akkoma] / test / pleroma / web / mastodon_api / views / status_view_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Activity
9 alias Pleroma.Bookmark
10 alias Pleroma.Conversation.Participation
11 alias Pleroma.HTML
12 alias Pleroma.Object
13 alias Pleroma.Repo
14 alias Pleroma.User
15 alias Pleroma.UserRelationship
16 alias Pleroma.Web.CommonAPI
17 alias Pleroma.Web.MastodonAPI.AccountView
18 alias Pleroma.Web.MastodonAPI.StatusView
19
20 import Pleroma.Factory
21 import Tesla.Mock
22 import OpenApiSpex.TestAssertions
23
24 setup do
25 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
26 :ok
27 end
28
29 test "has an emoji reaction list" do
30 user = insert(:user)
31 other_user = insert(:user)
32 third_user = insert(:user)
33 {:ok, activity} = CommonAPI.post(user, %{status: "dae cofe??"})
34
35 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "☕")
36 {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, ":dinosaur:")
37 {:ok, _} = CommonAPI.react_with_emoji(activity.id, third_user, "🍵")
38 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
39 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, ":dinosaur:")
40
41 activity = Repo.get(Activity, activity.id)
42 status = StatusView.render("show.json", activity: activity)
43
44 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
45
46 assert status[:pleroma][:emoji_reactions] == [
47 %{name: "☕", count: 2, me: false, url: nil, account_ids: [other_user.id, user.id]},
48 %{
49 count: 2,
50 me: false,
51 name: "dinosaur",
52 url: "http://localhost:4001/emoji/dino walking.gif",
53 account_ids: [other_user.id, user.id]
54 },
55 %{name: "🍵", count: 1, me: false, url: nil, account_ids: [third_user.id]}
56 ]
57
58 status = StatusView.render("show.json", activity: activity, for: user)
59
60 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
61
62 assert status[:pleroma][:emoji_reactions] == [
63 %{name: "☕", count: 2, me: true, url: nil, account_ids: [other_user.id, user.id]},
64 %{
65 count: 2,
66 me: true,
67 name: "dinosaur",
68 url: "http://localhost:4001/emoji/dino walking.gif",
69 account_ids: [other_user.id, user.id]
70 },
71 %{name: "🍵", count: 1, me: false, url: nil, account_ids: [third_user.id]}
72 ]
73 end
74
75 test "works correctly with badly formatted emojis" do
76 user = insert(:user)
77 {:ok, activity} = CommonAPI.post(user, %{status: "yo"})
78
79 activity
80 |> Object.normalize(fetch: false)
81 |> Object.update_data(%{"reactions" => %{"☕" => [user.ap_id], "x" => 1}})
82
83 activity = Activity.get_by_id(activity.id)
84 status = StatusView.render("show.json", activity: activity, for: user)
85
86 assert status[:pleroma][:emoji_reactions] == [
87 %{name: "☕", count: 1, me: true, url: nil, account_ids: [user.id]}
88 ]
89 end
90
91 test "doesn't show reactions from muted and blocked users" do
92 user = insert(:user)
93 other_user = insert(:user)
94 third_user = insert(:user)
95
96 {:ok, activity} = CommonAPI.post(user, %{status: "dae cofe??"})
97
98 {:ok, _} = User.mute(user, other_user)
99 {:ok, _} = User.block(other_user, third_user)
100
101 {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
102
103 activity = Repo.get(Activity, activity.id)
104 status = StatusView.render("show.json", activity: activity)
105
106 assert status[:pleroma][:emoji_reactions] == [
107 %{name: "☕", count: 1, me: false, url: nil, account_ids: [other_user.id]}
108 ]
109
110 status = StatusView.render("show.json", activity: activity, for: user)
111
112 assert status[:pleroma][:emoji_reactions] == []
113
114 {:ok, _} = CommonAPI.react_with_emoji(activity.id, third_user, "☕")
115
116 status = StatusView.render("show.json", activity: activity)
117
118 assert status[:pleroma][:emoji_reactions] == [
119 %{
120 name: "☕",
121 count: 2,
122 me: false,
123 url: nil,
124 account_ids: [third_user.id, other_user.id]
125 }
126 ]
127
128 status = StatusView.render("show.json", activity: activity, for: user)
129
130 assert status[:pleroma][:emoji_reactions] == [
131 %{name: "☕", count: 1, me: false, url: nil, account_ids: [third_user.id]}
132 ]
133
134 status = StatusView.render("show.json", activity: activity, for: other_user)
135
136 assert status[:pleroma][:emoji_reactions] == [
137 %{name: "☕", count: 1, me: true, url: nil, account_ids: [other_user.id]}
138 ]
139 end
140
141 test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
142 user = insert(:user)
143
144 {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
145 [participation] = Participation.for_user(user)
146
147 status =
148 StatusView.render("show.json",
149 activity: activity,
150 with_direct_conversation_id: true,
151 for: user
152 )
153
154 assert status[:pleroma][:direct_conversation_id] == participation.id
155
156 status = StatusView.render("show.json", activity: activity, for: user)
157 assert status[:pleroma][:direct_conversation_id] == nil
158 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
159 end
160
161 test "returns the direct conversation id when given the `direct_conversation_id` option" do
162 user = insert(:user)
163
164 {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
165 [participation] = Participation.for_user(user)
166
167 status =
168 StatusView.render("show.json",
169 activity: activity,
170 direct_conversation_id: participation.id,
171 for: user
172 )
173
174 assert status[:pleroma][:direct_conversation_id] == participation.id
175 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
176 end
177
178 test "returns a temporary ap_id based user for activities missing db users" do
179 user = insert(:user)
180
181 {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
182
183 Repo.delete(user)
184 User.invalidate_cache(user)
185
186 finger_url =
187 "https://localhost/.well-known/webfinger?resource=acct:#{user.nickname}@localhost"
188
189 Tesla.Mock.mock_global(fn
190 %{method: :get, url: "http://localhost/.well-known/host-meta"} ->
191 %Tesla.Env{status: 404, body: ""}
192
193 %{method: :get, url: "https://localhost/.well-known/host-meta"} ->
194 %Tesla.Env{status: 404, body: ""}
195
196 %{
197 method: :get,
198 url: ^finger_url
199 } ->
200 %Tesla.Env{status: 404, body: ""}
201 end)
202
203 %{account: ms_user} = StatusView.render("show.json", activity: activity)
204
205 assert ms_user.acct == "erroruser@example.com"
206 end
207
208 test "tries to get a user by nickname if fetching by ap_id doesn't work" do
209 user = insert(:user)
210
211 {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})
212
213 {:ok, user} =
214 user
215 |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"})
216 |> Repo.update()
217
218 User.invalidate_cache(user)
219
220 result = StatusView.render("show.json", activity: activity)
221
222 assert result[:account][:id] == to_string(user.id)
223 assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
224 end
225
226 test "a note with null content" do
227 note = insert(:note_activity)
228 note_object = Object.normalize(note, fetch: false)
229
230 data =
231 note_object.data
232 |> Map.put("content", nil)
233
234 Object.change(note_object, %{data: data})
235 |> Object.update_and_set_cache()
236
237 User.get_cached_by_ap_id(note.data["actor"])
238
239 status = StatusView.render("show.json", %{activity: note})
240
241 assert status.content == ""
242 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
243 end
244
245 test "a note activity" do
246 note = insert(:note_activity)
247 object_data = Object.normalize(note, fetch: false).data
248 user = User.get_cached_by_ap_id(note.data["actor"])
249
250 convo_id = :erlang.crc32(object_data["context"]) |> Bitwise.band(Bitwise.bnot(0x8000_0000))
251
252 status = StatusView.render("show.json", %{activity: note})
253
254 created_at =
255 (object_data["published"] || "")
256 |> String.replace(~r/\.\d+Z/, ".000Z")
257
258 expected = %{
259 id: to_string(note.id),
260 uri: object_data["id"],
261 url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note),
262 account: AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
263 in_reply_to_id: nil,
264 in_reply_to_account_id: nil,
265 card: nil,
266 reblog: nil,
267 content: HTML.filter_tags(object_data["content"]),
268 text: nil,
269 created_at: created_at,
270 reblogs_count: 0,
271 replies_count: 0,
272 favourites_count: 0,
273 reblogged: false,
274 bookmarked: false,
275 favourited: false,
276 muted: false,
277 pinned: false,
278 sensitive: false,
279 poll: nil,
280 spoiler_text: HTML.filter_tags(object_data["summary"]),
281 visibility: "public",
282 media_attachments: [],
283 emoji_reactions: [],
284 mentions: [],
285 tags: [
286 %{
287 name: "#{hd(object_data["tag"])}",
288 url: "http://localhost:4001/tag/#{hd(object_data["tag"])}"
289 }
290 ],
291 application: nil,
292 language: nil,
293 emojis: [
294 %{
295 shortcode: "2hu",
296 url: "corndog.png",
297 static_url: "corndog.png",
298 visible_in_picker: false
299 }
300 ],
301 pleroma: %{
302 local: true,
303 conversation_id: convo_id,
304 context: object_data["context"],
305 in_reply_to_account_acct: nil,
306 content: %{"text/plain" => HTML.strip_tags(object_data["content"])},
307 spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},
308 expires_at: nil,
309 direct_conversation_id: nil,
310 thread_muted: false,
311 emoji_reactions: [],
312 parent_visible: false,
313 pinned_at: nil
314 },
315 akkoma: %{
316 source: HTML.filter_tags(object_data["content"])
317 },
318 quote_id: nil,
319 quote: nil
320 }
321
322 assert status == expected
323 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
324 end
325
326 test "tells if the message is muted for some reason" do
327 user = insert(:user)
328 other_user = insert(:user)
329
330 {:ok, _user_relationships} = User.mute(user, other_user)
331
332 {:ok, activity} = CommonAPI.post(other_user, %{status: "test"})
333
334 relationships_opt = UserRelationship.view_relationships_option(user, [other_user])
335
336 opts = %{activity: activity}
337 status = StatusView.render("show.json", opts)
338 assert status.muted == false
339 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
340
341 status = StatusView.render("show.json", Map.put(opts, :relationships, relationships_opt))
342 assert status.muted == false
343
344 for_opts = %{activity: activity, for: user}
345 status = StatusView.render("show.json", for_opts)
346 assert status.muted == true
347
348 status = StatusView.render("show.json", Map.put(for_opts, :relationships, relationships_opt))
349 assert status.muted == true
350 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
351 end
352
353 test "tells if the message is thread muted" do
354 user = insert(:user)
355 other_user = insert(:user)
356
357 {:ok, _user_relationships} = User.mute(user, other_user)
358
359 {:ok, activity} = CommonAPI.post(other_user, %{status: "test"})
360 status = StatusView.render("show.json", %{activity: activity, for: user})
361
362 assert status.pleroma.thread_muted == false
363
364 {:ok, activity} = CommonAPI.add_mute(user, activity)
365
366 status = StatusView.render("show.json", %{activity: activity, for: user})
367
368 assert status.pleroma.thread_muted == true
369 end
370
371 test "tells if the status is bookmarked" do
372 user = insert(:user)
373
374 {:ok, activity} = CommonAPI.post(user, %{status: "Cute girls doing cute things"})
375 status = StatusView.render("show.json", %{activity: activity})
376
377 assert status.bookmarked == false
378
379 status = StatusView.render("show.json", %{activity: activity, for: user})
380
381 assert status.bookmarked == false
382
383 {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
384
385 activity = Activity.get_by_id_with_object(activity.id)
386
387 status = StatusView.render("show.json", %{activity: activity, for: user})
388
389 assert status.bookmarked == true
390 end
391
392 test "a reply" do
393 note = insert(:note_activity)
394 user = insert(:user)
395
396 {:ok, activity} = CommonAPI.post(user, %{status: "he", in_reply_to_status_id: note.id})
397
398 status = StatusView.render("show.json", %{activity: activity})
399
400 assert status.in_reply_to_id == to_string(note.id)
401
402 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
403
404 assert status.in_reply_to_id == to_string(note.id)
405 end
406
407 test "a quote" do
408 note = insert(:note_activity)
409 user = insert(:user)
410
411 {:ok, activity} = CommonAPI.post(user, %{status: "hehe", quote_id: note.id})
412
413 status = StatusView.render("show.json", %{activity: activity})
414
415 assert status.quote_id == to_string(note.id)
416
417 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
418
419 assert status.quote_id == to_string(note.id)
420 end
421
422 test "a quote that we can't resolve" do
423 note = insert(:note_activity, quoteUri: "oopsie")
424
425 status = StatusView.render("show.json", %{activity: note})
426
427 assert is_nil(status.quote_id)
428 assert is_nil(status.quote)
429 end
430
431 test "a quote from a user we block" do
432 user = insert(:user)
433 other_user = insert(:user)
434 blocked_user = insert(:user)
435
436 {:ok, _relationship} = User.block(user, blocked_user)
437
438 {:ok, activity} = CommonAPI.post(blocked_user, %{status: ":< i am ANGERY"})
439 {:ok, quote_activity} = CommonAPI.post(other_user, %{status: "hehe", quote_id: activity.id})
440
441 status = StatusView.render("show.json", %{activity: quote_activity, for: user})
442 assert is_nil(status.quote)
443 end
444
445 test "a quote from a user we mute" do
446 user = insert(:user)
447 other_user = insert(:user)
448 blocked_user = insert(:user)
449
450 {:ok, _relationship} = User.mute(user, blocked_user)
451
452 {:ok, activity} = CommonAPI.post(blocked_user, %{status: ":< i am ANGERY"})
453 {:ok, quote_activity} = CommonAPI.post(other_user, %{status: "hehe", quote_id: activity.id})
454
455 status = StatusView.render("show.json", %{activity: quote_activity, for: user})
456 assert is_nil(status.quote)
457 end
458
459 test "contains mentions" do
460 user = insert(:user)
461 mentioned = insert(:user)
462
463 {:ok, activity} = CommonAPI.post(user, %{status: "hi @#{mentioned.nickname}"})
464
465 status = StatusView.render("show.json", %{activity: activity})
466
467 assert status.mentions ==
468 Enum.map([mentioned], fn u -> AccountView.render("mention.json", %{user: u}) end)
469
470 assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
471 end
472
473 test "create mentions from the 'to' field" do
474 %User{ap_id: recipient_ap_id} = insert(:user)
475 cc = insert_pair(:user) |> Enum.map(& &1.ap_id)
476
477 object =
478 insert(:note, %{
479 data: %{
480 "to" => [recipient_ap_id],
481 "cc" => cc
482 }
483 })
484
485 activity =
486 insert(:note_activity, %{
487 note: object,
488 recipients: [recipient_ap_id | cc]
489 })
490
491 assert length(activity.recipients) == 3
492
493 %{mentions: [mention] = mentions} = StatusView.render("show.json", %{activity: activity})
494
495 assert length(mentions) == 1
496 assert mention.url == recipient_ap_id
497 end
498
499 test "create mentions from the 'tag' field" do
500 recipient = insert(:user)
501 cc = insert_pair(:user) |> Enum.map(& &1.ap_id)
502
503 object =
504 insert(:note, %{
505 data: %{
506 "cc" => cc,
507 "tag" => [
508 %{
509 "href" => recipient.ap_id,
510 "name" => recipient.nickname,
511 "type" => "Mention"
512 },
513 %{
514 "href" => "https://example.com/search?tag=test",
515 "name" => "#test",
516 "type" => "Hashtag"
517 }
518 ]
519 }
520 })
521
522 activity =
523 insert(:note_activity, %{
524 note: object,
525 recipients: [recipient.ap_id | cc]
526 })
527
528 assert length(activity.recipients) == 3
529
530 %{mentions: [mention] = mentions} = StatusView.render("show.json", %{activity: activity})
531
532 assert length(mentions) == 1
533 assert mention.url == recipient.ap_id
534 end
535
536 test "attachments" do
537 object = %{
538 "type" => "Image",
539 "url" => [
540 %{
541 "mediaType" => "image/png",
542 "href" => "someurl",
543 "width" => 200,
544 "height" => 100
545 }
546 ],
547 "blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn",
548 "uuid" => 6
549 }
550
551 expected = %{
552 id: "1638338801",
553 type: "image",
554 url: "someurl",
555 remote_url: "someurl",
556 preview_url: "someurl",
557 text_url: "someurl",
558 description: nil,
559 pleroma: %{mime_type: "image/png"},
560 meta: %{original: %{width: 200, height: 100, aspect: 2}},
561 blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
562 }
563
564 api_spec = Pleroma.Web.ApiSpec.spec()
565
566 assert expected == StatusView.render("attachment.json", %{attachment: object})
567 assert_schema(expected, "Attachment", api_spec)
568
569 # If theres a "id", use that instead of the generated one
570 object = Map.put(object, "id", 2)
571 result = StatusView.render("attachment.json", %{attachment: object})
572
573 assert %{id: "2"} = result
574 assert_schema(result, "Attachment", api_spec)
575 end
576
577 test "put the url advertised in the Activity in to the url attribute" do
578 id = "https://wedistribute.org/wp-json/pterotype/v1/object/85810"
579 [activity] = Activity.search(nil, id)
580
581 status = StatusView.render("show.json", %{activity: activity})
582
583 assert status.uri == id
584 assert status.url == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
585 end
586
587 test "a reblog" do
588 user = insert(:user)
589 activity = insert(:note_activity)
590
591 {:ok, reblog} = CommonAPI.repeat(activity.id, user)
592
593 represented = StatusView.render("show.json", %{for: user, activity: reblog})
594
595 assert represented[:id] == to_string(reblog.id)
596 assert represented[:reblog][:id] == to_string(activity.id)
597 assert represented[:emojis] == []
598 assert_schema(represented, "Status", Pleroma.Web.ApiSpec.spec())
599 end
600
601 test "a peertube video" do
602 user = insert(:user)
603
604 {:ok, object} =
605 Pleroma.Object.Fetcher.fetch_object_from_id(
606 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
607 )
608
609 %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
610
611 represented = StatusView.render("show.json", %{for: user, activity: activity})
612
613 assert represented[:id] == to_string(activity.id)
614 assert length(represented[:media_attachments]) == 1
615 assert_schema(represented, "Status", Pleroma.Web.ApiSpec.spec())
616 end
617
618 test "funkwhale audio" do
619 user = insert(:user)
620
621 {:ok, object} =
622 Pleroma.Object.Fetcher.fetch_object_from_id(
623 "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871"
624 )
625
626 %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
627
628 represented = StatusView.render("show.json", %{for: user, activity: activity})
629
630 assert represented[:id] == to_string(activity.id)
631 assert length(represented[:media_attachments]) == 1
632 end
633
634 test "a Mobilizon event" do
635 user = insert(:user)
636
637 {:ok, object} =
638 Pleroma.Object.Fetcher.fetch_object_from_id(
639 "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
640 )
641
642 %Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
643
644 represented = StatusView.render("show.json", %{for: user, activity: activity})
645
646 assert represented[:id] == to_string(activity.id)
647
648 assert represented[:url] ==
649 "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
650
651 assert represented[:content] ==
652 "<p><a href=\"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39\">Mobilizon Launching Party</a></p><p>Mobilizon is now federated! 🎉</p><p></p><p>You can view this event from other instances if they are subscribed to mobilizon.org, and soon directly from Mastodon and Pleroma. It is possible that you may see some comments from other instances, including Mastodon ones, just below.</p><p></p><p>With a Mobilizon account on an instance, you may <strong>participate</strong> at events from other instances and <strong>add comments</strong> on events.</p><p></p><p>Of course, it&#39;s still <u>a work in progress</u>: if reports made from an instance on events and comments can be federated, you can&#39;t block people right now, and moderators actions are rather limited, but this <strong>will definitely get fixed over time</strong> until first stable version next year.</p><p></p><p>Anyway, if you want to come up with some feedback, head over to our forum or - if you feel you have technical skills and are familiar with it - on our Gitlab repository.</p><p></p><p>Also, to people that want to set Mobilizon themselves even though we really don&#39;t advise to do that for now, we have a little documentation but it&#39;s quite the early days and you&#39;ll probably need some help. No worries, you can chat with us on our Forum or though our Matrix channel.</p><p></p><p>Check our website for more informations and follow us on Twitter or Mastodon.</p>"
653 end
654
655 describe "build_tags/1" do
656 test "it returns a a dictionary tags" do
657 object_tags = [
658 "fediverse",
659 "mastodon",
660 "nextcloud",
661 %{
662 "href" => "https://kawen.space/users/lain",
663 "name" => "@lain@kawen.space",
664 "type" => "Mention"
665 }
666 ]
667
668 assert StatusView.build_tags(object_tags) == [
669 %{name: "fediverse", url: "http://localhost:4001/tag/fediverse"},
670 %{name: "mastodon", url: "http://localhost:4001/tag/mastodon"},
671 %{name: "nextcloud", url: "http://localhost:4001/tag/nextcloud"}
672 ]
673 end
674 end
675
676 describe "rich media cards" do
677 test "a rich media card without a site name renders correctly" do
678 page_url = "http://example.com"
679
680 card = %{
681 url: page_url,
682 image: page_url <> "/example.jpg",
683 title: "Example website"
684 }
685
686 %{provider_name: "example.com"} =
687 StatusView.render("card.json", %{page_url: page_url, rich_media: card})
688 end
689
690 test "a rich media card without a site name or image renders correctly" do
691 page_url = "http://example.com"
692
693 card = %{
694 url: page_url,
695 title: "Example website"
696 }
697
698 %{provider_name: "example.com"} =
699 StatusView.render("card.json", %{page_url: page_url, rich_media: card})
700 end
701
702 test "a rich media card without an image renders correctly" do
703 page_url = "http://example.com"
704
705 card = %{
706 url: page_url,
707 site_name: "Example site name",
708 title: "Example website"
709 }
710
711 %{provider_name: "example.com"} =
712 StatusView.render("card.json", %{page_url: page_url, rich_media: card})
713 end
714
715 test "a rich media card with all relevant data renders correctly" do
716 page_url = "http://example.com"
717
718 card = %{
719 url: page_url,
720 site_name: "Example site name",
721 title: "Example website",
722 image: page_url <> "/example.jpg",
723 description: "Example description"
724 }
725
726 %{provider_name: "example.com"} =
727 StatusView.render("card.json", %{page_url: page_url, rich_media: card})
728 end
729 end
730
731 test "does not embed a relationship in the account" do
732 user = insert(:user)
733 other_user = insert(:user)
734
735 {:ok, activity} =
736 CommonAPI.post(user, %{
737 status: "drink more water"
738 })
739
740 result = StatusView.render("show.json", %{activity: activity, for: other_user})
741
742 assert result[:account][:pleroma][:relationship] == %{}
743 assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
744 end
745
746 test "does not embed a relationship in the account in reposts" do
747 user = insert(:user)
748 other_user = insert(:user)
749
750 {:ok, activity} =
751 CommonAPI.post(user, %{
752 status: "˙˙ɐʎns"
753 })
754
755 {:ok, activity} = CommonAPI.repeat(activity.id, other_user)
756
757 result = StatusView.render("show.json", %{activity: activity, for: user})
758
759 assert result[:account][:pleroma][:relationship] == %{}
760 assert result[:reblog][:account][:pleroma][:relationship] == %{}
761 assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
762 end
763
764 test "visibility/list" do
765 user = insert(:user)
766
767 {:ok, list} = Pleroma.List.create("foo", user)
768
769 {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
770
771 status = StatusView.render("show.json", activity: activity)
772
773 assert status.visibility == "list"
774 end
775
776 test "has a field for parent visibility" do
777 user = insert(:user)
778 poster = insert(:user)
779
780 {:ok, invisible} = CommonAPI.post(poster, %{status: "hey", visibility: "private"})
781
782 {:ok, visible} =
783 CommonAPI.post(poster, %{status: "hey", visibility: "private", in_reply_to_id: invisible.id})
784
785 status = StatusView.render("show.json", activity: visible, for: user)
786 refute status.pleroma.parent_visible
787
788 status = StatusView.render("show.json", activity: visible, for: poster)
789 assert status.pleroma.parent_visible
790 end
791 end