Merge branch 'fix/normalize-file-extension' into 'develop'
[akkoma] / test / web / mastodon_api / account_view_test.exs
1 defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
2 use Pleroma.DataCase
3 import Pleroma.Factory
4 alias Pleroma.Web.MastodonAPI.AccountView
5 alias Pleroma.User
6
7 test "Represent a user account" do
8 source_data = %{
9 "tag" => [
10 %{
11 "type" => "Emoji",
12 "icon" => %{"url" => "/file.png"},
13 "name" => ":karjalanpiirakka:"
14 }
15 ]
16 }
17
18 user =
19 insert(:user, %{
20 info: %{"note_count" => 5, "follower_count" => 3, "source_data" => source_data},
21 nickname: "shp@shitposter.club",
22 name: ":karjalanpiirakka: shp",
23 inserted_at: ~N[2017-08-15 15:47:06.597036]
24 })
25
26 expected = %{
27 id: to_string(user.id),
28 username: "shp",
29 acct: user.nickname,
30 display_name: user.name,
31 locked: false,
32 created_at: "2017-08-15T15:47:06.000Z",
33 followers_count: 3,
34 following_count: 0,
35 statuses_count: 5,
36 note: user.bio,
37 url: user.ap_id,
38 avatar: "http://localhost:4001/images/avi.png",
39 avatar_static: "http://localhost:4001/images/avi.png",
40 header: "http://localhost:4001/images/banner.png",
41 header_static: "http://localhost:4001/images/banner.png",
42 emojis: [
43 %{
44 "static_url" => "/file.png",
45 "url" => "/file.png",
46 "shortcode" => "karjalanpiirakka",
47 "visible_in_picker" => false
48 }
49 ],
50 fields: [],
51 source: %{
52 note: "",
53 privacy: "public",
54 sensitive: "false"
55 }
56 }
57
58 assert expected == AccountView.render("account.json", %{user: user})
59 end
60
61 test "Represent a smaller mention" do
62 user = insert(:user)
63
64 expected = %{
65 id: to_string(user.id),
66 acct: user.nickname,
67 username: user.nickname,
68 url: user.ap_id
69 }
70
71 assert expected == AccountView.render("mention.json", %{user: user})
72 end
73
74 test "represent a relationship" do
75 user = insert(:user)
76 other_user = insert(:user)
77
78 {:ok, user} = User.follow(user, other_user)
79 {:ok, user} = User.block(user, other_user)
80
81 expected = %{
82 id: to_string(other_user.id),
83 following: false,
84 followed_by: false,
85 blocking: true,
86 muting: false,
87 requested: false,
88 domain_blocking: false
89 }
90
91 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
92 end
93 end