1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.UserInviteTokenTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.UserInviteToken
9 describe "valid_invite?/1 one time invites" do
11 invite = %UserInviteToken{invite_type: "one_time"}
16 test "not used returns true", %{invite: invite} do
17 invite = %{invite | used: false}
18 assert UserInviteToken.valid_invite?(invite)
21 test "used returns false", %{invite: invite} do
22 invite = %{invite | used: true}
23 refute UserInviteToken.valid_invite?(invite)
27 describe "valid_invite?/1 reusable invites" do
29 invite = %UserInviteToken{
30 invite_type: "reusable",
37 test "with less uses then max use returns true", %{invite: invite} do
38 invite = %{invite | uses: 4}
39 assert UserInviteToken.valid_invite?(invite)
42 test "with equal or more uses then max use returns false", %{invite: invite} do
43 invite = %{invite | uses: 5}
45 refute UserInviteToken.valid_invite?(invite)
47 invite = %{invite | uses: 6}
49 refute UserInviteToken.valid_invite?(invite)
53 describe "valid_token?/1 date limited invites" do
55 invite = %UserInviteToken{invite_type: "date_limited"}
59 test "expires today returns true", %{invite: invite} do
60 invite = %{invite | expires_at: Date.utc_today()}
61 assert UserInviteToken.valid_invite?(invite)
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)
70 describe "valid_token?/1 reusable date limited invites" do
72 invite = %UserInviteToken{invite_type: "reusable_date_limited", max_use: 5}
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)
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)
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)
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)