paginate follow requests (#460)
[akkoma] / test / pleroma / user_invite_token_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.UserInviteTokenTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.UserInviteToken
8
9 describe "valid_invite?/1 one time invites" do
10 setup do
11 invite = %UserInviteToken{invite_type: "one_time"}
12
13 {:ok, invite: invite}
14 end
15
16 test "not used returns true", %{invite: invite} do
17 invite = %{invite | used: false}
18 assert UserInviteToken.valid_invite?(invite)
19 end
20
21 test "used returns false", %{invite: invite} do
22 invite = %{invite | used: true}
23 refute UserInviteToken.valid_invite?(invite)
24 end
25 end
26
27 describe "valid_invite?/1 reusable invites" do
28 setup do
29 invite = %UserInviteToken{
30 invite_type: "reusable",
31 max_use: 5
32 }
33
34 {:ok, invite: invite}
35 end
36
37 test "with less uses then max use returns true", %{invite: invite} do
38 invite = %{invite | uses: 4}
39 assert UserInviteToken.valid_invite?(invite)
40 end
41
42 test "with equal or more uses then max use returns false", %{invite: invite} do
43 invite = %{invite | uses: 5}
44
45 refute UserInviteToken.valid_invite?(invite)
46
47 invite = %{invite | uses: 6}
48
49 refute UserInviteToken.valid_invite?(invite)
50 end
51 end
52
53 describe "valid_token?/1 date limited invites" do
54 setup do
55 invite = %UserInviteToken{invite_type: "date_limited"}
56 {:ok, invite: invite}
57 end
58
59 test "expires today returns true", %{invite: invite} do
60 invite = %{invite | expires_at: Date.utc_today()}
61 assert UserInviteToken.valid_invite?(invite)
62 end
63
64 test "expires yesterday returns false", %{invite: invite} do
65 invite = %{invite | expires_at: Date.add(Date.utc_today(), -1)}
66 refute UserInviteToken.valid_invite?(invite)
67 end
68 end
69
70 describe "valid_token?/1 reusable date limited invites" do
71 setup do
72 invite = %UserInviteToken{invite_type: "reusable_date_limited", max_use: 5}
73 {:ok, invite: invite}
74 end
75
76 test "not overdue date and less uses returns true", %{invite: invite} do
77 invite = %{invite | expires_at: Date.utc_today(), uses: 4}
78 assert UserInviteToken.valid_invite?(invite)
79 end
80
81 test "overdue date and less uses returns false", %{invite: invite} do
82 invite = %{invite | expires_at: Date.add(Date.utc_today(), -1)}
83 refute UserInviteToken.valid_invite?(invite)
84 end
85
86 test "not overdue date with more uses returns false", %{invite: invite} do
87 invite = %{invite | expires_at: Date.utc_today(), uses: 5}
88 refute UserInviteToken.valid_invite?(invite)
89 end
90
91 test "overdue date with more uses returns false", %{invite: invite} do
92 invite = %{invite | expires_at: Date.add(Date.utc_today(), -1), uses: 5}
93 refute UserInviteToken.valid_invite?(invite)
94 end
95 end
96 end