1
0
Fork 0
forked from AkkomaGang/akkoma
akkoma/test/pleroma/workers/purge_expired_token_test.exs
Haelwenn (lanodan) Monnier c4439c630f
Bump Copyright to 2021
grep -rl '# Copyright © .* Pleroma' * | xargs sed -i 's;Copyright © .* Pleroma .*;Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>;'
2021-01-13 07:49:50 +01:00

51 lines
1.4 KiB
Elixir

# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PurgeExpiredTokenTest do
use Pleroma.DataCase, async: true
use Oban.Testing, repo: Pleroma.Repo
import Pleroma.Factory
setup do: clear_config([:oauth2, :clean_expired_tokens], true)
test "purges expired oauth token" do
user = insert(:user)
app = insert(:oauth_app)
{:ok, %{id: id}} = Pleroma.Web.OAuth.Token.create(app, user)
assert_enqueued(
worker: Pleroma.Workers.PurgeExpiredToken,
args: %{token_id: id, mod: Pleroma.Web.OAuth.Token}
)
assert {:ok, %{id: ^id}} =
perform_job(Pleroma.Workers.PurgeExpiredToken, %{
token_id: id,
mod: Pleroma.Web.OAuth.Token
})
assert Repo.aggregate(Pleroma.Web.OAuth.Token, :count, :id) == 0
end
test "purges expired mfa token" do
authorization = insert(:oauth_authorization)
{:ok, %{id: id}} = Pleroma.MFA.Token.create(authorization.user, authorization)
assert_enqueued(
worker: Pleroma.Workers.PurgeExpiredToken,
args: %{token_id: id, mod: Pleroma.MFA.Token}
)
assert {:ok, %{id: ^id}} =
perform_job(Pleroma.Workers.PurgeExpiredToken, %{
token_id: id,
mod: Pleroma.MFA.Token
})
assert Repo.aggregate(Pleroma.MFA.Token, :count, :id) == 0
end
end