account_view_test.exs 3.72 KB
Newer Older
lain's avatar
lain committed
1
2
3
4
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
  use Pleroma.DataCase
  import Pleroma.Factory
  alias Pleroma.Web.MastodonAPI.AccountView
Roger Braun's avatar
Roger Braun committed
5
  alias Pleroma.User
lain's avatar
lain committed
6
7

  test "Represent a user account" do
eal's avatar
eal committed
8
9
10
11
12
13
14
15
16
17
    source_data = %{
      "tag" => [
        %{
          "type" => "Emoji",
          "icon" => %{"url" => "/file.png"},
          "name" => ":karjalanpiirakka:"
        }
      ]
    }

lain's avatar
lain committed
18
19
    user =
      insert(:user, %{
20
        info: %{note_count: 5, follower_count: 3, source_data: source_data},
lain's avatar
lain committed
21
        nickname: "shp@shitposter.club",
eal's avatar
eal committed
22
        name: ":karjalanpiirakka: shp",
23
        bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
lain's avatar
lain committed
24
25
        inserted_at: ~N[2017-08-15 15:47:06.597036]
      })
lain's avatar
lain committed
26
27

    expected = %{
lain's avatar
lain committed
28
      id: to_string(user.id),
29
      username: "shp",
lain's avatar
lain committed
30
31
32
      acct: user.nickname,
      display_name: user.name,
      locked: false,
33
      created_at: "2017-08-15T15:47:06.000Z",
lain's avatar
lain committed
34
35
36
      followers_count: 3,
      following_count: 0,
      statuses_count: 5,
37
      note: "<span>valid html</span>",
lain's avatar
lain committed
38
      url: user.ap_id,
39
40
41
42
      avatar: "http://localhost:4001/images/avi.png",
      avatar_static: "http://localhost:4001/images/avi.png",
      header: "http://localhost:4001/images/banner.png",
      header_static: "http://localhost:4001/images/banner.png",
eal's avatar
eal committed
43
44
45
46
47
48
49
50
      emojis: [
        %{
          "static_url" => "/file.png",
          "url" => "/file.png",
          "shortcode" => "karjalanpiirakka",
          "visible_in_picker" => false
        }
      ],
Haelwenn's avatar
Haelwenn committed
51
      fields: [],
52
53
54
55
      bot: false,
      source: %{
        note: "",
        privacy: "public",
Martin's avatar
Martin committed
56
        sensitive: false
Ivan Tashkinov's avatar
Ivan Tashkinov committed
57
      },
58
59
60
61
      pleroma: %{
        confirmation_pending: false,
        tags: []
      }
62
63
64
65
66
67
68
69
    }

    assert expected == AccountView.render("account.json", %{user: user})
  end

  test "Represent a Service(bot) account" do
    user =
      insert(:user, %{
70
        info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
        nickname: "shp@shitposter.club",
        inserted_at: ~N[2017-08-15 15:47:06.597036]
      })

    expected = %{
      id: to_string(user.id),
      username: "shp",
      acct: user.nickname,
      display_name: user.name,
      locked: false,
      created_at: "2017-08-15T15:47:06.000Z",
      followers_count: 3,
      following_count: 0,
      statuses_count: 5,
      note: user.bio,
      url: user.ap_id,
      avatar: "http://localhost:4001/images/avi.png",
      avatar_static: "http://localhost:4001/images/avi.png",
      header: "http://localhost:4001/images/banner.png",
      header_static: "http://localhost:4001/images/banner.png",
      emojis: [],
      fields: [],
      bot: true,
94
95
96
      source: %{
        note: "",
        privacy: "public",
97
        sensitive: false
Ivan Tashkinov's avatar
Ivan Tashkinov committed
98
      },
99
100
101
102
      pleroma: %{
        confirmation_pending: false,
        tags: []
      }
lain's avatar
lain committed
103
104
105
106
107
108
109
110
111
    }

    assert expected == AccountView.render("account.json", %{user: user})
  end

  test "Represent a smaller mention" do
    user = insert(:user)

    expected = %{
lain's avatar
lain committed
112
      id: to_string(user.id),
lain's avatar
lain committed
113
114
115
116
117
118
119
      acct: user.nickname,
      username: user.nickname,
      url: user.ap_id
    }

    assert expected == AccountView.render("mention.json", %{user: user})
  end
Roger Braun's avatar
Roger Braun committed
120
121
122
123
124
125

  test "represent a relationship" do
    user = insert(:user)
    other_user = insert(:user)

    {:ok, user} = User.follow(user, other_user)
lain's avatar
lain committed
126
    {:ok, user} = User.block(user, other_user)
Roger Braun's avatar
Roger Braun committed
127
128

    expected = %{
lain's avatar
lain committed
129
      id: to_string(other_user.id),
130
      following: false,
Roger Braun's avatar
Roger Braun committed
131
      followed_by: false,
lain's avatar
lain committed
132
      blocking: true,
Roger Braun's avatar
Roger Braun committed
133
      muting: false,
134
      muting_notifications: false,
Roger Braun's avatar
Roger Braun committed
135
      requested: false,
136
      domain_blocking: false,
137
138
      showing_reblogs: false,
      endorsed: false
Roger Braun's avatar
Roger Braun committed
139
140
141
142
    }

    assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
  end
lain's avatar
lain committed
143
end