Merge branch '114_email_confirmation' 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 bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
24 inserted_at: ~N[2017-08-15 15:47:06.597036]
25 })
26
27 expected = %{
28 id: to_string(user.id),
29 username: "shp",
30 acct: user.nickname,
31 display_name: user.name,
32 locked: false,
33 created_at: "2017-08-15T15:47:06.000Z",
34 followers_count: 3,
35 following_count: 0,
36 statuses_count: 5,
37 note: "<span>valid html</span>",
38 url: user.ap_id,
39 avatar: "http://localhost:4001/images/avi.png",
40 avatar_static: "http://localhost:4001/images/avi.png",
41 header: "http://localhost:4001/images/banner.png",
42 header_static: "http://localhost:4001/images/banner.png",
43 emojis: [
44 %{
45 "static_url" => "/file.png",
46 "url" => "/file.png",
47 "shortcode" => "karjalanpiirakka",
48 "visible_in_picker" => false
49 }
50 ],
51 fields: [],
52 bot: false,
53 source: %{
54 note: "",
55 privacy: "public",
56 sensitive: false
57 },
58 pleroma: %{
59 confirmation_pending: false,
60 tags: []
61 }
62 }
63
64 assert expected == AccountView.render("account.json", %{user: user})
65 end
66
67 test "Represent a Service(bot) account" do
68 user =
69 insert(:user, %{
70 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
71 nickname: "shp@shitposter.club",
72 inserted_at: ~N[2017-08-15 15:47:06.597036]
73 })
74
75 expected = %{
76 id: to_string(user.id),
77 username: "shp",
78 acct: user.nickname,
79 display_name: user.name,
80 locked: false,
81 created_at: "2017-08-15T15:47:06.000Z",
82 followers_count: 3,
83 following_count: 0,
84 statuses_count: 5,
85 note: user.bio,
86 url: user.ap_id,
87 avatar: "http://localhost:4001/images/avi.png",
88 avatar_static: "http://localhost:4001/images/avi.png",
89 header: "http://localhost:4001/images/banner.png",
90 header_static: "http://localhost:4001/images/banner.png",
91 emojis: [],
92 fields: [],
93 bot: true,
94 source: %{
95 note: "",
96 privacy: "public",
97 sensitive: false
98 },
99 pleroma: %{
100 confirmation_pending: false,
101 tags: []
102 }
103 }
104
105 assert expected == AccountView.render("account.json", %{user: user})
106 end
107
108 test "Represent a smaller mention" do
109 user = insert(:user)
110
111 expected = %{
112 id: to_string(user.id),
113 acct: user.nickname,
114 username: user.nickname,
115 url: user.ap_id
116 }
117
118 assert expected == AccountView.render("mention.json", %{user: user})
119 end
120
121 test "represent a relationship" do
122 user = insert(:user)
123 other_user = insert(:user)
124
125 {:ok, user} = User.follow(user, other_user)
126 {:ok, user} = User.block(user, other_user)
127
128 expected = %{
129 id: to_string(other_user.id),
130 following: false,
131 followed_by: false,
132 blocking: true,
133 muting: false,
134 muting_notifications: false,
135 requested: false,
136 domain_blocking: false,
137 showing_reblogs: false,
138 endorsed: false
139 }
140
141 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
142 end
143 end