account_view_test.exs 1.77 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
8
    user = insert(:user, %{info: %{"note_count" => 5, "follower_count" => 3}, nickname: "shp@shitposter.club", inserted_at: ~N[2017-08-15 15:47:06.597036]})
lain's avatar
lain committed
9
10
11

    expected = %{
      id: user.id,
12
      username: "shp",
lain's avatar
lain committed
13
14
15
      acct: user.nickname,
      display_name: user.name,
      locked: false,
16
      created_at: "2017-08-15T15:47:06.000Z",
lain's avatar
lain committed
17
18
19
20
21
22
23
      followers_count: 3,
      following_count: 0,
      statuses_count: 5,
      note: user.bio,
      url: user.ap_id,
      avatar: "https://placehold.it/48x48",
      avatar_static: "https://placehold.it/48x48",
lain's avatar
lain committed
24
      header: "https://placehold.it/700x335",
25
26
27
28
29
30
      header_static: "https://placehold.it/700x335",
      source: %{
        note: "",
        privacy: "public",
        sensitive: "false"
      }
lain's avatar
lain committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    }

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

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

    expected = %{
      id: user.id,
      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
48
49
50
51
52
53

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

    {:ok, user} = User.follow(user, other_user)
lain's avatar
lain committed
54
    {:ok, user} = User.block(user, other_user)
Roger Braun's avatar
Roger Braun committed
55
56
57

    expected = %{
      id: other_user.id,
Roger Braun's avatar
Roger Braun committed
58
59
      following: true,
      followed_by: false,
lain's avatar
lain committed
60
      blocking: true,
Roger Braun's avatar
Roger Braun committed
61
62
63
64
65
66
67
      muting: false,
      requested: false,
      domain_blocking: false
    }

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