1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Workers.PurgeExpiredTokenTest do
7 use Oban.Testing, repo: Pleroma.Repo
11 setup do: clear_config([:oauth2, :clean_expired_tokens], true)
13 test "purges expired oauth token" do
15 app = insert(:oauth_app)
17 {:ok, %{id: id}} = Pleroma.Web.OAuth.Token.create(app, user)
20 worker: Pleroma.Workers.PurgeExpiredToken,
21 args: %{token_id: id, mod: Pleroma.Web.OAuth.Token}
24 assert {:ok, %{id: ^id}} =
25 perform_job(Pleroma.Workers.PurgeExpiredToken, %{
27 mod: Pleroma.Web.OAuth.Token
30 assert Repo.aggregate(Pleroma.Web.OAuth.Token, :count, :id) == 0
33 test "purges expired mfa token" do
34 authorization = insert(:oauth_authorization)
36 {:ok, %{id: id}} = Pleroma.MFA.Token.create(authorization.user, authorization)
39 worker: Pleroma.Workers.PurgeExpiredToken,
40 args: %{token_id: id, mod: Pleroma.MFA.Token}
43 assert {:ok, %{id: ^id}} =
44 perform_job(Pleroma.Workers.PurgeExpiredToken, %{
46 mod: Pleroma.MFA.Token
49 assert Repo.aggregate(Pleroma.MFA.Token, :count, :id) == 0