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