Merge pull request 'Additional timeline query improvements from upstream' (#291)...
[akkoma] / test / pleroma / workers / purge_expired_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.Workers.PurgeExpiredTokenTest do
6 use Pleroma.DataCase, async: true
7 use Oban.Testing, repo: Pleroma.Repo
8
9 import Pleroma.Factory
10
11 setup do: clear_config([:oauth2, :clean_expired_tokens], true)
12
13 test "purges expired oauth token" do
14 user = insert(:user)
15 app = insert(:oauth_app)
16
17 {:ok, %{id: id}} = Pleroma.Web.OAuth.Token.create(app, user)
18
19 assert_enqueued(
20 worker: Pleroma.Workers.PurgeExpiredToken,
21 args: %{token_id: id, mod: Pleroma.Web.OAuth.Token}
22 )
23
24 assert {:ok, %{id: ^id}} =
25 perform_job(Pleroma.Workers.PurgeExpiredToken, %{
26 token_id: id,
27 mod: Pleroma.Web.OAuth.Token
28 })
29
30 assert Repo.aggregate(Pleroma.Web.OAuth.Token, :count, :id) == 0
31 end
32
33 test "purges expired mfa token" do
34 authorization = insert(:oauth_authorization)
35
36 {:ok, %{id: id}} = Pleroma.MFA.Token.create(authorization.user, authorization)
37
38 assert_enqueued(
39 worker: Pleroma.Workers.PurgeExpiredToken,
40 args: %{token_id: id, mod: Pleroma.MFA.Token}
41 )
42
43 assert {:ok, %{id: ^id}} =
44 perform_job(Pleroma.Workers.PurgeExpiredToken, %{
45 token_id: id,
46 mod: Pleroma.MFA.Token
47 })
48
49 assert Repo.aggregate(Pleroma.MFA.Token, :count, :id) == 0
50 end
51 end