Merge branch 'develop' into issue/2099
[akkoma] / test / user / import_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.User.ImportTest do
6 alias Pleroma.Repo
7 alias Pleroma.Tests.ObanHelpers
8 alias Pleroma.User
9
10 use Pleroma.DataCase
11 use Oban.Testing, repo: Pleroma.Repo
12
13 import Pleroma.Factory
14
15 setup_all do
16 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
17 :ok
18 end
19
20 describe "follow_import" do
21 test "it imports user followings from list" do
22 [user1, user2, user3] = insert_list(3, :user)
23
24 identifiers = [
25 user2.ap_id,
26 user3.nickname
27 ]
28
29 {:ok, job} = User.Import.follow_import(user1, identifiers)
30
31 assert {:ok, result} = ObanHelpers.perform(job)
32 assert is_list(result)
33 assert result == [user2, user3]
34 assert User.following?(user1, user2)
35 assert User.following?(user1, user3)
36 end
37 end
38
39 describe "blocks_import" do
40 test "it imports user blocks from list" do
41 [user1, user2, user3] = insert_list(3, :user)
42
43 identifiers = [
44 user2.ap_id,
45 user3.nickname
46 ]
47
48 {:ok, job} = User.Import.blocks_import(user1, identifiers)
49
50 assert {:ok, result} = ObanHelpers.perform(job)
51 assert is_list(result)
52 assert result == [user2, user3]
53 assert User.blocks?(user1, user2)
54 assert User.blocks?(user1, user3)
55 end
56 end
57
58 describe "mutes_import" do
59 test "it imports user mutes from list" do
60 [user1, user2, user3] = insert_list(3, :user)
61
62 identifiers = [
63 user2.ap_id,
64 user3.nickname
65 ]
66
67 {:ok, job} = User.Import.mutes_import(user1, identifiers)
68
69 assert {:ok, result} = ObanHelpers.perform(job)
70 assert is_list(result)
71 assert result == [user2, user3]
72 assert User.mutes?(user1, user2)
73 assert User.mutes?(user1, user3)
74 end
75 end
76 end