logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

user_invite_token_test.exs (2934B)


  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. defmodule Pleroma.UserInviteTokenTest do
  5. use ExUnit.Case, async: true
  6. alias Pleroma.UserInviteToken
  7. describe "valid_invite?/1 one time invites" do
  8. setup do
  9. invite = %UserInviteToken{invite_type: "one_time"}
  10. {:ok, invite: invite}
  11. end
  12. test "not used returns true", %{invite: invite} do
  13. invite = %{invite | used: false}
  14. assert UserInviteToken.valid_invite?(invite)
  15. end
  16. test "used returns false", %{invite: invite} do
  17. invite = %{invite | used: true}
  18. refute UserInviteToken.valid_invite?(invite)
  19. end
  20. end
  21. describe "valid_invite?/1 reusable invites" do
  22. setup do
  23. invite = %UserInviteToken{
  24. invite_type: "reusable",
  25. max_use: 5
  26. }
  27. {:ok, invite: invite}
  28. end
  29. test "with less uses then max use returns true", %{invite: invite} do
  30. invite = %{invite | uses: 4}
  31. assert UserInviteToken.valid_invite?(invite)
  32. end
  33. test "with equal or more uses then max use returns false", %{invite: invite} do
  34. invite = %{invite | uses: 5}
  35. refute UserInviteToken.valid_invite?(invite)
  36. invite = %{invite | uses: 6}
  37. refute UserInviteToken.valid_invite?(invite)
  38. end
  39. end
  40. describe "valid_token?/1 date limited invites" do
  41. setup do
  42. invite = %UserInviteToken{invite_type: "date_limited"}
  43. {:ok, invite: invite}
  44. end
  45. test "expires today returns true", %{invite: invite} do
  46. invite = %{invite | expires_at: Date.utc_today()}
  47. assert UserInviteToken.valid_invite?(invite)
  48. end
  49. test "expires yesterday returns false", %{invite: invite} do
  50. invite = %{invite | expires_at: Date.add(Date.utc_today(), -1)}
  51. refute UserInviteToken.valid_invite?(invite)
  52. end
  53. end
  54. describe "valid_token?/1 reusable date limited invites" do
  55. setup do
  56. invite = %UserInviteToken{invite_type: "reusable_date_limited", max_use: 5}
  57. {:ok, invite: invite}
  58. end
  59. test "not overdue date and less uses returns true", %{invite: invite} do
  60. invite = %{invite | expires_at: Date.utc_today(), uses: 4}
  61. assert UserInviteToken.valid_invite?(invite)
  62. end
  63. test "overdue date and less uses returns false", %{invite: invite} do
  64. invite = %{invite | expires_at: Date.add(Date.utc_today(), -1)}
  65. refute UserInviteToken.valid_invite?(invite)
  66. end
  67. test "not overdue date with more uses returns false", %{invite: invite} do
  68. invite = %{invite | expires_at: Date.utc_today(), uses: 5}
  69. refute UserInviteToken.valid_invite?(invite)
  70. end
  71. test "overdue date with more uses returns false", %{invite: invite} do
  72. invite = %{invite | expires_at: Date.add(Date.utc_today(), -1), uses: 5}
  73. refute UserInviteToken.valid_invite?(invite)
  74. end
  75. end
  76. end